From 7a9c399812976d26e454e2c952e46a19ebdb3541 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 20 Sep 2023 19:09:02 +0200 Subject: [PATCH] Fix comptes membres groupes --- app/models/groups.py | 18 +++++++++++++++++- app/scodoc/sco_formsemestre_status.py | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/models/groups.py b/app/models/groups.py index b8fb5f46dc..a4a5792f6f 100644 --- a/app/models/groups.py +++ b/app/models/groups.py @@ -12,6 +12,7 @@ from sqlalchemy.exc import IntegrityError from app import db, log from app.models import Scolog, GROUPNAME_STR_LEN, SHORT_STR_LEN +from app.models.etudiants import Identite from app.scodoc import sco_cache from app.scodoc import sco_utils as scu from app.scodoc.sco_exceptions import AccessDenied, ScoValueError @@ -50,7 +51,7 @@ class Partition(db.Model): backref=db.backref("partition", lazy=True), lazy="dynamic", cascade="all, delete-orphan", - order_by="GroupDescr.numero", + order_by="GroupDescr.numero, GroupDescr.group_name", ) def __init__(self, **kwargs): @@ -240,6 +241,21 @@ class GroupDescr(db.Model): d["partition"] = self.partition.to_dict(with_groups=False) return d + def get_nb_inscrits(self) -> int: + """Nombre inscrits à ce group et au formsemestre. + C'est nécessaire car lors d'une désinscription, on conserve l'appartenance + aux groupes pour facilier une éventuelle ré-inscription. + """ + from app.models.formsemestre import FormSemestreInscription + + return ( + Identite.query.join(group_membership) + .filter_by(group_id=self.id) + .join(FormSemestreInscription) + .filter_by(formsemestre_id=self.partition.formsemestre.id) + .count() + ) + @classmethod def check_name( cls, partition: "Partition", group_name: str, existing=False, default=False diff --git a/app/scodoc/sco_formsemestre_status.py b/app/scodoc/sco_formsemestre_status.py index 260ba77dd6..d35d9d94c2 100755 --- a/app/scodoc/sco_formsemestre_status.py +++ b/app/scodoc/sco_formsemestre_status.py @@ -828,7 +828,7 @@ def _make_listes_sem(formsemestre: FormSemestre) -> str: # Genere liste pour chaque partition (categorie de groupes) for partition in formsemestre.get_partitions_list(): groups = partition.groups.all() - effectifs = {g.id: g.etuds.count() for g in groups} + effectifs = {g.id: g.get_nb_inscrits() for g in groups} partition_is_empty = sum(effectifs.values()) == 0 H.append( f"""