From 073c3c7c4423989794a6d72f3c6613b1cc844e38 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 22 Jan 2023 18:15:56 -0300 Subject: [PATCH] Fix #573 (API set group) --- app/api/partitions.py | 20 +++++--------------- app/models/groups.py | 1 + 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/app/api/partitions.py b/app/api/partitions.py index 699f18e71..0b297871c 100644 --- a/app/api/partitions.py +++ b/app/api/partitions.py @@ -19,6 +19,7 @@ from app.models import FormSemestre, FormSemestreInscription, Identite from app.models import GroupDescr, Partition from app.models.groups import group_membership from app.scodoc import sco_cache +from app.scodoc import sco_groups from app.scodoc.sco_permissions import Permission from app.scodoc import sco_utils as scu @@ -172,22 +173,11 @@ def set_etud_group(etudid: int, group_id: int): group = query.first_or_404() if etud.id not in {e.id for e in group.partition.formsemestre.etuds}: return json_error(404, "etud non inscrit au formsemestre du groupe") - groups = ( - GroupDescr.query.filter_by(partition_id=group.partition.id) - .join(group_membership) - .filter_by(etudid=etudid) + + sco_groups.change_etud_group_in_partition( + etudid, group_id, group.partition.to_dict() ) - ok = False - for other_group in groups: - if other_group.id == group_id: - ok = True - else: - other_group.etuds.remove(etud) - if not ok: - group.etuds.append(etud) - log(f"set_etud_group({etud}, {group})") - db.session.commit() - sco_cache.invalidate_formsemestre(group.partition.formsemestre_id) + return jsonify({"group_id": group_id, "etudid": etudid}) diff --git a/app/models/groups.py b/app/models/groups.py index 4fd25a940..6fafa234b 100644 --- a/app/models/groups.py +++ b/app/models/groups.py @@ -87,6 +87,7 @@ class Partition(db.Model): def to_dict(self, with_groups=False) -> dict: """as a dict, with or without groups""" d = dict(self.__dict__) + d["partition_id"] = self.id d.pop("_sa_instance_state", None) d.pop("formsemestre", None)