mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-08-09 16:15:12 +02:00
Add attachment validator when uploading attachment to tickets
This commit is contained in:
15
helpdesk/validators.py
Normal file
15
helpdesk/validators.py
Normal file
@ -0,0 +1,15 @@
|
||||
# validators.py
|
||||
#
|
||||
# validators for file uploads, etc.
|
||||
|
||||
|
||||
|
||||
def validate_file_extension(value):
|
||||
import os
|
||||
from django.core.exceptions import ValidationError
|
||||
ext = os.path.splitext(value.name)[1] # [0] returns path+filename
|
||||
valid_extensions = ['.txt', '.pdf', '.doc', '.docx', '.odt', '.jpg', '.png']
|
||||
# TODO: we might improve this with more thorough checks of file types
|
||||
# rather than just the extensions.
|
||||
if not ext.lower() in valid_extensions:
|
||||
raise ValidationError('Unsupported file extension.')
|
Reference in New Issue
Block a user