From 80bd02114ed674e1e02d7864742631706dd0977d Mon Sep 17 00:00:00 2001 From: Iziram Date: Fri, 31 May 2024 10:13:22 +0200 Subject: [PATCH] =?UTF-8?q?Assiduit=C3=A9=20:=20erreurs=20dates=20hors=20s?= =?UTF-8?q?emestres=20#907?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/assiduites.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/app/views/assiduites.py b/app/views/assiduites.py index d3115f9c..dda822cb 100644 --- a/app/views/assiduites.py +++ b/app/views/assiduites.py @@ -301,6 +301,7 @@ def ajout_assiduite_etud() -> str | Response: def _get_dates_from_assi_form( form: AjoutAssiOrJustForm, + etud: Identite, from_justif: bool = False, ) -> tuple[ bool, datetime.datetime | None, datetime.datetime | None, datetime.datetime | None @@ -393,6 +394,34 @@ def _get_dates_from_assi_form( dt_debut_tz_server = dt_debut_tz_server.replace(hour=0, minute=0) dt_fin_tz_server = dt_fin_tz_server.replace(hour=23, minute=59) + # Vérification dates contenu dans un semestre de l'étudiant + dates_semestres: list[tuple[datetime.date, datetime.date]] = [ + (sem.date_debut, sem.date_fin) for sem in etud.get_formsemestres() + ] + + # Vérification date début + if not any( + [ + dt_debut_tz_server.date() >= deb and dt_debut_tz_server.date() <= fin + for deb, fin in dates_semestres + ] + ): + form.set_error( + "La date de début n'appartient à aucun semestre de l'étudiant", + form.date_debut, + ) + + # Vérification date fin + if form.date_fin.data and not any( + [ + dt_fin_tz_server.date() >= deb and dt_fin_tz_server.date() <= fin + for deb, fin in dates_semestres + ] + ): + form.set_error( + "La date de fin n'appartient à aucun semestre de l'étudiant", form.date_fin + ) + dt_entry_date_tz_server = ( scu.TIME_ZONE.localize(dt_entry_date) if dt_entry_date else None ) @@ -415,7 +444,7 @@ def _record_assiduite_etud( dt_debut_tz_server, dt_fin_tz_server, dt_entry_date_tz_server, - ) = _get_dates_from_assi_form(form) + ) = _get_dates_from_assi_form(form, etud) # Le module (avec "autre") mod_data = form.modimpl.data if mod_data: @@ -724,7 +753,7 @@ def _record_justificatif_etud( dt_debut_tz_server, dt_fin_tz_server, dt_entry_date_tz_server, - ) = _get_dates_from_assi_form(form, from_justif=True) + ) = _get_dates_from_assi_form(form, etud, from_justif=True) if not ok: log("_record_justificatif_etud: dates invalides") form.set_error("Erreur: dates invalides")