From 203f3a53428a6a367a9cb440b28f19b1026383ed Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 24 Mar 2024 10:34:02 +0100 Subject: [PATCH] =?UTF-8?q?Conversion=20date=20naissance=20=C3=A9tudiant.?= =?UTF-8?q?=20compl=C3=A8te=20#593.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/notesdb.py | 2 +- app/views/scolar.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/scodoc/notesdb.py b/app/scodoc/notesdb.py index 5aa5c91b..0f72cd01 100644 --- a/app/scodoc/notesdb.py +++ b/app/scodoc/notesdb.py @@ -480,7 +480,7 @@ def DateDMYtoISO(dmy: str, null_is_empty=False) -> str | None: try: dt = datetime.datetime.fromisoformat(dmy) except ValueError as exc: - raise ValueError(f'Date (j/m/a or iso) invalide: "{dmy}"') from exc + raise ScoValueError(f'Date (j/m/a or iso) invalide: "{dmy}"') from exc return dt.date().isoformat() diff --git a/app/views/scolar.py b/app/views/scolar.py index f20e24c5..6cb7a357 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -1365,6 +1365,15 @@ def etudident_edit_form(): return _etudident_create_or_edit_form(edit=True) +def _validate_date_naissance(val: str, field) -> bool: + "vrai si date saisie valide" + try: + date_naissance = scu.convert_fr_date(val) + except ScoValueError: + return False + return date_naissance < datetime.datetime.now() + + def _etudident_create_or_edit_form(edit): "Le formulaire HTML" H = [html_sco_header.sco_header()] @@ -1506,8 +1515,7 @@ def _etudident_create_or_edit_form(edit): "title": "Date de naissance", "input_type": "date", "explanation": "j/m/a", - "validator": lambda val, _: DMY_REGEXP.match(val) - and (ndb.DateDMYtoISO(val) < datetime.date.today().isoformat()), + "validator": _validate_date_naissance, }, ), ("lieu_naissance", {"title": "Lieu de naissance", "size": 32}), @@ -1779,7 +1787,7 @@ def _etudident_create_or_edit_form(edit): + homonyms_html + F ) - + tf[2]["date_naissance"] = scu.convert_fr_date(tf[2]["date_naissance"]) if not edit: etud = sco_etud.create_etud(cnx, args=tf[2]) etudid = etud["etudid"]