diff --git a/boards/forms.py b/boards/forms.py --- a/boards/forms.py +++ b/boards/forms.py @@ -55,6 +55,7 @@ MIMETYPE_EXTENSIONS = { 'application/pdf': 'pdf', 'x-diff': 'diff', 'image/svg+xml': 'svg', + 'application/x-shockwave-flash': 'swf', } 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 @@ -2,7 +2,7 @@ from django.db import models from boards import utils from boards.models.attachment.viewers import get_viewers, AbstractViewer -from boards.utils import get_upload_filename, get_file_mimetype +from boards.utils import get_upload_filename, get_file_mimetype, get_extension class AttachmentManager(models.Manager): @@ -13,7 +13,7 @@ class AttachmentManager(models.Manager): attachment = existing[0] else: # FIXME Use full mimetype here, need to modify viewers too - file_type = get_file_mimetype(file).split('/')[-1] + file_type = get_extension(file.name) attachment = self.create(file=file, mimetype=file_type, hash=file_hash) diff --git a/boards/utils.py b/boards/utils.py --- a/boards/utils.py +++ b/boards/utils.py @@ -127,9 +127,13 @@ def validate_file_size(size: int): % str(max_size)) +def get_extension(filename): + return filename.split(FILE_EXTENSION_DELIMITER)[-1:][0] + + def get_upload_filename(model_instance, old_filename): # TODO Use something other than random number in file name - extension = old_filename.split(FILE_EXTENSION_DELIMITER)[-1:][0] + extension = get_extension(old_filename) new_name = '{}{}.{}'.format( str(int(time.mktime(time.gmtime()))), str(int(random() * 1000)),