Show More
@@ -52,6 +52,36 b' URL_PROTOCOLS = {' | |||
|
52 | 52 | CSS_CLASS_IMAGE = 'image' |
|
53 | 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 | 86 | def get_viewers(): |
|
57 | 87 | return AbstractViewer.__subclasses__() |
@@ -87,11 +117,7 b' class AbstractViewer:' | |||
|
87 | 117 | else: |
|
88 | 118 | search_url = '' |
|
89 | 119 | |
|
90 | return '<div class="image">'\ | |
|
91 | '{}'\ | |
|
92 | '<div class="image-metadata"><a href="{}" download >{}, {}</a>'\ | |
|
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, | |
|
120 | return ABSTRACT_VIEW.format(self.get_format_view(), self.file.url, | |
|
95 | 121 |
|
|
96 | 122 |
|
|
97 | 123 | |
@@ -106,9 +132,7 b' class AbstractViewer:' | |||
|
106 | 132 | |
|
107 | 133 | w, h = get_static_dimensions(image) |
|
108 | 134 | |
|
109 | return '<a href="{}">'\ | |
|
110 | '<img class="url-image" src="{}" width="{}" height="{}"/>'\ | |
|
111 | '</a>'.format(self.file.url, static(image), w, h) | |
|
135 | return ABSTRACT_FORMAT_VIEW.format(self.file.url, static(image), w, h) | |
|
112 | 136 | |
|
113 | 137 | |
|
114 | 138 | class VideoViewer(AbstractViewer): |
@@ -117,8 +141,7 b' class VideoViewer(AbstractViewer):' | |||
|
117 | 141 | return file_type in FILE_TYPES_VIDEO |
|
118 | 142 | |
|
119 | 143 | def get_format_view(self): |
|
120 | return '<video width="200" height="150" controls src="{}"></video>'\ | |
|
121 | .format(self.file.url) | |
|
144 | return VIDEO_FORMAT_VIEW.format(self.file.url) | |
|
122 | 145 | |
|
123 | 146 | |
|
124 | 147 | class AudioViewer(AbstractViewer): |
@@ -127,7 +150,7 b' class AudioViewer(AbstractViewer):' | |||
|
127 | 150 | return file_type in FILE_TYPES_AUDIO |
|
128 | 151 | |
|
129 | 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 | 156 | class SvgViewer(AbstractViewer): |
@@ -136,9 +159,7 b' class SvgViewer(AbstractViewer):' | |||
|
136 | 159 | return file_type == FILE_TYPE_SVG |
|
137 | 160 | |
|
138 | 161 | def get_format_view(self): |
|
139 | return '<a class="thumb" href="{}">'\ | |
|
140 | '<img class="post-image-preview" width="200" height="150" src="{}" />'\ | |
|
141 | '</a>'.format(self.file.url, self.file.url) | |
|
162 | return SVG_FORMAT_VIEW.format(self.file.url, self.file.url) | |
|
142 | 163 | |
|
143 | 164 | |
|
144 | 165 | class ImageViewer(AbstractViewer): |
@@ -164,16 +185,7 b' class ImageViewer(AbstractViewer):' | |||
|
164 | 185 | w, h = 200, 150 |
|
165 | 186 | thumb_url = '%s.%sx%s.%s' % (split[0], w, h, split[1]) |
|
166 | 187 | |
|
167 | return '<a class="{}" href="{full}">' \ | |
|
168 | '<img class="post-image-preview"' \ | |
|
169 | ' src="{}"' \ | |
|
170 | ' alt="{}"' \ | |
|
171 | ' width="{}"' \ | |
|
172 | ' height="{}"' \ | |
|
173 | ' data-width="{}"' \ | |
|
174 | ' data-height="{}" />' \ | |
|
175 | '</a>' \ | |
|
176 | .format(CSS_CLASS_THUMB, | |
|
188 | return IMAGE_FORMAT_VIEW.format(CSS_CLASS_THUMB, | |
|
177 | 189 |
|
|
178 | 190 |
|
|
179 | 191 |
|
@@ -187,10 +199,7 b' class UrlViewer(AbstractViewer):' | |||
|
187 | 199 | return file_type is None |
|
188 | 200 | |
|
189 | 201 | def get_view(self): |
|
190 | return '<div class="image">' \ | |
|
191 | '{}' \ | |
|
192 | '<div class="image-metadata">{}</div>' \ | |
|
193 | '</div>'.format(self.get_format_view(), get_domain(self.url)) | |
|
202 | return URL_VIEW.format(self.get_format_view(), get_domain(self.url)) | |
|
194 | 203 | |
|
195 | 204 | def get_format_view(self): |
|
196 | 205 | protocol = self.url.split(':')[0] |
@@ -208,9 +217,7 b' class UrlViewer(AbstractViewer):' | |||
|
208 | 217 | image = static(image_path) |
|
209 | 218 | w, h = get_static_dimensions(image_path) |
|
210 | 219 | |
|
211 | return '<a href="{}">' \ | |
|
212 | '<img class="url-image" src="{}" width="{}" height="{}"/>' \ | |
|
213 | '</a>'.format(self.url, image, w, h) | |
|
220 | return URL_FORMAT_VIEW.format(self.url, image, w, h) | |
|
214 | 221 | |
|
215 | 222 | @cached_result() |
|
216 | 223 | def _find_image_for_domains(self, domain): |
General Comments 0
You need to be logged in to leave comments.
Login now