Conversion date naissance étudiant. complète #593.

This commit is contained in:
Emmanuel Viennet 2024-03-24 10:34:02 +01:00 committed by Iziram
parent 8ecaa2bed0
commit 68128c27d5
2 changed files with 12 additions and 4 deletions

View File

@ -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()

View File

@ -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"]