##// 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 7 from django.db import models
8 8
9 from boards.models.attachment.viewers import AbstractViewer, WebmViewer, \
10 AudioViewer, SvgViewer
9 from boards.models.attachment.viewers import get_viewers, AbstractViewer
10
11 11
12 12 FILES_DIRECTORY = 'files/'
13 13 FILE_EXTENSION_DELIMITER = '.'
14 14
15 VIEWERS = (
16 WebmViewer,
17 AudioViewer,
18 SvgViewer,
19 )
20
21 15
22 16 class AttachmentManager(models.Manager):
23 17 def create_with_hash(self, file):
@@ -65,7 +59,7 b' class Attachment(models.Model):'
65 59
66 60 def get_view(self):
67 61 file_viewer = None
68 for viewer in VIEWERS:
62 for viewer in get_viewers():
69 63 if viewer.supports(self.mimetype):
70 64 file_viewer = viewer(self.file, self.mimetype)
71 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 18 class AbstractViewer:
15 19 def __init__(self, file, file_type):
16 20 self.file = file
General Comments 0
You need to be logged in to leave comments. Login now