##// END OF EJS Templates
Removed redundant viewers code
neko259 -
r2040:5608c1c3 default
parent child Browse files
Show More
@@ -8,6 +8,8 b' from boards.abstracts.constants import T'
8 from boards.settings import SECTION_EXTERNAL
8 from boards.settings import SECTION_EXTERNAL
9 from boards.utils import get_domain, cached_result, get_extension
9 from boards.utils import get_domain, cached_result, get_extension
10
10
11 URL_IMAGE_PATH = 'images/{}.png'
12
11 PROTOCOL_DELIMITER = ':'
13 PROTOCOL_DELIMITER = ':'
12 DOMAIN_DELIMITER = '.'
14 DOMAIN_DELIMITER = '.'
13
15
@@ -50,7 +52,6 b' URL_PROTOCOLS = {'
50 }
52 }
51
53
52 CSS_CLASS_IMAGE = 'image'
54 CSS_CLASS_IMAGE = 'image'
53 CSS_CLASS_THUMB = 'thumb'
54
55
55 ABSTRACT_VIEW = '<div class="image">'\
56 ABSTRACT_VIEW = '<div class="image">'\
56 '{}'\
57 '{}'\
@@ -66,7 +67,7 b' ABSTRACT_FORMAT_VIEW = \'<a href="{}">\'\\'
66 '</a>'
67 '</a>'
67 VIDEO_FORMAT_VIEW = '<video width="200" height="150" controls src="{}"></video>'
68 VIDEO_FORMAT_VIEW = '<video width="200" height="150" controls src="{}"></video>'
68 AUDIO_FORMAT_VIEW = '<audio controls src="{}"></audio>'
69 AUDIO_FORMAT_VIEW = '<audio controls src="{}"></audio>'
69 IMAGE_FORMAT_VIEW = '<a class="{}" href="{full}">' \
70 IMAGE_FORMAT_VIEW = '<a class="thumb" href="{full}">' \
70 '<img class="post-image-preview"' \
71 '<img class="post-image-preview"' \
71 ' src="{}"' \
72 ' src="{}"' \
72 ' alt="{}"' \
73 ' alt="{}"' \
@@ -87,8 +88,6 b' def get_viewers():'
87 return AbstractViewer.__subclasses__()
88 return AbstractViewer.__subclasses__()
88
89
89
90
90
91
92 class AbstractViewer:
91 class AbstractViewer:
93 def __init__(self, file, file_type, id, url):
92 def __init__(self, file, file_type, id, url):
94 self.file = file
93 self.file = file
@@ -134,7 +133,6 b' class AbstractViewer:'
134 file_path = finders.find(filename)
133 file_path = finders.find(filename)
135 return get_image_dimensions(file_path)
134 return get_image_dimensions(file_path)
136
135
137
138 @cached_result()
136 @cached_result()
139 def file_exists(self, filename):
137 def file_exists(self, filename):
140 return finders.find(filename) is not None
138 return finders.find(filename) is not None
@@ -173,9 +171,6 b' class ImageViewer(AbstractViewer):'
173 return file_type in FILE_TYPES_IMAGE
171 return file_type in FILE_TYPES_IMAGE
174
172
175 def get_format_view(self):
173 def get_format_view(self):
176 metadata = '{}, {}'.format(self.file.name.split('.')[-1],
177 filesizeformat(self.file.size))
178
179 try:
174 try:
180 width, height = get_image_dimensions(self.file.path)
175 width, height = get_image_dimensions(self.file.path)
181 except Exception:
176 except Exception:
@@ -193,12 +188,11 b' class ImageViewer(AbstractViewer):'
193 w, h = THUMB_SIZES[0]
188 w, h = THUMB_SIZES[0]
194 thumb_url = '%s.%sx%s.%s' % (split[0], w, h, split[1])
189 thumb_url = '%s.%sx%s.%s' % (split[0], w, h, split[1])
195
190
196 return IMAGE_FORMAT_VIEW.format(CSS_CLASS_THUMB,
191 return IMAGE_FORMAT_VIEW.format(
197 thumb_url,
192 thumb_url,
198 self.id,
193 self.id,
199 str(pre_width),
194 pre_width, pre_height, width, height,
200 str(pre_height), str(width), str(height),
195 full=self.file.url)
201 full=self.file.url, image_meta=metadata)
202
196
203
197
204 class UrlViewer(AbstractViewer):
198 class UrlViewer(AbstractViewer):
@@ -214,7 +208,7 b' class UrlViewer(AbstractViewer):'
214
208
215 domain = get_domain(self.url)
209 domain = get_domain(self.url)
216
210
217 image_path = 'images/{}.png'.format(self._get_image_name(protocol, domain))
211 image_path = URL_IMAGE_PATH.format(self._get_image_name(protocol, domain))
218 image = static(image_path)
212 image = static(image_path)
219 w, h = self.get_static_dimensions(image_path)
213 w, h = self.get_static_dimensions(image_path)
220
214
General Comments 0
You need to be logged in to leave comments. Login now