1
0
forked from ScoDoc/ScoDoc

Fix comptes membres groupes

This commit is contained in:
Emmanuel Viennet 2023-09-20 19:09:02 +02:00
parent 366bd0bea7
commit 7a9c399812
2 changed files with 18 additions and 2 deletions

View File

@ -12,6 +12,7 @@ from sqlalchemy.exc import IntegrityError
from app import db, log from app import db, log
from app.models import Scolog, GROUPNAME_STR_LEN, SHORT_STR_LEN 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_cache
from app.scodoc import sco_utils as scu from app.scodoc import sco_utils as scu
from app.scodoc.sco_exceptions import AccessDenied, ScoValueError from app.scodoc.sco_exceptions import AccessDenied, ScoValueError
@ -50,7 +51,7 @@ class Partition(db.Model):
backref=db.backref("partition", lazy=True), backref=db.backref("partition", lazy=True),
lazy="dynamic", lazy="dynamic",
cascade="all, delete-orphan", cascade="all, delete-orphan",
order_by="GroupDescr.numero", order_by="GroupDescr.numero, GroupDescr.group_name",
) )
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -240,6 +241,21 @@ class GroupDescr(db.Model):
d["partition"] = self.partition.to_dict(with_groups=False) d["partition"] = self.partition.to_dict(with_groups=False)
return d 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 -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 @classmethod
def check_name( def check_name(
cls, partition: "Partition", group_name: str, existing=False, default=False cls, partition: "Partition", group_name: str, existing=False, default=False

View File

@ -828,7 +828,7 @@ def _make_listes_sem(formsemestre: FormSemestre) -> str:
# Genere liste pour chaque partition (categorie de groupes) # Genere liste pour chaque partition (categorie de groupes)
for partition in formsemestre.get_partitions_list(): for partition in formsemestre.get_partitions_list():
groups = partition.groups.all() 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 partition_is_empty = sum(effectifs.values()) == 0
H.append( H.append(
f""" f"""