##// END OF EJS Templates
Video formats are not limited to webm
neko259 -
r1307:ba607abe default
parent child Browse files
Show More
@@ -1,67 +1,70 b''
1 1 from django.template.defaultfilters import filesizeformat
2 2 from django.contrib.staticfiles.templatetags.staticfiles import static
3 3
4 4 FILE_STUB_IMAGE = 'images/file.png'
5 5
6 FILE_TYPE_WEBM = 'webm'
6 FILE_TYPES_VIDEO = (
7 'webm',
8 'mp4',
9 )
7 10 FILE_TYPE_SVG = 'svg'
8 11 FILE_TYPES_AUDIO = (
9 12 'ogg',
10 13 'mp3',
11 14 )
12 15
13 16
14 17 def get_viewers():
15 18 return AbstractViewer.__subclasses__()
16 19
17 20
18 21 class AbstractViewer:
19 22 def __init__(self, file, file_type):
20 23 self.file = file
21 24 self.file_type = file_type
22 25
23 26 @staticmethod
24 27 def supports(file_type):
25 28 return True
26 29
27 30 def get_view(self):
28 31 return '<div class="image">'\
29 32 '{}'\
30 33 '<div class="image-metadata">{}, {}</div>'\
31 34 '</div>'.format(self.get_format_view(),
32 35 self.file_type, filesizeformat(self.file.size))
33 36
34 37 def get_format_view(self):
35 38 return '<a href="{}">'\
36 39 '<img src="{}" width="200" height="150"/>'\
37 40 '</a>'.format(self.file.url,static(FILE_STUB_IMAGE))
38 41
39 42
40 class WebmViewer(AbstractViewer):
43 class VideoViewer(AbstractViewer):
41 44 @staticmethod
42 45 def supports(file_type):
43 return file_type == FILE_TYPE_WEBM
46 return file_type in FILE_TYPES_VIDEO
44 47
45 48 def get_format_view(self):
46 49 return '<video width="200" height="150" controls src="{}"></video>'\
47 50 .format(self.file.url)
48 51
49 52
50 53 class AudioViewer(AbstractViewer):
51 54 @staticmethod
52 55 def supports(file_type):
53 56 return file_type in FILE_TYPES_AUDIO
54 57
55 58 def get_format_view(self):
56 59 return '<audio controls src="{}"></audio>'.format(self.file.url)
57 60
58 61
59 62 class SvgViewer(AbstractViewer):
60 63 @staticmethod
61 64 def supports(file_type):
62 65 return file_type == FILE_TYPE_SVG
63 66
64 67 def get_format_view(self):
65 68 return '<a class="thumb" href="{}">'\
66 69 '<img class="post-image-preview" width="200" height="150" src="{}" />'\
67 70 '</a>'.format(self.file.url, self.file.url)
General Comments 0
You need to be logged in to leave comments. Login now