##// END OF EJS Templates
Autodetect attachment viewers by getting all abstract viewer subclasses
neko259 -
r1286:7f80fc70 default
parent child Browse files
Show More
@@ -6,18 +6,12 b' from random import random'
6
6
7 from django.db import models
7 from django.db import models
8
8
9 from boards.models.attachment.viewers import AbstractViewer, WebmViewer, \
9 from boards.models.attachment.viewers import get_viewers, AbstractViewer
10 AudioViewer, SvgViewer
10
11
11
12 FILES_DIRECTORY = 'files/'
12 FILES_DIRECTORY = 'files/'
13 FILE_EXTENSION_DELIMITER = '.'
13 FILE_EXTENSION_DELIMITER = '.'
14
14
15 VIEWERS = (
16 WebmViewer,
17 AudioViewer,
18 SvgViewer,
19 )
20
21
15
22 class AttachmentManager(models.Manager):
16 class AttachmentManager(models.Manager):
23 def create_with_hash(self, file):
17 def create_with_hash(self, file):
@@ -65,7 +59,7 b' class Attachment(models.Model):'
65
59
66 def get_view(self):
60 def get_view(self):
67 file_viewer = None
61 file_viewer = None
68 for viewer in VIEWERS:
62 for viewer in get_viewers():
69 if viewer.supports(self.mimetype):
63 if viewer.supports(self.mimetype):
70 file_viewer = viewer(self.file, self.mimetype)
64 file_viewer = viewer(self.file, self.mimetype)
71 break
65 break
@@ -11,6 +11,10 b' FILE_TYPES_AUDIO = ('
11 )
11 )
12
12
13
13
14 def get_viewers():
15 return AbstractViewer.__subclasses__()
16
17
14 class AbstractViewer:
18 class AbstractViewer:
15 def __init__(self, file, file_type):
19 def __init__(self, file, file_type):
16 self.file = file
20 self.file = file
General Comments 0
You need to be logged in to leave comments. Login now