forked from ScoDoc/ScoDoc
Assiduités : fix Bug module autre #710
This commit is contained in:
parent
69eda90eea
commit
f9970a16ad
@ -587,16 +587,6 @@ def _create_singular(
|
||||
if fin is None:
|
||||
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
|
||||
|
||||
desc: str = data.get("desc", None)
|
||||
@ -606,6 +596,21 @@ def _create_singular(
|
||||
if not isinstance(external_data, dict):
|
||||
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:
|
||||
err: str = ", ".join(errors)
|
||||
return (404, err)
|
||||
@ -709,58 +714,10 @@ def assiduite_edit(assiduite_id: int):
|
||||
errors: list[str] = []
|
||||
data = request.get_json(force=True)
|
||||
|
||||
# Vérifications de data
|
||||
code, obj = _edit_singular(assiduite_unique, data)
|
||||
|
||||
# Cas 1 : Etat
|
||||
if data.get("etat") is not None:
|
||||
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)
|
||||
if code == 404:
|
||||
return json_error(404, obj)
|
||||
|
||||
log(f"assiduite_edit: {assiduite_unique.etudiant.id} {assiduite_unique}")
|
||||
Scolog.logdb(
|
||||
@ -841,22 +798,41 @@ def _edit_singular(assiduite_unique, data):
|
||||
else:
|
||||
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
|
||||
moduleimpl_id = data.get("moduleimpl_id", False)
|
||||
moduleimpl: ModuleImpl = None
|
||||
|
||||
if moduleimpl_id is not False:
|
||||
if moduleimpl_id is not None:
|
||||
moduleimpl = ModuleImpl.query.filter_by(id=int(moduleimpl_id)).first()
|
||||
if moduleimpl is None:
|
||||
errors.append("param 'moduleimpl_id': invalide")
|
||||
if moduleimpl_id == "autre":
|
||||
assiduite_unique.moduleimpl_id = None
|
||||
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:
|
||||
if not moduleimpl.est_inscrit(
|
||||
Identite.query.filter_by(id=assiduite_unique.etudid).first()
|
||||
):
|
||||
errors.append("param 'moduleimpl_id': etud non inscrit")
|
||||
moduleimpl = ModuleImpl.query.filter_by(id=int(moduleimpl_id)).first()
|
||||
if moduleimpl is None:
|
||||
errors.append("param 'moduleimpl_id': invalide")
|
||||
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:
|
||||
assiduite_unique.moduleimpl_id = moduleimpl_id
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user