Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
use existant function, DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreJunod committed May 24, 2024
1 parent 8b76b49 commit 397cf8c
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions geocity/apps/submissions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,6 @@ def set_field_value(self, form, field, value):
)
is_file = field.input_type == Field.INPUT_TYPE_FILE
is_date = field.input_type == Field.INPUT_TYPE_DATE
# TODO this doesn’t seem to be used? Remove?
is_address = field.input_type == Field.INPUT_TYPE_ADDRESS

if value == "" or value is None:
existing_value_obj.delete()
Expand Down Expand Up @@ -759,18 +757,10 @@ def set_field_value(self, form, field, value):
directory, "{}_{}_{}{}".format(form.pk, field.pk, file_uuid, ext)
)

# Check that extension is allowed in field configuration if additional restriction is defined in admin
if field.allowed_file_types:
if upper_ext not in field.allowed_file_types.upper():
logger.warning(
f"Attempt to upload unauthorized file type for file ({value.name})"
)
# FIXME: send the validation error correctly to the form as this will in fact only raise a generic error to the user
raise ValidationError(
_(
f"L'extension du fichier n'est pas autorisé pour ce document"
)
)
# Check file size and extension
from . import services

services.validate_file(value)

private_storage.save(path, value)

Expand Down

0 comments on commit 397cf8c

Please sign in to comment.