Show More
@@ -87,14 +87,6 b' def get_viewers():' | |||||
87 | return AbstractViewer.__subclasses__() |
|
87 | return AbstractViewer.__subclasses__() | |
88 |
|
88 | |||
89 |
|
89 | |||
90 | def get_static_dimensions(filename): |
|
|||
91 | file_path = finders.find(filename) |
|
|||
92 | return get_image_dimensions(file_path) |
|
|||
93 |
|
||||
94 |
|
||||
95 | # TODO Move this to utils |
|
|||
96 | def file_exists(filename): |
|
|||
97 | return finders.find(filename) is not None |
|
|||
98 |
|
90 | |||
99 |
|
91 | |||
100 | class AbstractViewer: |
|
92 | class AbstractViewer: | |
@@ -128,15 +120,25 b' class AbstractViewer:' | |||||
128 | image_name = PLAIN_FILE_FORMATS.get(self.extension, self.extension) |
|
120 | image_name = PLAIN_FILE_FORMATS.get(self.extension, self.extension) | |
129 | file_name = FILE_FILEFORMAT.format(image_name) |
|
121 | file_name = FILE_FILEFORMAT.format(image_name) | |
130 |
|
122 | |||
131 | if file_exists(file_name): |
|
123 | if self.file_exists(file_name): | |
132 | image = file_name |
|
124 | image = file_name | |
133 | else: |
|
125 | else: | |
134 | image = FILE_STUB_IMAGE |
|
126 | image = FILE_STUB_IMAGE | |
135 |
|
127 | |||
136 | w, h = get_static_dimensions(image) |
|
128 | w, h = self.get_static_dimensions(image) | |
137 |
|
129 | |||
138 | return ABSTRACT_FORMAT_VIEW.format(self.file.url, static(image), w, h) |
|
130 | return ABSTRACT_FORMAT_VIEW.format(self.file.url, static(image), w, h) | |
139 |
|
131 | |||
|
132 | @cached_result() | |||
|
133 | def get_static_dimensions(self, filename): | |||
|
134 | file_path = finders.find(filename) | |||
|
135 | return get_image_dimensions(file_path) | |||
|
136 | ||||
|
137 | ||||
|
138 | @cached_result() | |||
|
139 | def file_exists(self, filename): | |||
|
140 | return finders.find(filename) is not None | |||
|
141 | ||||
140 |
|
142 | |||
141 | class VideoViewer(AbstractViewer): |
|
143 | class VideoViewer(AbstractViewer): | |
142 | @staticmethod |
|
144 | @staticmethod | |
@@ -221,7 +223,7 b' class UrlViewer(AbstractViewer):' | |||||
221 |
|
223 | |||
222 | image_path = 'images/{}.png'.format(url_image_name) |
|
224 | image_path = 'images/{}.png'.format(url_image_name) | |
223 | image = static(image_path) |
|
225 | image = static(image_path) | |
224 | w, h = get_static_dimensions(image_path) |
|
226 | w, h = self.get_static_dimensions(image_path) | |
225 |
|
227 | |||
226 | return URL_FORMAT_VIEW.format(self.url, image, w, h) |
|
228 | return URL_FORMAT_VIEW.format(self.url, image, w, h) | |
227 |
|
229 | |||
@@ -237,7 +239,7 b' class UrlViewer(AbstractViewer):' | |||||
237 | domain = DOMAIN_DELIMITER.join(levels) |
|
239 | domain = DOMAIN_DELIMITER.join(levels) | |
238 |
|
240 | |||
239 | filename = 'images/domains/{}.png'.format(domain) |
|
241 | filename = 'images/domains/{}.png'.format(domain) | |
240 | if file_exists(filename): |
|
242 | if self.file_exists(filename): | |
241 | return 'domains/' + domain |
|
243 | return 'domains/' + domain | |
242 | else: |
|
244 | else: | |
243 | del levels[0] |
|
245 | del levels[0] |
General Comments 0
You need to be logged in to leave comments.
Login now