##// END OF EJS Templates
Use real image stub sizes, not 200x150
neko259 -
r1684:308a708f default
parent child Browse files
Show More
@@ -1,6 +1,9 b''
1 import os
2
1 from django.core.files.images import get_image_dimensions
3 from django.core.files.images import get_image_dimensions
2 from django.template.defaultfilters import filesizeformat
4 from django.template.defaultfilters import filesizeformat
3 from django.contrib.staticfiles.templatetags.staticfiles import static
5 from django.contrib.staticfiles.templatetags.staticfiles import static
6 from django.contrib.staticfiles import finders
4
7
5 FILE_STUB_IMAGE = 'images/file.png'
8 FILE_STUB_IMAGE = 'images/file.png'
6 FILE_STUB_URL = 'url'
9 FILE_STUB_URL = 'url'
@@ -45,6 +48,11 b' def get_viewers():'
45 return AbstractViewer.__subclasses__()
48 return AbstractViewer.__subclasses__()
46
49
47
50
51 def get_static_dimensions(filename):
52 file_path = finders.find(filename)
53 return get_image_dimensions(file_path)
54
55
48 class AbstractViewer:
56 class AbstractViewer:
49 def __init__(self, file, file_type, hash, url):
57 def __init__(self, file, file_type, hash, url):
50 self.file = file
58 self.file = file
@@ -70,9 +78,11 b' class AbstractViewer:'
70 else:
78 else:
71 image = FILE_STUB_IMAGE
79 image = FILE_STUB_IMAGE
72
80
81 w, h = get_static_dimensions(image)
82
73 return '<a href="{}">'\
83 return '<a href="{}">'\
74 '<img class="url-image" src="{}" width="200" height="150"/>'\
84 '<img class="url-image" src="{}" width="{}" height="{}"/>'\
75 '</a>'.format(self.file.url, static(image))
85 '</a>'.format(self.file.url, static(image), w, h)
76
86
77
87
78 class VideoViewer(AbstractViewer):
88 class VideoViewer(AbstractViewer):
@@ -153,6 +163,8 b' class UrlViewer(AbstractViewer):'
153 url_image_name = URL_PROTOCOLS.get(protocol, FILE_STUB_URL)
163 url_image_name = URL_PROTOCOLS.get(protocol, FILE_STUB_URL)
154 image = static('images/' + url_image_name + '.png')
164 image = static('images/' + url_image_name + '.png')
155
165
166 w, h = get_static_dimensions('images/' + url_image_name + '.png')
167
156 return '<a href="{}">' \
168 return '<a href="{}">' \
157 '<img class="url-image" src="{}" width="200" height="150"/>' \
169 '<img class="url-image" src="{}" width="{}" height="{}"/>' \
158 '</a>'.format(self.url, image)
170 '</a>'.format(self.url, image, w, h)
General Comments 0
You need to be logged in to leave comments. Login now