Assiduités : fix Bug module autre #710

This commit is contained in:
iziram 2023-09-04 15:05:17 +02:00
parent 69eda90eea
commit f9970a16ad

View File

@ -587,16 +587,6 @@ def _create_singular(
if fin is None: if fin is None:
errors.append("param 'date_fin': format invalide") errors.append("param 'date_fin': format invalide")
# cas 4 : moduleimpl_id
moduleimpl_id = data.get("moduleimpl_id", False)
moduleimpl: ModuleImpl = None
if moduleimpl_id not in [False, None]:
moduleimpl = ModuleImpl.query.filter_by(id=int(moduleimpl_id)).first()
if moduleimpl is None:
errors.append("param 'moduleimpl_id': invalide")
# cas 5 : desc # cas 5 : desc
desc: str = data.get("desc", None) desc: str = data.get("desc", None)
@ -606,6 +596,21 @@ def _create_singular(
if not isinstance(external_data, dict): if not isinstance(external_data, dict):
errors.append("param 'external_data' : n'est pas un objet JSON") errors.append("param 'external_data' : n'est pas un objet JSON")
# cas 4 : moduleimpl_id
moduleimpl_id = data.get("moduleimpl_id", False)
moduleimpl: ModuleImpl = None
if moduleimpl_id not in [False, None]:
if moduleimpl_id != "autre":
moduleimpl = ModuleImpl.query.filter_by(id=int(moduleimpl_id)).first()
if moduleimpl is None:
errors.append("param 'moduleimpl_id': invalide")
else:
moduleimpl_id = None
external_data = external_data if external_data is not None else {}
external_data["module"] = "Autre"
if errors: if errors:
err: str = ", ".join(errors) err: str = ", ".join(errors)
return (404, err) return (404, err)
@ -709,58 +714,10 @@ def assiduite_edit(assiduite_id: int):
errors: list[str] = [] errors: list[str] = []
data = request.get_json(force=True) data = request.get_json(force=True)
# Vérifications de data code, obj = _edit_singular(assiduite_unique, data)
# Cas 1 : Etat if code == 404:
if data.get("etat") is not None: return json_error(404, obj)
etat = scu.EtatAssiduite.get(data.get("etat"))
if etat is None:
errors.append("param 'etat': invalide")
else:
assiduite_unique.etat = etat
# Cas 2 : Moduleimpl_id
moduleimpl_id = data.get("moduleimpl_id", False)
moduleimpl: ModuleImpl = None
if moduleimpl_id is not False:
if moduleimpl_id is not None and moduleimpl_id != "":
moduleimpl = ModuleImpl.query.filter_by(id=int(moduleimpl_id)).first()
if moduleimpl is None:
errors.append("param 'moduleimpl_id': invalide")
else:
if not moduleimpl.est_inscrit(
Identite.query.filter_by(id=assiduite_unique.etudid).first()
):
errors.append("param 'moduleimpl_id': etud non inscrit")
else:
assiduite_unique.moduleimpl_id = moduleimpl_id
else:
assiduite_unique.moduleimpl_id = None
# Cas 3 : desc
desc = data.get("desc", False)
if desc is not False:
assiduite_unique.description = desc
# Cas 4 : est_just
est_just = data.get("est_just")
if est_just is not None:
if not isinstance(est_just, bool):
errors.append("param 'est_just' : booléen non reconnu")
else:
assiduite_unique.est_just = est_just
external_data = data.get("external_data")
if external_data is not None:
if not isinstance(external_data, dict):
errors.append("param 'external_data' : n'est pas un objet JSON")
else:
assiduite_unique.external_data = external_data
if errors:
err: str = ", ".join(errors)
return json_error(404, err)
log(f"assiduite_edit: {assiduite_unique.etudiant.id} {assiduite_unique}") log(f"assiduite_edit: {assiduite_unique.etudiant.id} {assiduite_unique}")
Scolog.logdb( Scolog.logdb(
@ -841,22 +798,41 @@ def _edit_singular(assiduite_unique, data):
else: else:
assiduite_unique.etat = etat assiduite_unique.etat = etat
external_data = data.get("external_data")
if external_data is not None:
if not isinstance(external_data, dict):
errors.append("param 'external_data' : n'est pas un objet JSON")
else:
assiduite_unique.external_data = external_data
# Cas 2 : Moduleimpl_id # Cas 2 : Moduleimpl_id
moduleimpl_id = data.get("moduleimpl_id", False) moduleimpl_id = data.get("moduleimpl_id", False)
moduleimpl: ModuleImpl = None moduleimpl: ModuleImpl = None
if moduleimpl_id is not False: if moduleimpl_id is not False:
if moduleimpl_id is not None: if moduleimpl_id is not None:
moduleimpl = ModuleImpl.query.filter_by(id=int(moduleimpl_id)).first() if moduleimpl_id == "autre":
if moduleimpl is None: assiduite_unique.moduleimpl_id = None
errors.append("param 'moduleimpl_id': invalide") external_data = (
external_data
if external_data is not None and isinstance(external_data, dict)
else assiduite_unique.external_data
)
external_data = external_data if external_data is not None else {}
external_data["module"] = "Autre"
assiduite_unique.external_data = external_data
else: else:
if not moduleimpl.est_inscrit( moduleimpl = ModuleImpl.query.filter_by(id=int(moduleimpl_id)).first()
Identite.query.filter_by(id=assiduite_unique.etudid).first() if moduleimpl is None:
): errors.append("param 'moduleimpl_id': invalide")
errors.append("param 'moduleimpl_id': etud non inscrit")
else: else:
assiduite_unique.moduleimpl_id = moduleimpl_id if not moduleimpl.est_inscrit(
Identite.query.filter_by(id=assiduite_unique.etudid).first()
):
errors.append("param 'moduleimpl_id': etud non inscrit")
else:
assiduite_unique.moduleimpl_id = moduleimpl_id
else: else:
assiduite_unique.moduleimpl_id = moduleimpl_id assiduite_unique.moduleimpl_id = moduleimpl_id