From 3e0e6ae7b415defd7802d603e8e5342b93ecca8d Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 19 Jan 2021 00:33:44 +0100 Subject: [PATCH] Check that syntheses are valid files --- apps/participation/forms.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/participation/forms.py b/apps/participation/forms.py index 1d619d0..b7032cb 100644 --- a/apps/participation/forms.py +++ b/apps/participation/forms.py @@ -119,7 +119,7 @@ class SolutionForm(forms.ModelForm): def clean_file(self): if "file" in self.files: file = self.files["file"] - if file.size > 2e6: + if file.size > 5e6: raise ValidationError(_("The uploaded file size must be under 5 Mo.")) if file.content_type != "application/pdf": raise ValidationError(_("The uploaded file must be a PDF file.")) @@ -179,6 +179,15 @@ class PassageForm(forms.ModelForm): class SynthesisForm(forms.ModelForm): + def clean_file(self): + if "file" in self.files: + file = self.files["file"] + if file.size > 2e6: + raise ValidationError(_("The uploaded file size must be under 2 Mo.")) + if file.content_type != "application/pdf": + raise ValidationError(_("The uploaded file must be a PDF file.")) + return self.cleaned_data["photo_authorization"] + def save(self, commit=True): """ Don't save a synthesis with this way. Use a view instead