mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 09:18:23 +02:00
Detect when a solution has more than 30 pages
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
|
||||
import re
|
||||
|
||||
from PyPDF3 import PdfFileReader
|
||||
from bootstrap_datepicker_plus import DatePickerInput, DateTimePickerInput
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
@ -115,6 +116,19 @@ class TournamentForm(forms.ModelForm):
|
||||
|
||||
|
||||
class SolutionForm(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 5 Mo."))
|
||||
if file.content_type != "application/pdf":
|
||||
raise ValidationError(_("The uploaded file must be a PDF file."))
|
||||
pdf_reader = PdfFileReader(file)
|
||||
pages = len(pdf_reader.pages)
|
||||
if pages > 30:
|
||||
raise ValidationError(_("The PDF file must not have more than 30 pages."))
|
||||
return self.cleaned_data["photo_authorization"]
|
||||
|
||||
def save(self, commit=True):
|
||||
"""
|
||||
Don't save a solution with this way. Use a view instead
|
||||
|
Reference in New Issue
Block a user