##// 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 3 from django.core.files.images import get_image_dimensions
2 4 from django.template.defaultfilters import filesizeformat
3 5 from django.contrib.staticfiles.templatetags.staticfiles import static
6 from django.contrib.staticfiles import finders
4 7
5 8 FILE_STUB_IMAGE = 'images/file.png'
6 9 FILE_STUB_URL = 'url'
@@ -45,6 +48,11 b' def get_viewers():'
45 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 56 class AbstractViewer:
49 57 def __init__(self, file, file_type, hash, url):
50 58 self.file = file
@@ -70,9 +78,11 b' class AbstractViewer:'
70 78 else:
71 79 image = FILE_STUB_IMAGE
72 80
81 w, h = get_static_dimensions(image)
82
73 83 return '<a href="{}">'\
74 '<img class="url-image" src="{}" width="200" height="150"/>'\
75 '</a>'.format(self.file.url, static(image))
84 '<img class="url-image" src="{}" width="{}" height="{}"/>'\
85 '</a>'.format(self.file.url, static(image), w, h)
76 86
77 87
78 88 class VideoViewer(AbstractViewer):
@@ -153,6 +163,8 b' class UrlViewer(AbstractViewer):'
153 163 url_image_name = URL_PROTOCOLS.get(protocol, FILE_STUB_URL)
154 164 image = static('images/' + url_image_name + '.png')
155 165
166 w, h = get_static_dimensions('images/' + url_image_name + '.png')
167
156 168 return '<a href="{}">' \
157 '<img class="url-image" src="{}" width="200" height="150"/>' \
158 '</a>'.format(self.url, image)
169 '<img class="url-image" src="{}" width="{}" height="{}"/>' \
170 '</a>'.format(self.url, image, w, h)
General Comments 0
You need to be logged in to leave comments. Login now