From 8ee95cc2e5bacea6e512df12fdafb825f7b02612 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 13 Jul 2023 20:01:42 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liore=20partition=5Fremove=5Fetud=20en?= =?UTF-8?q?=20cas=20d'acc=C3=A8s=20concurrents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/partitions.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/api/partitions.py b/app/api/partitions.py index 4d752b65..f854af38 100644 --- a/app/api/partitions.py +++ b/app/api/partitions.py @@ -12,6 +12,7 @@ from operator import attrgetter from flask import g, request from flask_json import as_json from flask_login import login_required +import sqlalchemy as sa from sqlalchemy.exc import IntegrityError import app @@ -248,19 +249,25 @@ def partition_remove_etud(partition_id: int, etudid: int): partition = query.first_or_404() if not partition.formsemestre.etat: return json_error(403, "formsemestre verrouillé") - groups = ( - GroupDescr.query.filter_by(partition_id=partition_id) - .join(group_membership) - .filter_by(etudid=etudid) + + db.session.execute( + sa.text( + """DELETE FROM group_membership + WHERE etudid=:etudid + and group_id IN ( + SELECT id FROM group_descr WHERE partition_id = :partition_id + ); + """ + ), + {"etudid": etudid, "partition_id": partition_id}, + ) + + Scolog.logdb( + method="partition_remove_etud", + etudid=etud.id, + msg=f"Retrait de la partition {partition.partition_name}", + commit=False, ) - for group in groups: - group.etuds.remove(etud) - Scolog.logdb( - method="partition_remove_etud", - etudid=etud.id, - msg=f"Retrait du groupe {group.group_name} de {group.partition.partition_name}", - commit=True, - ) db.session.commit() # Update parcours partition.formsemestre.update_inscriptions_parcours_from_groups()