118 lines
3.7 KiB
Python
118 lines
3.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
|
||
|
from app.tables import table_builder as tb
|
||
|
|
||
|
|
||
|
class TableEtud(tb.Table):
|
||
|
"""Table listant des étudiants
|
||
|
Peut-être sous-classée pour ajouter des colonnes.
|
||
|
L'id de la ligne est etuid, et le row stocke etud.
|
||
|
"""
|
||
|
|
||
|
def __init__(
|
||
|
self,
|
||
|
etuds: list[Identite] = None,
|
||
|
classes: list[str] = None,
|
||
|
row_class=None,
|
||
|
with_foot_titles=False,
|
||
|
**kwargs,
|
||
|
):
|
||
|
self.rows: list["RowEtud"] = [] # juste pour que VSCode nous aide sur .rows
|
||
|
classes = classes or ["gt_table", "gt_left"]
|
||
|
super().__init__(
|
||
|
row_class=row_class or RowEtud,
|
||
|
classes=classes,
|
||
|
with_foot_titles=with_foot_titles,
|
||
|
**kwargs,
|
||
|
)
|
||
|
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 RowEtud(tb.Row):
|
||
|
"Ligne de la table d'étudiants"
|
||
|
# pour le moment très simple, extensible (codes, liens bulletins, ...)
|
||
|
def __init__(self, table: TableEtud, etud: Identite, *args, **kwargs):
|
||
|
super().__init__(table, etud.id, *args, **kwargs)
|
||
|
self.etud = etud
|
||
|
|
||
|
def add_etud_cols(self):
|
||
|
"""Ajoute colonnes étudiant: codes, noms"""
|
||
|
etud = self.etud
|
||
|
self.table.group_titles.update(
|
||
|
{
|
||
|
"etud_codes": "Codes",
|
||
|
"identite_detail": "",
|
||
|
"identite_court": "",
|
||
|
}
|
||
|
)
|
||
|
# --- Codes (seront cachés, mais exportés en excel)
|
||
|
# self.add_cell("etudid", "etudid", etud.id, "etud_codes")
|
||
|
# self.add_cell(
|
||
|
# "code_nip",
|
||
|
# "code_nip",
|
||
|
# etud.code_nip or "",
|
||
|
# "etud_codes",
|
||
|
# )
|
||
|
|
||
|
# --- Identité étudiant
|
||
|
# url_bulletin = url_for(
|
||
|
# "notes.formsemestre_bulletinetud",
|
||
|
# scodoc_dept=g.scodoc_dept,
|
||
|
# formsemestre_id=res.formsemestre.id,
|
||
|
# etudid=etud.id,
|
||
|
# )
|
||
|
url_bulletin = None # pour extension future
|
||
|
self.add_cell("civilite_str", "Civ.", etud.civilite_str, "identite_detail")
|
||
|
self.add_cell(
|
||
|
"nom_disp",
|
||
|
"Nom",
|
||
|
etud.nom_disp(),
|
||
|
"identite_detail",
|
||
|
data={"order": etud.sort_key},
|
||
|
target=url_bulletin,
|
||
|
target_attrs={"class": "etudinfo discretelink", "id": str(etud.id)},
|
||
|
)
|
||
|
self.add_cell("prenom", "Prénom", etud.prenom, "identite_detail")
|
||
|
# self.add_cell(
|
||
|
# "nom_short",
|
||
|
# "Nom",
|
||
|
# etud.nom_short,
|
||
|
# "identite_court",
|
||
|
# data={
|
||
|
# "order": etud.sort_key,
|
||
|
# "etudid": etud.id,
|
||
|
# "nomprenom": etud.nomprenom,
|
||
|
# },
|
||
|
# target=url_bulletin,
|
||
|
# target_attrs={"class": "etudinfo", "id": str(etud.id)},
|
||
|
# )
|
||
|
|
||
|
|
||
|
def etuds_sorted_from_ids(etudids) -> list[Identite]:
|
||
|
"Liste triée d'etuds à partir d'une collections d'etudids"
|
||
|
etuds = [Identite.query.get_or_404(etudid) for etudid in etudids]
|
||
|
return sorted(etuds, key=lambda etud: etud.sort_key)
|
||
|
|
||
|
|
||
|
def html_table_etuds(etudids) -> str:
|
||
|
"""Table HTML simple des étudiants indiqués"""
|
||
|
etuds = etuds_sorted_from_ids(etudids)
|
||
|
table = TableEtud(etuds)
|
||
|
return table.html()
|