forked from ScoDoc/ScoDoc
Améliore partition_remove_etud en cas d'accès concurrents
This commit is contained in:
parent
c933f010d4
commit
8ee95cc2e5
@ -12,6 +12,7 @@ from operator import attrgetter
|
|||||||
from flask import g, request
|
from flask import g, request
|
||||||
from flask_json import as_json
|
from flask_json import as_json
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
import sqlalchemy as sa
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
import app
|
import app
|
||||||
@ -248,19 +249,25 @@ def partition_remove_etud(partition_id: int, etudid: int):
|
|||||||
partition = query.first_or_404()
|
partition = query.first_or_404()
|
||||||
if not partition.formsemestre.etat:
|
if not partition.formsemestre.etat:
|
||||||
return json_error(403, "formsemestre verrouillé")
|
return json_error(403, "formsemestre verrouillé")
|
||||||
groups = (
|
|
||||||
GroupDescr.query.filter_by(partition_id=partition_id)
|
db.session.execute(
|
||||||
.join(group_membership)
|
sa.text(
|
||||||
.filter_by(etudid=etudid)
|
"""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()
|
db.session.commit()
|
||||||
# Update parcours
|
# Update parcours
|
||||||
partition.formsemestre.update_inscriptions_parcours_from_groups()
|
partition.formsemestre.update_inscriptions_parcours_from_groups()
|
||||||
|
Loading…
Reference in New Issue
Block a user