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