mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-21 23:43:11 +01:00
24 lines
758 B
Python
24 lines
758 B
Python
# validators.py
|
|
#
|
|
# validators for file uploads, etc.
|
|
|
|
from django.conf import settings
|
|
|
|
def validate_file_extension(value):
|
|
import os
|
|
from django.core.exceptions import ValidationError
|
|
ext = os.path.splitext(value.name)[1] # [0] returns path+filename
|
|
# TODO: we might improve this with more thorough checks of file types
|
|
# rather than just the extensions.
|
|
|
|
# check if VALID_EXTENSTIONS is defined in settings.py
|
|
# if not use defaults
|
|
|
|
if settings.VALID_EXTENSTIONS:
|
|
valid_extenstions = settings.VALID_EXTENSTIONS
|
|
else:
|
|
valid_extenstions = ['.txt', '.pdf', '.doc', '.docx', '.odt', '.jpg', '.png']
|
|
|
|
if not ext.lower() in valid_extenstions:
|
|
raise ValidationError('Unsupported file extension.')
|