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) formsemestres = query.order_by(FormSemestre.date_debut)
return jsonify( return jsonify([formsemestre.to_dict_api() for formsemestre in formsemestres])
[formsemestre.to_dict(convert_objects=True) for formsemestre in formsemestres]
)
@bp.route( @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) query = GroupDescr.query.filter_by(id=group_id)
if g.scodoc_dept: if g.scodoc_dept:
query = ( query = (
query.join(Partition) query.join(Partition).join(FormSemestre).filter_by(dept_id=g.scodoc_dept_id)
.join(FormSemestre)
.filter_by(dept_id=group.scodoc_dept_id)
) )
group = query.first_or_404() group = query.first_or_404()
if etud.id not in {e.id for e in group.partition.formsemestre.etuds}: 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) .filter_by(etudid=etudid)
) )
ok = False ok = False
for group in groups: for other_group in groups:
if group.id == group_id: if other_group.id == group_id:
ok = True ok = True
else: else:
group.etuds.remove(etud) other_group.etuds.remove(etud)
if not ok: if not ok:
group.etuds.append(etud) group.etuds.append(etud)
log(f"set_etud_group({etud}, {group})") log(f"set_etud_group({etud}, {group})")
@ -417,7 +415,7 @@ def formsemestre_order_partitions(formsemestre_id: int):
db.session.commit() db.session.commit()
app.set_sco_dept(formsemestre.departement.acronym) app.set_sco_dept(formsemestre.departement.acronym)
sco_cache.invalidate_formsemestre(formsemestre_id) 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"]) @bp.route("/partition/<int:partition_id>/groups/order", methods=["POST"])
@ -448,6 +446,7 @@ def partition_order_groups(partition_id: int):
db.session.commit() db.session.commit()
app.set_sco_dept(partition.formsemestre.departement.acronym) app.set_sco_dept(partition.formsemestre.departement.acronym)
sco_cache.invalidate_formsemestre(partition.formsemestre_id) sco_cache.invalidate_formsemestre(partition.formsemestre_id)
log(f"partition_order_groups: {partition} : {group_ids}")
return jsonify(partition.to_dict(with_groups=True)) return jsonify(partition.to_dict(with_groups=True))

View File

@ -170,6 +170,9 @@ class FormSemestre(db.Model):
d["titre_formation"] = self.titre_formation() d["titre_formation"] = self.titre_formation()
if convert_objects: if convert_objects:
d["parcours"] = [p.to_dict() for p in self.parcours] 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 return d
def to_dict_api(self): def to_dict_api(self):
@ -189,8 +192,10 @@ class FormSemestre(db.Model):
d["date_fin_iso"] = self.date_fin.isoformat() d["date_fin_iso"] = self.date_fin.isoformat()
else: else:
d["date_fin"] = d["date_fin_iso"] = "" d["date_fin"] = d["date_fin_iso"] = ""
d["departement"] = self.departement.to_dict()
d["etape_apo"] = self.etapes_apo_str() d["etape_apo"] = self.etapes_apo_str()
d["formsemestre_id"] = self.id d["formsemestre_id"] = self.id
d["formation"] = self.formation.to_dict()
d["parcours"] = [p.to_dict() for p in self.parcours] d["parcours"] = [p.to_dict() for p in self.parcours]
d["responsables"] = [u.id for u in self.responsables] d["responsables"] = [u.id for u in self.responsables]
d["titre_court"] = self.formation.acronyme d["titre_court"] = self.formation.acronyme