##// END OF EJS Templates
Use proper cached static image for unknown file
neko259 -
r1275:ec03da5d default
parent child Browse files
Show More
@@ -1,39 +1,40 b''
1 from django.template.defaultfilters import filesizeformat
1 from django.template.defaultfilters import filesizeformat
2 from django.templatetags.static import static
2
3
3
4
4 class AbstractViewer:
5 class AbstractViewer:
5 def __init__(self, file, file_type):
6 def __init__(self, file, file_type):
6 self.file = file
7 self.file = file
7 self.file_type = file_type
8 self.file_type = file_type
8
9
9 @staticmethod
10 @staticmethod
10 def get_viewer(file_type, file):
11 def get_viewer(file_type, file):
11 for viewer in VIEWERS:
12 for viewer in VIEWERS:
12 if viewer.supports(file_type):
13 if viewer.supports(file_type):
13 return viewer(file)
14 return viewer(file)
14 return AbstractViewer(file)
15 return AbstractViewer(file)
15
16
16 @staticmethod
17 @staticmethod
17 def supports(file_type):
18 def supports(file_type):
18 return true
19 return true
19
20
20 def get_view(self):
21 def get_view(self):
21 return '<div class="image"><a href="{}">'\
22 return '<div class="image"><a href="{}">'\
22 '<img src="/static/images/file.png" width="200" height="150"/>'\
23 '<img src="{}" width="200" height="150"/>'\
23 '</a>'\
24 '</a>'\
24 '<div class="image-metadata">{}, {}</div>'\
25 '<div class="image-metadata">{}, {}</div>'\
25 '</div>'.format(self.file.url, self.file_type,
26 '</div>'.format(self.file.url, static('images/file.png'), self.file_type,
26 filesizeformat(self.file.size))
27 filesizeformat(self.file.size))
27
28
28
29
29 class WebmViewer(AbstractViewer):
30 class WebmViewer(AbstractViewer):
30 @staticmethod
31 @staticmethod
31 def supports(file_type):
32 def supports(file_type):
32 return file_type == 'webm'
33 return file_type == 'webm'
33
34
34 def get_view(self):
35 def get_view(self):
35 return '<div class="image">'\
36 return '<div class="image">'\
36 '<video width="200" height="150" controls/>'\
37 '<video width="200" height="150" controls/>'\
37 '<source src="{}">'\
38 '<source src="{}">'\
38 '</div>'.format(self.file.url)
39 '</div>'.format(self.file.url)
39
40
General Comments 0
You need to be logged in to leave comments. Login now