##// 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 8 from boards.settings import SECTION_EXTERNAL
9 9 from boards.utils import get_domain, cached_result, get_extension
10 10
11 URL_IMAGE_PATH = 'images/{}.png'
12
11 13 PROTOCOL_DELIMITER = ':'
12 14 DOMAIN_DELIMITER = '.'
13 15
@@ -50,7 +52,6 b' URL_PROTOCOLS = {'
50 52 }
51 53
52 54 CSS_CLASS_IMAGE = 'image'
53 CSS_CLASS_THUMB = 'thumb'
54 55
55 56 ABSTRACT_VIEW = '<div class="image">'\
56 57 '{}'\
@@ -66,7 +67,7 b' ABSTRACT_FORMAT_VIEW = \'<a href="{}">\'\\'
66 67 '</a>'
67 68 VIDEO_FORMAT_VIEW = '<video width="200" height="150" controls src="{}"></video>'
68 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 71 '<img class="post-image-preview"' \
71 72 ' src="{}"' \
72 73 ' alt="{}"' \
@@ -87,8 +88,6 b' def get_viewers():'
87 88 return AbstractViewer.__subclasses__()
88 89
89 90
90
91
92 91 class AbstractViewer:
93 92 def __init__(self, file, file_type, id, url):
94 93 self.file = file
@@ -134,7 +133,6 b' class AbstractViewer:'
134 133 file_path = finders.find(filename)
135 134 return get_image_dimensions(file_path)
136 135
137
138 136 @cached_result()
139 137 def file_exists(self, filename):
140 138 return finders.find(filename) is not None
@@ -173,9 +171,6 b' class ImageViewer(AbstractViewer):'
173 171 return file_type in FILE_TYPES_IMAGE
174 172
175 173 def get_format_view(self):
176 metadata = '{}, {}'.format(self.file.name.split('.')[-1],
177 filesizeformat(self.file.size))
178
179 174 try:
180 175 width, height = get_image_dimensions(self.file.path)
181 176 except Exception:
@@ -193,12 +188,11 b' class ImageViewer(AbstractViewer):'
193 188 w, h = THUMB_SIZES[0]
194 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 192 thumb_url,
198 193 self.id,
199 str(pre_width),
200 str(pre_height), str(width), str(height),
201 full=self.file.url, image_meta=metadata)
194 pre_width, pre_height, width, height,
195 full=self.file.url)
202 196
203 197
204 198 class UrlViewer(AbstractViewer):
@@ -214,7 +208,7 b' class UrlViewer(AbstractViewer):'
214 208
215 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 212 image = static(image_path)
219 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