From d81860208456fe77863033d6e183daec2bcd684f Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 27 Jul 2022 17:42:58 +0200 Subject: [PATCH] Fix: API partitions/order, groups/order, group/set_etudiant --- app/api/etudiants.py | 4 +--- app/api/partitions.py | 13 ++++++------- app/models/formsemestre.py | 5 +++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/api/etudiants.py b/app/api/etudiants.py index 0da5f60f4..80b7eff08 100644 --- a/app/api/etudiants.py +++ b/app/api/etudiants.py @@ -286,9 +286,7 @@ def etudiant_formsemestres(etudid: int = None, nip: int = None, ine: int = None) formsemestres = query.order_by(FormSemestre.date_debut) - return jsonify( - [formsemestre.to_dict(convert_objects=True) for formsemestre in formsemestres] - ) + return jsonify([formsemestre.to_dict_api() for formsemestre in formsemestres]) @bp.route( diff --git a/app/api/partitions.py b/app/api/partitions.py index 6b366ec54..1f7280ca8 100644 --- a/app/api/partitions.py +++ b/app/api/partitions.py @@ -165,9 +165,7 @@ def set_etud_group(etudid: int, group_id: int): query = GroupDescr.query.filter_by(id=group_id) if g.scodoc_dept: query = ( - query.join(Partition) - .join(FormSemestre) - .filter_by(dept_id=group.scodoc_dept_id) + query.join(Partition).join(FormSemestre).filter_by(dept_id=g.scodoc_dept_id) ) group = query.first_or_404() if etud.id not in {e.id for e in group.partition.formsemestre.etuds}: @@ -178,11 +176,11 @@ def set_etud_group(etudid: int, group_id: int): .filter_by(etudid=etudid) ) ok = False - for group in groups: - if group.id == group_id: + for other_group in groups: + if other_group.id == group_id: ok = True else: - group.etuds.remove(etud) + other_group.etuds.remove(etud) if not ok: group.etuds.append(etud) log(f"set_etud_group({etud}, {group})") @@ -417,7 +415,7 @@ def formsemestre_order_partitions(formsemestre_id: int): db.session.commit() app.set_sco_dept(formsemestre.departement.acronym) sco_cache.invalidate_formsemestre(formsemestre_id) - return jsonify(formsemestre.to_dict(convert_objects=True)) + return jsonify(formsemestre.to_dict_api()) @bp.route("/partition//groups/order", methods=["POST"]) @@ -448,6 +446,7 @@ def partition_order_groups(partition_id: int): db.session.commit() app.set_sco_dept(partition.formsemestre.departement.acronym) sco_cache.invalidate_formsemestre(partition.formsemestre_id) + log(f"partition_order_groups: {partition} : {group_ids}") return jsonify(partition.to_dict(with_groups=True)) diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index b3688dd90..a5514200e 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -170,6 +170,9 @@ class FormSemestre(db.Model): d["titre_formation"] = self.titre_formation() if convert_objects: d["parcours"] = [p.to_dict() for p in self.parcours] + d["departement"] = self.departement.to_dict() + d["formation"] = self.formation.to_dict() + d["etape_apo"] = self.etapes_apo_str() return d def to_dict_api(self): @@ -189,8 +192,10 @@ class FormSemestre(db.Model): d["date_fin_iso"] = self.date_fin.isoformat() else: d["date_fin"] = d["date_fin_iso"] = "" + d["departement"] = self.departement.to_dict() d["etape_apo"] = self.etapes_apo_str() d["formsemestre_id"] = self.id + d["formation"] = self.formation.to_dict() d["parcours"] = [p.to_dict() for p in self.parcours] d["responsables"] = [u.id for u in self.responsables] d["titre_court"] = self.formation.acronyme