diff --git a/app/models/groups.py b/app/models/groups.py index b8fb5f46d..a4a5792f6 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 260ba77dd..d35d9d94c 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"""