Assiduité : erreurs dates hors semestres #907

This commit is contained in:
Iziram 2024-05-31 10:13:22 +02:00
parent 65a4b31fbd
commit 80bd02114e

View File

@ -301,6 +301,7 @@ def ajout_assiduite_etud() -> str | Response:
def _get_dates_from_assi_form( def _get_dates_from_assi_form(
form: AjoutAssiOrJustForm, form: AjoutAssiOrJustForm,
etud: Identite,
from_justif: bool = False, from_justif: bool = False,
) -> tuple[ ) -> tuple[
bool, datetime.datetime | None, datetime.datetime | None, datetime.datetime | None 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_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) 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 = ( dt_entry_date_tz_server = (
scu.TIME_ZONE.localize(dt_entry_date) if dt_entry_date else None 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_debut_tz_server,
dt_fin_tz_server, dt_fin_tz_server,
dt_entry_date_tz_server, dt_entry_date_tz_server,
) = _get_dates_from_assi_form(form) ) = _get_dates_from_assi_form(form, etud)
# Le module (avec "autre") # Le module (avec "autre")
mod_data = form.modimpl.data mod_data = form.modimpl.data
if mod_data: if mod_data:
@ -724,7 +753,7 @@ def _record_justificatif_etud(
dt_debut_tz_server, dt_debut_tz_server,
dt_fin_tz_server, dt_fin_tz_server,
dt_entry_date_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: if not ok:
log("_record_justificatif_etud: dates invalides") log("_record_justificatif_etud: dates invalides")
form.set_error("Erreur: dates invalides") form.set_error("Erreur: dates invalides")