Skip to content

Commit cf32f6c

Browse files
authored
allow for magic file path to be specified in settings
1 parent 105fb07 commit cf32f6c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

validatedfile/fields.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django import forms
33
from django.template.defaultfilters import filesizeformat
44
from django.utils.translation import ugettext as _
5+
from django.conf import settings
56

67
import magic
78

@@ -20,7 +21,11 @@ def clean(self, *args, **kwargs):
2021
if self.content_types:
2122
uploaded_content_type = getattr(file, 'content_type', '')
2223

23-
mg = magic.Magic(mime=True)
24+
magic_file_path = getattr(settings, "MAGIC_FILE_PATH", None)
25+
if (magic_file_path):
26+
mg = magic.Magic(mime=True, magic_file=magic_file_path)
27+
else:
28+
mg = magic.Magic(mime=True)
2429
content_type_magic = mg.from_buffer(
2530
file.read(self.mime_lookup_length)
2631
)

0 commit comments

Comments
 (0)