forked from ScoDoc/ScoDoc
147 lines
4.7 KiB
Python
147 lines
4.7 KiB
Python
|
##############################################################################
|
||
|
# ScoDoc
|
||
|
# Copyright (c) 1999 - 2023 Emmanuel Viennet. All rights reserved.
|
||
|
# See LICENSE
|
||
|
##############################################################################
|
||
|
|
||
|
"""Liste simple d'étudiants
|
||
|
"""
|
||
|
|
||
|
from flask import g, url_for
|
||
|
from app.models import Identite, Assiduite, Justificatif
|
||
|
from app.tables import table_builder as tb
|
||
|
import app.scodoc.sco_assiduites as scass
|
||
|
from app.scodoc import sco_preferences
|
||
|
|
||
|
|
||
|
class TableAssi(tb.Table):
|
||
|
"""Table listant l'assiduité des étudiants
|
||
|
L'id de la ligne est etuid, et le row stocke etud.
|
||
|
"""
|
||
|
|
||
|
def __init__(
|
||
|
self,
|
||
|
etuds: list[Identite] = None,
|
||
|
dates: tuple[str, str] = None,
|
||
|
**kwargs,
|
||
|
):
|
||
|
self.rows: list["RowEtud"] = [] # juste pour que VSCode nous aide sur .rows
|
||
|
classes = ["gt_table", "gt_left"]
|
||
|
self.dates = [str(dates[0]) + "T00:00", str(dates[1]) + "T23:59"]
|
||
|
|
||
|
super().__init__(
|
||
|
row_class=RowAssi,
|
||
|
classes=classes,
|
||
|
**kwargs,
|
||
|
with_foot_titles=False,
|
||
|
)
|
||
|
self.add_etuds(etuds)
|
||
|
|
||
|
def add_etuds(self, etuds: list[Identite]):
|
||
|
"Ajoute des étudiants à la table"
|
||
|
for etud in etuds:
|
||
|
row = self.row_class(self, etud)
|
||
|
row.add_etud_cols()
|
||
|
self.add_row(row)
|
||
|
|
||
|
|
||
|
class RowAssi(tb.Row):
|
||
|
"Ligne de la table assiduité"
|
||
|
|
||
|
# pour le moment très simple, extensible (codes, liens bulletins, ...)
|
||
|
def __init__(self, table: TableAssi, etud: Identite, *args, **kwargs):
|
||
|
super().__init__(table, etud.id, *args, **kwargs)
|
||
|
self.etud = etud
|
||
|
self.dates = table.dates
|
||
|
|
||
|
def add_etud_cols(self):
|
||
|
"""Ajoute les colonnes"""
|
||
|
etud = self.etud
|
||
|
self.table.group_titles.update(
|
||
|
{
|
||
|
"etud_codes": "Codes",
|
||
|
"identite_detail": "",
|
||
|
"identite_court": "",
|
||
|
}
|
||
|
)
|
||
|
|
||
|
bilan_etud = f"{url_for('assiduites.bilan_etud', scodoc_dept=g.scodoc_dept)}?etudid={etud.id}"
|
||
|
self.add_cell(
|
||
|
"nom_disp",
|
||
|
"Nom",
|
||
|
etud.nom_disp(),
|
||
|
"identite_detail",
|
||
|
data={"order": etud.sort_key},
|
||
|
target=bilan_etud,
|
||
|
target_attrs={"class": "discretelink", "id": str(etud.id)},
|
||
|
)
|
||
|
self.add_cell(
|
||
|
"prenom",
|
||
|
"Prénom",
|
||
|
etud.prenom,
|
||
|
"identite_detail",
|
||
|
data={"order": etud.sort_key},
|
||
|
target=bilan_etud,
|
||
|
target_attrs={"class": "discretelink", "id": str(etud.id)},
|
||
|
)
|
||
|
stats = self._get_etud_stats(etud)
|
||
|
for key, value in stats.items():
|
||
|
self.add_cell(key, value[0], f"{value[1] - value[2]}", "assi_stats")
|
||
|
self.add_cell(
|
||
|
key + "_justi",
|
||
|
value[0] + " Justifiée(s)",
|
||
|
f"{value[2]}",
|
||
|
"assi_stats",
|
||
|
)
|
||
|
|
||
|
compte_justificatifs = scass.filter_by_date(
|
||
|
etud.justificatifs, Justificatif, self.dates[0], self.dates[1]
|
||
|
).count()
|
||
|
|
||
|
self.add_cell("justificatifs", "Justificatifs", f"{compte_justificatifs}")
|
||
|
|
||
|
def _get_etud_stats(self, etud: Identite) -> dict[str, list[str, float, float]]:
|
||
|
retour: dict[str, tuple[str, float, float]] = {
|
||
|
"present": ["Présence(s)", 0.0, 0.0],
|
||
|
"retard": ["Retard(s)", 0.0, 0.0],
|
||
|
"absent": ["Absence(s)", 0.0, 0.0],
|
||
|
}
|
||
|
|
||
|
assi_metric = {
|
||
|
"H.": "heure",
|
||
|
"J.": "journee",
|
||
|
"1/2 J.": "demi",
|
||
|
}.get(sco_preferences.get_preference("assi_metrique", dept_id=g.scodoc_dept_id))
|
||
|
|
||
|
for etat, valeur in retour.items():
|
||
|
compte_etat = scass.get_assiduites_stats(
|
||
|
assiduites=etud.assiduites,
|
||
|
metric=assi_metric,
|
||
|
filtered={
|
||
|
"date_debut": self.dates[0],
|
||
|
"date_fin": self.dates[1],
|
||
|
"etat": etat,
|
||
|
},
|
||
|
)
|
||
|
|
||
|
compte_etat_just = scass.get_assiduites_stats(
|
||
|
assiduites=etud.assiduites,
|
||
|
metric=assi_metric,
|
||
|
filtered={
|
||
|
"date_debut": self.dates[0],
|
||
|
"date_fin": self.dates[1],
|
||
|
"etat": etat,
|
||
|
"est_just": True,
|
||
|
},
|
||
|
)
|
||
|
|
||
|
valeur[1] = compte_etat[assi_metric]
|
||
|
valeur[2] = compte_etat_just[assi_metric]
|
||
|
return retour
|
||
|
|
||
|
|
||
|
def etuds_sorted_from_ids(etudids) -> list[Identite]:
|
||
|
"Liste triée d'etuds à partir d'une collections d'etudids"
|
||
|
etuds = [Identite.get_etud(etudid) for etudid in etudids]
|
||
|
return sorted(etuds, key=lambda etud: etud.sort_key)
|