Fix: API partitions/order, groups/order, group/set_etudiant

This commit is contained in:
Emmanuel Viennet 2022-07-27 17:42:58 +02:00
parent cf4d948733
commit d818602084
3 changed files with 12 additions and 10 deletions

View File

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

View File

@ -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/<int:partition_id>/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))

View File

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