##// END OF EJS Templates
Gif is an image, not an attachment file
Gif is an image, not an attachment file

File last commit:

r1275:ec03da5d default
r1277:87234f05 default
Show More
viewers.py
40 lines | 1.2 KiB | text/x-python | PythonLexer
neko259
Added support for different attachment types
r1273 from django.template.defaultfilters import filesizeformat
neko259
Use proper cached static image for unknown file
r1275 from django.templatetags.static import static
neko259
Added support for different attachment types
r1273
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="{}">'\
neko259
Use proper cached static image for unknown file
r1275 '<img src="{}" width="200" height="150"/>'\
neko259
Added support for different attachment types
r1273 '</a>'\
'<div class="image-metadata">{}, {}</div>'\
neko259
Use proper cached static image for unknown file
r1275 '</div>'.format(self.file.url, static('images/file.png'), self.file_type,
neko259
Added support for different attachment types
r1273 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)