##// END OF EJS Templates
Deduplicated file hash calculation method
Deduplicated file hash calculation method

File last commit:

r1300:cc50b489 default
r1305:8d3d0486 default
Show More
viewers.py
67 lines | 1.8 KiB | text/x-python | PythonLexer
neko259
Added support for different attachment types
r1273 from django.template.defaultfilters import filesizeformat
neko259
Updated file image
r1290 from django.contrib.staticfiles.templatetags.staticfiles import static
neko259
Added support for different attachment types
r1273
neko259
Support audio viewer
r1279 FILE_STUB_IMAGE = 'images/file.png'
FILE_TYPE_WEBM = 'webm'
neko259
Added basic SVG support
r1284 FILE_TYPE_SVG = 'svg'
neko259
Support audio viewer
r1279 FILE_TYPES_AUDIO = (
'ogg',
'mp3',
)
neko259
Added support for different attachment types
r1273
neko259
Autodetect attachment viewers by getting all abstract viewer subclasses
r1286 def get_viewers():
return AbstractViewer.__subclasses__()
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 supports(file_type):
neko259
Support audio viewer
r1279 return True
neko259
Added support for different attachment types
r1273
def get_view(self):
neko259
Show file metadata for all attachments
r1300 return '<div class="image">'\
'{}'\
'<div class="image-metadata">{}, {}</div>'\
'</div>'.format(self.get_format_view(),
self.file_type, filesizeformat(self.file.size))
def get_format_view(self):
return '<a href="{}">'\
neko259
Use proper cached static image for unknown file
r1275 '<img src="{}" width="200" height="150"/>'\
neko259
Show file metadata for all attachments
r1300 '</a>'.format(self.file.url,static(FILE_STUB_IMAGE))
neko259
Added support for different attachment types
r1273
class WebmViewer(AbstractViewer):
@staticmethod
def supports(file_type):
neko259
Support audio viewer
r1279 return file_type == FILE_TYPE_WEBM
neko259
Added support for different attachment types
r1273
neko259
Show file metadata for all attachments
r1300 def get_format_view(self):
return '<video width="200" height="150" controls src="{}"></video>'\
.format(self.file.url)
neko259
Added support for different attachment types
r1273
neko259
Support audio viewer
r1279
class AudioViewer(AbstractViewer):
@staticmethod
def supports(file_type):
return file_type in FILE_TYPES_AUDIO
neko259
Show file metadata for all attachments
r1300 def get_format_view(self):
return '<audio controls src="{}"></audio>'.format(self.file.url)
neko259
Added basic SVG support
r1284
class SvgViewer(AbstractViewer):
@staticmethod
def supports(file_type):
return file_type == FILE_TYPE_SVG
neko259
Show file metadata for all attachments
r1300 def get_format_view(self):
return '<a class="thumb" href="{}">'\
'<img class="post-image-preview" width="200" height="150" src="{}" />'\
'</a>'.format(self.file.url, self.file.url)