##// END OF EJS Templates
Use proper cached static image for unknown file
Use proper cached static image for unknown file

File last commit:

r1275:ec03da5d default
r1275:ec03da5d default
Show More
viewers.py
40 lines | 1.2 KiB | text/x-python | PythonLexer
from django.template.defaultfilters import filesizeformat
from django.templatetags.static import static
class AbstractViewer:
def __init__(self, file, file_type):
self.file = file
self.file_type = file_type
@staticmethod
def get_viewer(file_type, file):
for viewer in VIEWERS:
if viewer.supports(file_type):
return viewer(file)
return AbstractViewer(file)
@staticmethod
def supports(file_type):
return true
def get_view(self):
return '<div class="image"><a href="{}">'\
'<img src="{}" width="200" height="150"/>'\
'</a>'\
'<div class="image-metadata">{}, {}</div>'\
'</div>'.format(self.file.url, static('images/file.png'), self.file_type,
filesizeformat(self.file.size))
class WebmViewer(AbstractViewer):
@staticmethod
def supports(file_type):
return file_type == 'webm'
def get_view(self):
return '<div class="image">'\
'<video width="200" height="150" controls/>'\
'<source src="{}">'\
'</div>'.format(self.file.url)