From deff37b9b72f46c36f1e94d4b970cfe332d3e80d Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 31 Jul 2023 18:46:41 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20#672:=20mise=20=C3=A0=20jour=20parcours?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/partitions.py | 6 +- app/models/formsemestre.py | 95 +++++++++++++++------ app/scodoc/sco_formsemestre_inscriptions.py | 2 +- app/scodoc/sco_groups.py | 2 +- 4 files changed, 73 insertions(+), 32 deletions(-) diff --git a/app/api/partitions.py b/app/api/partitions.py index 25a6d0454..5d7f56421 100644 --- a/app/api/partitions.py +++ b/app/api/partitions.py @@ -230,7 +230,9 @@ def group_remove_etud(group_id: int, etudid: int): commit=True, ) # Update parcours - group.partition.formsemestre.update_inscriptions_parcours_from_groups() + group.partition.formsemestre.update_inscriptions_parcours_from_groups( + etudid=etudid + ) sco_cache.invalidate_formsemestre(group.partition.formsemestre_id) return {"group_id": group_id, "etudid": etudid} @@ -277,7 +279,7 @@ def partition_remove_etud(partition_id: int, etudid: int): ) db.session.commit() # Update parcours - partition.formsemestre.update_inscriptions_parcours_from_groups() + partition.formsemestre.update_inscriptions_parcours_from_groups(etudid=etudid) app.set_sco_dept(partition.formsemestre.departement.acronym) sco_cache.invalidate_formsemestre(partition.formsemestre_id) return {"partition_id": partition_id, "etudid": etudid} diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index be395fea5..e4690a06a 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -818,11 +818,15 @@ class FormSemestre(db.Model): db.session.commit() - def update_inscriptions_parcours_from_groups(self) -> None: + def update_inscriptions_parcours_from_groups(self, etudid: int = None) -> None: """Met à jour les inscriptions dans les parcours du semestres en fonction des groupes de parcours. + Les groupes de parcours sont ceux de la partition scu.PARTITION_PARCOURS et leur nom est le code du parcours (eg "Cyber"). + + Si etudid est sépcifié, n'affecte que cet étudiant, + sinon traite tous les inscrits du semestre. """ if self.formation.referentiel_competence_id is None: return # safety net @@ -833,17 +837,32 @@ class FormSemestre(db.Model): return # Efface les inscriptions aux parcours: - db.session.execute( - text( - """UPDATE notes_formsemestre_inscription - SET parcour_id=NULL - WHERE formsemestre_id=:formsemestre_id - """ - ), - { - "formsemestre_id": self.id, - }, - ) + if etudid: + db.session.execute( + text( + """UPDATE notes_formsemestre_inscription + SET parcour_id=NULL + WHERE formsemestre_id=:formsemestre_id + AND etudid=:etudid + """ + ), + { + "formsemestre_id": self.id, + "etudid": etudid, + }, + ) + else: + db.session.execute( + text( + """UPDATE notes_formsemestre_inscription + SET parcour_id=NULL + WHERE formsemestre_id=:formsemestre_id + """ + ), + { + "formsemestre_id": self.id, + }, + ) # Inscrit les étudiants des groupes de parcours: for group in partition.groups: query = ( @@ -861,22 +880,42 @@ class FormSemestre(db.Model): ) continue parcour = query.first() - db.session.execute( - text( - """UPDATE notes_formsemestre_inscription ins - SET parcour_id=:parcour_id - FROM group_membership gm - WHERE formsemestre_id=:formsemestre_id - AND gm.etudid = ins.etudid - AND gm.group_id = :group_id - """ - ), - { - "formsemestre_id": self.id, - "parcour_id": parcour.id, - "group_id": group.id, - }, - ) + if etudid: + db.session.execute( + text( + """UPDATE notes_formsemestre_inscription ins + SET parcour_id=:parcour_id + FROM group_membership gm + WHERE formsemestre_id=:formsemestre_id + AND ins.etudid = :etudid + AND gm.etudid = :etudid + AND gm.group_id = :group_id + """ + ), + { + "etudid": etudid, + "formsemestre_id": self.id, + "parcour_id": parcour.id, + "group_id": group.id, + }, + ) + else: + db.session.execute( + text( + """UPDATE notes_formsemestre_inscription ins + SET parcour_id=:parcour_id + FROM group_membership gm + WHERE formsemestre_id=:formsemestre_id + AND gm.etudid = ins.etudid + AND gm.group_id = :group_id + """ + ), + { + "formsemestre_id": self.id, + "parcour_id": parcour.id, + "group_id": group.id, + }, + ) db.session.commit() def etud_validations_description_html(self, etudid: int) -> str: diff --git a/app/scodoc/sco_formsemestre_inscriptions.py b/app/scodoc/sco_formsemestre_inscriptions.py index 82744b8fb..24943558e 100644 --- a/app/scodoc/sco_formsemestre_inscriptions.py +++ b/app/scodoc/sco_formsemestre_inscriptions.py @@ -314,7 +314,7 @@ def do_formsemestre_inscription_with_modules( formsemestre_id=formsemestre_id, ) # Mise à jour des inscriptions aux parcours: - formsemestre.update_inscriptions_parcours_from_groups() + formsemestre.update_inscriptions_parcours_from_groups(etudid=etudid) def formsemestre_inscription_with_modules_etud( diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index c5f68fe06..ecdf9b9d8 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -684,7 +684,7 @@ def change_etud_group_in_partition(etudid: int, group: GroupDescr) -> bool: # - Update parcours if group.partition.partition_name == scu.PARTITION_PARCOURS: - formsemestre.update_inscriptions_parcours_from_groups() + formsemestre.update_inscriptions_parcours_from_groups(etudid=etudid) # - invalidate cache sco_cache.invalidate_formsemestre(