forked from ScoDoc/ScoDoc
114 lines
4.0 KiB
Python
114 lines
4.0 KiB
Python
##############################################################################
|
|
# ScoDoc
|
|
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
|
# See LICENSE
|
|
##############################################################################
|
|
|
|
"""Jury BUT: table synthèse résultats semestre / PV
|
|
"""
|
|
from flask import g, request, url_for
|
|
|
|
from openpyxl.styles import Font, Border, Side, Alignment, PatternFill
|
|
|
|
from app import log
|
|
from app.but import jury_but
|
|
from app.models.etudiants import Identite
|
|
from app.models.formsemestre import FormSemestre
|
|
from app.scodoc.gen_tables import GenTable
|
|
from app.scodoc import sco_excel
|
|
from app.scodoc.sco_exceptions import ScoValueError
|
|
from app.scodoc import sco_preferences
|
|
from app.scodoc import sco_utils as scu
|
|
|
|
|
|
def _descr_cursus_but(etud: Identite) -> str:
|
|
"description de la liste des semestres BUT suivis"
|
|
# prend simplement tous les semestre de type APC, ce qui sera faux si
|
|
# l'étudiant change de spécialité au sein du même département
|
|
# (ce qui ne peut normalement pas se produire)
|
|
indices = sorted(
|
|
[
|
|
ins.formsemestre.semestre_id
|
|
if ins.formsemestre.semestre_id is not None
|
|
else -1
|
|
for ins in etud.formsemestre_inscriptions
|
|
if ins.formsemestre.formation.is_apc()
|
|
]
|
|
)
|
|
return ", ".join(f"S{indice}" for indice in indices)
|
|
|
|
|
|
def pvjury_table_but(formsemestre_id: int, format="html") -> list[dict]:
|
|
"""Page récapitulant les décisions de jury BUT
|
|
formsemestre peut être pair ou impair
|
|
"""
|
|
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
|
assert formsemestre.formation.is_apc()
|
|
title = "Jury BUT annuel"
|
|
|
|
if format == "html":
|
|
line_sep = "<br/>"
|
|
else:
|
|
line_sep = "\n"
|
|
# remplace pour le BUT la fonction sco_pvjury.pvjury_table
|
|
annee_but = (formsemestre.semestre_id + 1) // 2
|
|
titles = {
|
|
"nom": "Nom",
|
|
"cursus": "Cursus",
|
|
"niveaux": "Niveaux de compétences validés",
|
|
"decision_but": f"Décision BUT{annee_but}",
|
|
"diplome": "Résultat au diplôme",
|
|
"devenir": "Devenir",
|
|
"observations": "Observations",
|
|
}
|
|
rows = []
|
|
for etudid in formsemestre.etuds_inscriptions:
|
|
etud: Identite = Identite.query.get(etudid)
|
|
try:
|
|
deca = jury_but.DecisionsProposeesAnnee(etud, formsemestre)
|
|
if deca.annee_but != annee_but: # wtf ?
|
|
log(
|
|
f"pvjury_table_but: inconsistent annee_but {deca.annee_but} != {annee_but}"
|
|
)
|
|
continue
|
|
except ScoValueError:
|
|
deca = None
|
|
row = {
|
|
"nom": etud.etat_civil_pv(line_sep=line_sep),
|
|
"_nom_order": etud.sort_key,
|
|
"cursus": _descr_cursus_but(etud),
|
|
"niveaux": deca.descr_niveaux_validation(line_sep=line_sep)
|
|
if deca
|
|
else "-",
|
|
"decision_but": deca.code_valide if deca else "",
|
|
"devenir": ", ".join([f"S{i}" for i in deca.get_autorisations_passage()]),
|
|
}
|
|
|
|
rows.append(row)
|
|
|
|
rows.sort(key=lambda x: x["_nom_order"])
|
|
|
|
# Style excel... passages à la ligne sur \n
|
|
xls_style_base = sco_excel.excel_make_style()
|
|
xls_style_base["alignment"] = Alignment(wrapText=True, vertical="top")
|
|
|
|
tab = GenTable(
|
|
columns_ids=titles.keys(),
|
|
rows=rows,
|
|
titles=titles,
|
|
origin=f"Généré par {scu.sco_version.SCONAME} le {scu.timedate_human_repr()}",
|
|
caption=title,
|
|
html_caption=title,
|
|
html_class="pvjury_table_but table_leftalign",
|
|
# html_class_ignore_default=True,
|
|
html_with_td_classes=True,
|
|
xls_style_base=xls_style_base,
|
|
base_url=f"{request.base_url}?formsemestre_id={formsemestre_id}",
|
|
page_title=title,
|
|
html_title=f"<h2>{title}</h2>",
|
|
pdf_title=title,
|
|
preferences=sco_preferences.SemPreferences(),
|
|
table_id="formation_table_recap",
|
|
)
|
|
return tab.make_page(format=format, javascripts=[])
|