Show More
@@ -52,6 +52,36 b' URL_PROTOCOLS = {' | |||||
52 | CSS_CLASS_IMAGE = 'image' |
|
52 | CSS_CLASS_IMAGE = 'image' | |
53 | CSS_CLASS_THUMB = 'thumb' |
|
53 | CSS_CLASS_THUMB = 'thumb' | |
54 |
|
54 | |||
|
55 | ABSTRACT_VIEW = '<div class="image">'\ | |||
|
56 | '{}'\ | |||
|
57 | '<div class="image-metadata"><a href="{}" download >{}, {}</a>'\ | |||
|
58 | ' <a class="file-menu" href="#" data-type="{}" data-search-url="{}" data-filename="{}">π </a></div>'\ | |||
|
59 | '</div>' | |||
|
60 | URL_VIEW = '<div class="image">' \ | |||
|
61 | '{}' \ | |||
|
62 | '<div class="image-metadata">{}</div>' \ | |||
|
63 | '</div>' | |||
|
64 | ABSTRACT_FORMAT_VIEW = '<a href="{}">'\ | |||
|
65 | '<img class="url-image" src="{}" width="{}" height="{}"/>'\ | |||
|
66 | '</a>' | |||
|
67 | VIDEO_FORMAT_VIEW = '<video width="200" height="150" controls src="{}"></video>' | |||
|
68 | AUDIO_FORMAT_VIEW = '<audio controls src="{}"></audio>' | |||
|
69 | IMAGE_FORMAT_VIEW = '<a class="{}" href="{full}">' \ | |||
|
70 | '<img class="post-image-preview"' \ | |||
|
71 | ' src="{}"' \ | |||
|
72 | ' alt="{}"' \ | |||
|
73 | ' width="{}"' \ | |||
|
74 | ' height="{}"' \ | |||
|
75 | ' data-width="{}"' \ | |||
|
76 | ' data-height="{}" />' \ | |||
|
77 | '</a>' | |||
|
78 | SVG_FORMAT_VIEW = '<a class="thumb" href="{}">'\ | |||
|
79 | '<img class="post-image-preview" width="200" height="150" src="{}" />'\ | |||
|
80 | '</a>' | |||
|
81 | URL_FORMAT_VIEW = '<a href="{}">' \ | |||
|
82 | '<img class="url-image" src="{}" width="{}" height="{}"/>' \ | |||
|
83 | '</a>' | |||
|
84 | ||||
55 |
|
85 | |||
56 | def get_viewers(): |
|
86 | def get_viewers(): | |
57 | return AbstractViewer.__subclasses__() |
|
87 | return AbstractViewer.__subclasses__() | |
@@ -87,13 +117,9 b' class AbstractViewer:' | |||||
87 | else: |
|
117 | else: | |
88 | search_url = '' |
|
118 | search_url = '' | |
89 |
|
119 | |||
90 | return '<div class="image">'\ |
|
120 | return ABSTRACT_VIEW.format(self.get_format_view(), self.file.url, | |
91 | '{}'\ |
|
121 | self.file_type, filesizeformat(self.file.size), | |
92 | '<div class="image-metadata"><a href="{}" download >{}, {}</a>'\ |
|
122 | self.file_type, search_url, self.file.name) | |
93 | ' <a class="file-menu" href="#" data-type="{}" data-search-url="{}" data-filename="{}">π </a></div>'\ |
|
|||
94 | '</div>'.format(self.get_format_view(), self.file.url, |
|
|||
95 | self.file_type, filesizeformat(self.file.size), |
|
|||
96 | self.file_type, search_url, self.file.name) |
|
|||
97 |
|
123 | |||
98 | def get_format_view(self): |
|
124 | def get_format_view(self): | |
99 | image_name = PLAIN_FILE_FORMATS.get(self.file_type, self.file_type) |
|
125 | image_name = PLAIN_FILE_FORMATS.get(self.file_type, self.file_type) | |
@@ -106,9 +132,7 b' class AbstractViewer:' | |||||
106 |
|
132 | |||
107 | w, h = get_static_dimensions(image) |
|
133 | w, h = get_static_dimensions(image) | |
108 |
|
134 | |||
109 | return '<a href="{}">'\ |
|
135 | return ABSTRACT_FORMAT_VIEW.format(self.file.url, static(image), w, h) | |
110 | '<img class="url-image" src="{}" width="{}" height="{}"/>'\ |
|
|||
111 | '</a>'.format(self.file.url, static(image), w, h) |
|
|||
112 |
|
136 | |||
113 |
|
137 | |||
114 | class VideoViewer(AbstractViewer): |
|
138 | class VideoViewer(AbstractViewer): | |
@@ -117,8 +141,7 b' class VideoViewer(AbstractViewer):' | |||||
117 | return file_type in FILE_TYPES_VIDEO |
|
141 | return file_type in FILE_TYPES_VIDEO | |
118 |
|
142 | |||
119 | def get_format_view(self): |
|
143 | def get_format_view(self): | |
120 | return '<video width="200" height="150" controls src="{}"></video>'\ |
|
144 | return VIDEO_FORMAT_VIEW.format(self.file.url) | |
121 | .format(self.file.url) |
|
|||
122 |
|
145 | |||
123 |
|
146 | |||
124 | class AudioViewer(AbstractViewer): |
|
147 | class AudioViewer(AbstractViewer): | |
@@ -127,7 +150,7 b' class AudioViewer(AbstractViewer):' | |||||
127 | return file_type in FILE_TYPES_AUDIO |
|
150 | return file_type in FILE_TYPES_AUDIO | |
128 |
|
151 | |||
129 | def get_format_view(self): |
|
152 | def get_format_view(self): | |
130 | return '<audio controls src="{}"></audio>'.format(self.file.url) |
|
153 | return AUDIO_FORMAT_VIEW.format(self.file.url) | |
131 |
|
154 | |||
132 |
|
155 | |||
133 | class SvgViewer(AbstractViewer): |
|
156 | class SvgViewer(AbstractViewer): | |
@@ -136,9 +159,7 b' class SvgViewer(AbstractViewer):' | |||||
136 | return file_type == FILE_TYPE_SVG |
|
159 | return file_type == FILE_TYPE_SVG | |
137 |
|
160 | |||
138 | def get_format_view(self): |
|
161 | def get_format_view(self): | |
139 | return '<a class="thumb" href="{}">'\ |
|
162 | return SVG_FORMAT_VIEW.format(self.file.url, self.file.url) | |
140 | '<img class="post-image-preview" width="200" height="150" src="{}" />'\ |
|
|||
141 | '</a>'.format(self.file.url, self.file.url) |
|
|||
142 |
|
163 | |||
143 |
|
164 | |||
144 | class ImageViewer(AbstractViewer): |
|
165 | class ImageViewer(AbstractViewer): | |
@@ -164,21 +185,12 b' class ImageViewer(AbstractViewer):' | |||||
164 | w, h = 200, 150 |
|
185 | w, h = 200, 150 | |
165 | thumb_url = '%s.%sx%s.%s' % (split[0], w, h, split[1]) |
|
186 | thumb_url = '%s.%sx%s.%s' % (split[0], w, h, split[1]) | |
166 |
|
187 | |||
167 | return '<a class="{}" href="{full}">' \ |
|
188 | return IMAGE_FORMAT_VIEW.format(CSS_CLASS_THUMB, | |
168 | '<img class="post-image-preview"' \ |
|
189 | thumb_url, | |
169 |
|
|
190 | self.hash, | |
170 | ' alt="{}"' \ |
|
191 | str(pre_width), | |
171 | ' width="{}"' \ |
|
192 | str(pre_height), str(width), str(height), | |
172 | ' height="{}"' \ |
|
193 | full=self.file.url, image_meta=metadata) | |
173 | ' data-width="{}"' \ |
|
|||
174 | ' data-height="{}" />' \ |
|
|||
175 | '</a>' \ |
|
|||
176 | .format(CSS_CLASS_THUMB, |
|
|||
177 | thumb_url, |
|
|||
178 | self.hash, |
|
|||
179 | str(pre_width), |
|
|||
180 | str(pre_height), str(width), str(height), |
|
|||
181 | full=self.file.url, image_meta=metadata) |
|
|||
182 |
|
194 | |||
183 |
|
195 | |||
184 | class UrlViewer(AbstractViewer): |
|
196 | class UrlViewer(AbstractViewer): | |
@@ -187,10 +199,7 b' class UrlViewer(AbstractViewer):' | |||||
187 | return file_type is None |
|
199 | return file_type is None | |
188 |
|
200 | |||
189 | def get_view(self): |
|
201 | def get_view(self): | |
190 | return '<div class="image">' \ |
|
202 | return URL_VIEW.format(self.get_format_view(), get_domain(self.url)) | |
191 | '{}' \ |
|
|||
192 | '<div class="image-metadata">{}</div>' \ |
|
|||
193 | '</div>'.format(self.get_format_view(), get_domain(self.url)) |
|
|||
194 |
|
203 | |||
195 | def get_format_view(self): |
|
204 | def get_format_view(self): | |
196 | protocol = self.url.split(':')[0] |
|
205 | protocol = self.url.split(':')[0] | |
@@ -208,9 +217,7 b' class UrlViewer(AbstractViewer):' | |||||
208 | image = static(image_path) |
|
217 | image = static(image_path) | |
209 | w, h = get_static_dimensions(image_path) |
|
218 | w, h = get_static_dimensions(image_path) | |
210 |
|
219 | |||
211 | return '<a href="{}">' \ |
|
220 | return URL_FORMAT_VIEW.format(self.url, image, w, h) | |
212 | '<img class="url-image" src="{}" width="{}" height="{}"/>' \ |
|
|||
213 | '</a>'.format(self.url, image, w, h) |
|
|||
214 |
|
221 | |||
215 | @cached_result() |
|
222 | @cached_result() | |
216 | def _find_image_for_domains(self, domain): |
|
223 | def _find_image_for_domains(self, domain): |
General Comments 0
You need to be logged in to leave comments.
Login now