diff --git a/boards/models/attachment/__init__.py b/boards/models/attachment/__init__.py --- a/boards/models/attachment/__init__.py +++ b/boards/models/attachment/__init__.py @@ -6,18 +6,12 @@ from random import random from django.db import models -from boards.models.attachment.viewers import AbstractViewer, WebmViewer, \ - AudioViewer, SvgViewer +from boards.models.attachment.viewers import get_viewers, AbstractViewer + FILES_DIRECTORY = 'files/' FILE_EXTENSION_DELIMITER = '.' -VIEWERS = ( - WebmViewer, - AudioViewer, - SvgViewer, -) - class AttachmentManager(models.Manager): def create_with_hash(self, file): @@ -65,7 +59,7 @@ class Attachment(models.Model): def get_view(self): file_viewer = None - for viewer in VIEWERS: + for viewer in get_viewers(): if viewer.supports(self.mimetype): file_viewer = viewer(self.file, self.mimetype) break diff --git a/boards/models/attachment/viewers.py b/boards/models/attachment/viewers.py --- a/boards/models/attachment/viewers.py +++ b/boards/models/attachment/viewers.py @@ -11,6 +11,10 @@ FILE_TYPES_AUDIO = ( ) +def get_viewers(): + return AbstractViewer.__subclasses__() + + class AbstractViewer: def __init__(self, file, file_type): self.file = file