##// END OF EJS Templates
Image search in every image view, using context menu
neko259 -
r1812:f2a9c571 default
parent child Browse files
Show More
1 NO CONTENT: modified file, binary diff hidden
@@ -581,3 +581,6 b' msgstr "\xd0\x9c\xd0\xb0\xd0\xba\xd1\x81\xd0\xb8\xd0\xbc\xd0\xb0\xd0\xbb\xd1\x8c\xd0\xbd\xd0\xbe\xd0\xb5 \xd0\xba\xd0\xbe\xd0\xbb\xd0\xb8\xd1\x87\xd0\xb5\xd1\x81\xd1\x82\xd0\xb2\xd0\xbe \xd1\x84\xd0\xb0\xd0\xb9\xd0\xbb\xd0\xbe\xd0\xb2 %(max_files)s."'
581 581 msgid "Moderation"
582 582 msgstr "Модерация"
583 583
584 msgid "Duplicates search"
585 msgstr "Поиск дубликатов"
586
@@ -4,8 +4,11 b' from django.contrib.staticfiles import f'
4 4 from django.contrib.staticfiles.templatetags.staticfiles import static
5 5 from django.core.files.images import get_image_dimensions
6 6 from django.template.defaultfilters import filesizeformat
7 from django.core.urlresolvers import reverse
8 from django.utils.translation import ugettext_lazy as _, ungettext_lazy
7 9
8 10 from boards.utils import get_domain, cached_result
11 from boards import settings
9 12
10 13
11 14 FILE_STUB_IMAGE = 'images/file.png'
@@ -74,11 +77,13 b' class AbstractViewer:'
74 77 return True
75 78
76 79 def get_view(self):
77 return '<div class="image">'\
80 return '<div class="image" id="file{}">'\
78 81 '{}'\
79 '<div class="image-metadata"><a href="{}" download >{}, {}</a></div>'\
80 '</div>'.format(self.get_format_view(), self.file.url,
81 self.file_type, filesizeformat(self.file.size))
82 '<div class="image-metadata"><a href="{}" download >{}, {}</a>'\
83 ' <a class="file-menu" href="#">🔍 </a></div>'\
84 '</div>'.format(self.hash, self.get_format_view(), self.file.url,
85 self.file_type, filesizeformat(self.file.size))\
86 + self._build_context_menu(self.get_context_menu())
82 87
83 88 def get_format_view(self):
84 89 image_name = PLAIN_FILE_FORMATS.get(self.file_type, self.file_type)
@@ -95,6 +100,26 b' class AbstractViewer:'
95 100 '<img class="url-image" src="{}" width="{}" height="{}"/>'\
96 101 '</a>'.format(self.file.url, static(image), w, h)
97 102
103 def get_context_menu(self):
104 items = []
105 items.append({
106 'name': 'duplicates',
107 'label': _('Duplicates search'),
108 'url': reverse('feed') + '?image_hash=' + self.hash,
109 })
110
111 return items
112
113 def _build_context_menu(self, items):
114 if not items:
115 return ''
116
117 cm_items = []
118 for item in items:
119 cm_items.append(('{}: {{name: "{}", callback: function(key, opt) {{window.location="{}";}}}}')\
120 .format(item['name'], item['label'], item['url']))
121 return '<script>$.contextMenu({{trigger: "left", selector: "#file{} .file-menu", items: {{ {} }} }});</script>'.format(self.hash, ', '.join(cm_items))
122
98 123
99 124 class VideoViewer(AbstractViewer):
100 125 @staticmethod
@@ -158,6 +183,24 b' class ImageViewer(AbstractViewer):'
158 183 str(pre_height), str(width), str(height),
159 184 full=self.file.url, image_meta=metadata)
160 185
186 def get_context_menu(self):
187 items = super().get_context_menu()
188
189 image_url = settings.get('External', 'ImageSearchHost') + self.file.url
190
191 items.append({
192 'name': 'google',
193 'label': 'Google',
194 'url': 'https://www.google.com/searchbyimage?image_url={}'.format(image_url),
195 })
196 items.append({
197 'name': 'iqdb',
198 'label': 'iqdb',
199 'url': 'http://iqdb.org/?url={}'.format(image_url)
200 })
201
202 return items
203
161 204
162 205 class UrlViewer(AbstractViewer):
163 206 @staticmethod
@@ -190,6 +233,9 b' class UrlViewer(AbstractViewer):'
190 233 '<img class="url-image" src="{}" width="{}" height="{}"/>' \
191 234 '</a>'.format(self.url, image, w, h)
192 235
236 def get_context_menu(self):
237 return []
238
193 239 @cached_result()
194 240 def _find_image_for_domains(self, domain):
195 241 """
@@ -24,8 +24,6 b''
24 24 {{ image.get_view }}
25 25 <div class="gallery_image_metadata">
26 26 {{ image.get_size.0 }}x{{ image.get_size.1 }}
27 {% image_actions image.file.url %},
28 [<a href="{% url 'feed' %}?image_hash={{ image.hash }}">{{ site_name }}</a>]
29 27 <br />
30 28 <a href="{{ post.get_absolute_url }}">>>{{ post.id }}</a>
31 29 </div>
@@ -19,17 +19,6 b' HTML4_SINGLETS =('
19 19
20 20 register = template.Library()
21 21
22 actions = [
23 {
24 'name': 'google',
25 'link': 'https://www.google.com/searchbyimage?image_url={}',
26 },
27 {
28 'name': 'iqdb',
29 'link': 'http://iqdb.org/?url={}',
30 },
31 ]
32
33 22
34 23 @register.simple_tag(name='post_url')
35 24 def post_url(*args, **kwargs):
@@ -40,18 +29,6 b' def post_url(*args, **kwargs):'
40 29 return post.get_absolute_url()
41 30
42 31
43 @register.simple_tag(name='image_actions')
44 def image_actions(*args, **kwargs):
45 image_link = args[0]
46 host = settings.get('External', 'ImageSearchHost')
47 if host.endswith('/'):
48 host = host[:-1]
49 image_link = settings.get('External', 'ImageSearchHost') + image_link
50
51 return ', '.join([IMG_ACTION_URL.format(
52 action['link'].format(image_link), action['name']) for action in actions])
53
54
55 32 @register.inclusion_tag('boards/post.html', name='post_view', takes_context=True)
56 33 def post_view(context, post, *args, **kwargs):
57 34 kwargs['perms'] = context['perms']
General Comments 0
You need to be logged in to leave comments. Login now