Increase nginx upload limit to have a better message in the Django form

This commit is contained in:
Yohann D'ANELLO 2020-12-22 20:40:01 +01:00
parent 996d00c7f0
commit 8f742b8e14
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 8 additions and 6 deletions

View File

@ -72,12 +72,13 @@ class PhotoAuthorizationForm(forms.ModelForm):
Form to send a photo authorization.
"""
def clean_photo_authorization(self):
if "photo_authorization" not in self.files:
raise ValidationError(_("The uploaded file size must be under 2 Mo."))
file = self.files["photo_authorization"]
if file.content_type not in ["application/pdf", "image/png", "image/jpeg"]:
raise ValidationError(_("The uploaded file must be a PDF, PNG of JPEG file."))
return self.cleaned_data["photo_authorization"]
if "photo_authorization" in self.files:
file = self.files["photo_authorization"]
if file.size > 2e6:
raise ValidationError(_("The uploaded file size must be under 2 Mo."))
if file.content_type not in ["application/pdf", "image/png", "image/jpeg"]:
raise ValidationError(_("The uploaded file must be a PDF, PNG of JPEG file."))
return self.cleaned_data["photo_authorization"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

View File

@ -5,6 +5,7 @@ upstream corres2math {
server {
listen 80;
server_name corres2math;
client_max_body_size 50M;
location / {
proxy_pass http://corres2math;