##// END OF EJS Templates
Simplify adding new domain images. Not there is no separate dict, just searching a file by name from a static finder
neko259 -
r1718:d0d5dc51 default
parent child Browse files
Show More
@@ -5,7 +5,6 b' from django.contrib.staticfiles.template'
5 from django.core.files.images import get_image_dimensions
5 from django.core.files.images import get_image_dimensions
6 from django.template.defaultfilters import filesizeformat
6 from django.template.defaultfilters import filesizeformat
7
7
8 from boards.models.attachment.domains import URL_DOMAINS
9
8
10 REGEX_DOMAIN = re.compile(r'(\w+\.)*(\w+\.\w+)')
9 REGEX_DOMAIN = re.compile(r'(\w+\.)*(\w+\.\w+)')
11
10
@@ -60,6 +59,11 b' def get_static_dimensions(filename):'
60 return get_image_dimensions(file_path)
59 return get_image_dimensions(file_path)
61
60
62
61
62 # TODO Move this to utils
63 def file_exists(filename):
64 return finders.find(filename) is not None
65
66
63 class AbstractViewer:
67 class AbstractViewer:
64 def __init__(self, file, file_type, hash, url):
68 def __init__(self, file, file_type, hash, url):
65 self.file = file
69 self.file = file
@@ -172,14 +176,16 b' class UrlViewer(AbstractViewer):'
172
176
173 if protocol in URL_PROTOCOLS:
177 if protocol in URL_PROTOCOLS:
174 url_image_name = URL_PROTOCOLS.get(protocol)
178 url_image_name = URL_PROTOCOLS.get(protocol)
175 elif domain in URL_DOMAINS:
176 url_image_name = 'domains/' + URL_DOMAINS.get(domain)
177 else:
179 else:
178 url_image_name = FILE_STUB_URL
180 filename = 'images/domains/{}.png'.format(domain)
181 if file_exists(filename):
182 url_image_name = 'domains/' + domain
183 else:
184 url_image_name = FILE_STUB_URL
179
185
180 image = static('images/' + url_image_name + '.png')
186 image_path = 'images/{}.png'.format(url_image_name)
181
187 image = static(image_path)
182 w, h = get_static_dimensions('images/' + url_image_name + '.png')
188 w, h = get_static_dimensions(image_path)
183
189
184 return '<a href="{}">' \
190 return '<a href="{}">' \
185 '<img class="url-image" src="{}" width="{}" height="{}"/>' \
191 '<img class="url-image" src="{}" width="{}" height="{}"/>' \
1 NO CONTENT: file renamed from boards/static/images/domains/meduza.png to boards/static/images/domains/meduza.io.png
NO CONTENT: file renamed from boards/static/images/domains/meduza.png to boards/static/images/domains/meduza.io.png
1 NO CONTENT: file renamed from boards/static/images/domains/wikipedia.png to boards/static/images/domains/wikipedia.org.png
NO CONTENT: file renamed from boards/static/images/domains/wikipedia.png to boards/static/images/domains/wikipedia.org.png
1 NO CONTENT: file renamed from boards/static/images/domains/youtube.png to boards/static/images/domains/youtu.be.png
NO CONTENT: file renamed from boards/static/images/domains/youtube.png to boards/static/images/domains/youtu.be.png
1 NO CONTENT: file copied from boards/static/images/domains/youtube.png to boards/static/images/domains/youtube.com.png
NO CONTENT: file copied from boards/static/images/domains/youtube.png to boards/static/images/domains/youtube.com.png
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now