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: try:
dt = datetime.datetime.fromisoformat(dmy) dt = datetime.datetime.fromisoformat(dmy)
except ValueError as exc: 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() return dt.date().isoformat()

View File

@ -1365,6 +1365,15 @@ def etudident_edit_form():
return _etudident_create_or_edit_form(edit=True) 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): def _etudident_create_or_edit_form(edit):
"Le formulaire HTML" "Le formulaire HTML"
H = [html_sco_header.sco_header()] H = [html_sco_header.sco_header()]
@ -1506,8 +1515,7 @@ def _etudident_create_or_edit_form(edit):
"title": "Date de naissance", "title": "Date de naissance",
"input_type": "date", "input_type": "date",
"explanation": "j/m/a", "explanation": "j/m/a",
"validator": lambda val, _: DMY_REGEXP.match(val) "validator": _validate_date_naissance,
and (ndb.DateDMYtoISO(val) < datetime.date.today().isoformat()),
}, },
), ),
("lieu_naissance", {"title": "Lieu de naissance", "size": 32}), ("lieu_naissance", {"title": "Lieu de naissance", "size": 32}),
@ -1779,7 +1787,7 @@ def _etudident_create_or_edit_form(edit):
+ homonyms_html + homonyms_html
+ F + F
) )
tf[2]["date_naissance"] = scu.convert_fr_date(tf[2]["date_naissance"])
if not edit: if not edit:
etud = sco_etud.create_etud(cnx, args=tf[2]) etud = sco_etud.create_etud(cnx, args=tf[2])
etudid = etud["etudid"] etudid = etud["etudid"]