pycodestyle formatting

This commit is contained in:
Martin Whitehouse
2022-07-12 12:34:19 +02:00
parent d36cc7e381
commit aa876f8016
39 changed files with 892 additions and 464 deletions

View File

@ -4,8 +4,11 @@
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
# 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):
import os
from django.core.exceptions import ValidationError
@ -19,9 +22,12 @@ def validate_file_extension(value):
if hasattr(settings, 'VALID_EXTENSIONS'):
valid_extensions = settings.VALID_EXTENSIONS
else:
valid_extensions = ['.txt', '.asc', '.htm', '.html', '.pdf', '.doc', '.docx', '.odt', '.jpg', '.png', '.eml']
valid_extensions = ['.txt', '.asc', '.htm', '.html',
'.pdf', '.doc', '.docx', '.odt', '.jpg', '.png', '.eml']
if not ext.lower() in valid_extensions:
# TODO: one more check in case it is a file with no extension; we should always allow that?
# TODO: one more check in case it is a file with no extension; we
# should always allow that?
if not (ext.lower() == '' or ext.lower() == '.'):
raise ValidationError('Unsupported file extension: %s.' % ext.lower())
raise ValidationError(
'Unsupported file extension: %s.' % ext.lower())