mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-06-03 16:35:50 +02:00
Spellchecking in validators.py
This commit is contained in:
parent
345a713777
commit
ae73fec2a0
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
#TODO: can we use the builtin Django validator instead?
|
||||||
|
# see: https://docs.djangoproject.com/en/4.0/ref/validators/#fileextensionvalidator
|
||||||
def validate_file_extension(value):
|
def validate_file_extension(value):
|
||||||
import os
|
import os
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
@ -11,13 +13,13 @@ def validate_file_extension(value):
|
|||||||
# TODO: we might improve this with more thorough checks of file types
|
# TODO: we might improve this with more thorough checks of file types
|
||||||
# rather than just the extensions.
|
# rather than just the extensions.
|
||||||
|
|
||||||
# check if VALID_EXTENSTIONS is defined in settings.py
|
# check if VALID_EXTENSIONS is defined in settings.py
|
||||||
# if not use defaults
|
# if not use defaults
|
||||||
|
|
||||||
if settings.VALID_EXTENSTIONS:
|
if settings.VALID_EXTENSIONS:
|
||||||
valid_extenstions = settings.VALID_EXTENSTIONS
|
valid_extensions = settings.VALID_EXTENSIONS
|
||||||
else:
|
else:
|
||||||
valid_extenstions = ['.txt', '.pdf', '.doc', '.docx', '.odt', '.jpg', '.png']
|
valid_extensions = ['.txt', '.pdf', '.doc', '.docx', '.odt', '.jpg', '.png']
|
||||||
|
|
||||||
if not ext.lower() in valid_extenstions:
|
if not ext.lower() in valid_extensions:
|
||||||
raise ValidationError('Unsupported file extension.')
|
raise ValidationError('Unsupported file extension.')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user