# HG changeset patch # User neko259 # Date 2016-10-20 15:30:41 # Node ID 308a708f674b4cd95d56625da2e276341d1e67f3 # Parent 0b52d25186ec8a936a16c43711b3db42a28deb27 Use real image stub sizes, not 200x150 diff --git a/boards/models/attachment/viewers.py b/boards/models/attachment/viewers.py --- a/boards/models/attachment/viewers.py +++ b/boards/models/attachment/viewers.py @@ -1,6 +1,9 @@ +import os + from django.core.files.images import get_image_dimensions from django.template.defaultfilters import filesizeformat from django.contrib.staticfiles.templatetags.staticfiles import static +from django.contrib.staticfiles import finders FILE_STUB_IMAGE = 'images/file.png' FILE_STUB_URL = 'url' @@ -45,6 +48,11 @@ def get_viewers(): return AbstractViewer.__subclasses__() +def get_static_dimensions(filename): + file_path = finders.find(filename) + return get_image_dimensions(file_path) + + class AbstractViewer: def __init__(self, file, file_type, hash, url): self.file = file @@ -70,9 +78,11 @@ class AbstractViewer: else: image = FILE_STUB_IMAGE + w, h = get_static_dimensions(image) + return ''\ - ''\ - ''.format(self.file.url, static(image)) + ''\ + ''.format(self.file.url, static(image), w, h) class VideoViewer(AbstractViewer): @@ -153,6 +163,8 @@ class UrlViewer(AbstractViewer): url_image_name = URL_PROTOCOLS.get(protocol, FILE_STUB_URL) image = static('images/' + url_image_name + '.png') + w, h = get_static_dimensions('images/' + url_image_name + '.png') + return '' \ - '' \ - ''.format(self.url, image) + '' \ + ''.format(self.url, image, w, h)