##// END OF EJS Templates
Recognize flash mimetype properly. Store extension as mimetype in attachment...
neko259 -
r1382:8669bd71 default
parent child Browse files
Show More
@@ -55,6 +55,7 b' MIMETYPE_EXTENSIONS = {'
55 55 'application/pdf': 'pdf',
56 56 'x-diff': 'diff',
57 57 'image/svg+xml': 'svg',
58 'application/x-shockwave-flash': 'swf',
58 59 }
59 60
60 61
@@ -2,7 +2,7 b' from django.db import models'
2 2
3 3 from boards import utils
4 4 from boards.models.attachment.viewers import get_viewers, AbstractViewer
5 from boards.utils import get_upload_filename, get_file_mimetype
5 from boards.utils import get_upload_filename, get_file_mimetype, get_extension
6 6
7 7
8 8 class AttachmentManager(models.Manager):
@@ -13,7 +13,7 b' class AttachmentManager(models.Manager):'
13 13 attachment = existing[0]
14 14 else:
15 15 # FIXME Use full mimetype here, need to modify viewers too
16 file_type = get_file_mimetype(file).split('/')[-1]
16 file_type = get_extension(file.name)
17 17 attachment = self.create(file=file, mimetype=file_type,
18 18 hash=file_hash)
19 19
@@ -127,9 +127,13 b' def validate_file_size(size: int):'
127 127 % str(max_size))
128 128
129 129
130 def get_extension(filename):
131 return filename.split(FILE_EXTENSION_DELIMITER)[-1:][0]
132
133
130 134 def get_upload_filename(model_instance, old_filename):
131 135 # TODO Use something other than random number in file name
132 extension = old_filename.split(FILE_EXTENSION_DELIMITER)[-1:][0]
136 extension = get_extension(old_filename)
133 137 new_name = '{}{}.{}'.format(
134 138 str(int(time.mktime(time.gmtime()))),
135 139 str(int(random() * 1000)),
General Comments 0
You need to be logged in to leave comments. Login now