117 lines
4.1 KiB
Python
117 lines
4.1 KiB
Python
|
##############################################################################
|
||
|
# ScoDoc
|
||
|
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
||
|
# See LICENSE
|
||
|
##############################################################################
|
||
|
|
||
|
"""Génération bulletin BUT au format PDF standard
|
||
|
"""
|
||
|
|
||
|
import datetime
|
||
|
from app.scodoc.sco_pdf import blue, cm, mm
|
||
|
|
||
|
from flask import url_for, g
|
||
|
from app.models.formsemestre import FormSemestre
|
||
|
|
||
|
from app.scodoc import gen_tables
|
||
|
from app.scodoc import sco_utils as scu
|
||
|
from app.scodoc import sco_bulletins_json
|
||
|
from app.scodoc import sco_preferences
|
||
|
from app.scodoc.sco_codes_parcours import UE_SPORT
|
||
|
from app.scodoc.sco_utils import fmt_note
|
||
|
from app.comp.res_but import ResultatsSemestreBUT
|
||
|
|
||
|
from app.scodoc.sco_bulletins_standard import BulletinGeneratorStandard
|
||
|
|
||
|
|
||
|
class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
|
||
|
"""Génération du bulletin de BUT au format PDF.
|
||
|
|
||
|
self.infos est le dict issu de BulletinBUT.bulletin_etud_complet()
|
||
|
"""
|
||
|
|
||
|
list_in_menu = False # spécialisation du BulletinGeneratorStandard, ne pas présenter à l'utilisateur
|
||
|
|
||
|
def bul_table(self, format="html"):
|
||
|
"""Génère la table centrale du bulletin de notes
|
||
|
Renvoie:
|
||
|
- en HTML: une chaine
|
||
|
- en PDF: une liste d'objets PLATYPUS (eg instance de Table).
|
||
|
"""
|
||
|
formsemestre_id = self.infos["formsemestre_id"]
|
||
|
(
|
||
|
synth_col_keys,
|
||
|
synth_P,
|
||
|
synth_pdf_style,
|
||
|
synth_col_widths,
|
||
|
) = self.but_table_synthese()
|
||
|
#
|
||
|
table_synthese = gen_tables.GenTable(
|
||
|
rows=synth_P,
|
||
|
columns_ids=synth_col_keys,
|
||
|
pdf_table_style=synth_pdf_style,
|
||
|
pdf_col_widths=[synth_col_widths[k] for k in synth_col_keys],
|
||
|
preferences=self.preferences,
|
||
|
html_class="notes_bulletin",
|
||
|
html_class_ignore_default=True,
|
||
|
html_with_td_classes=True,
|
||
|
)
|
||
|
# Ici on ajoutera table des ressources, tables des UE
|
||
|
# TODO
|
||
|
|
||
|
# XXX à modifier pour générer plusieurs tables:
|
||
|
return table_synthese.gen(format=format)
|
||
|
|
||
|
def but_table_synthese(self):
|
||
|
"""La table de synthèse; pour chaque UE, liste des ressources et SAÉs avec leurs notes
|
||
|
et leurs coefs.
|
||
|
Renvoie: colkeys, P, pdf_style, colWidths
|
||
|
- colkeys: nom des colonnes de la table (clés)
|
||
|
- P : table (liste de dicts de chaines de caracteres)
|
||
|
- pdf_style : commandes table Platypus
|
||
|
- largeurs de colonnes pour PDF
|
||
|
"""
|
||
|
col_widths = {
|
||
|
"titre": None,
|
||
|
"moyenne": 2 * cm,
|
||
|
"coef": 2 * cm,
|
||
|
}
|
||
|
P = [] # elems pour générer table avec gen_table (liste de dicts)
|
||
|
col_keys = ["titre", "moyenne"] # noms des colonnes à afficher
|
||
|
for ue_acronym, ue in self.infos["ues"].items():
|
||
|
# 1er ligne titre UE
|
||
|
moy_ue = ue.get("moyenne")
|
||
|
t = {
|
||
|
"titre": f"{ue_acronym} - {ue['titre']}",
|
||
|
"moyenne": moy_ue.get("value", "-") if moy_ue is not None else "-",
|
||
|
"_css_row_class": "note_bold",
|
||
|
"_pdf_row_markup": ["b"],
|
||
|
"_pdf_style": [],
|
||
|
}
|
||
|
P.append(t)
|
||
|
# 2eme ligne titre UE (bonus/malus/ects)
|
||
|
t = {
|
||
|
"titre": "",
|
||
|
"moyenne": f"""Bonus: {ue['bonus']} - Malus: {
|
||
|
ue["malus"]} - ECTS: {ue["ECTS"]["acquis"]} / {ue["ECTS"]["total"]}""",
|
||
|
"_css_row_class": "note_bold",
|
||
|
"_pdf_row_markup": ["b"],
|
||
|
"_pdf_style": [
|
||
|
(
|
||
|
"LINEBELOW",
|
||
|
(0, 0),
|
||
|
(-1, 0),
|
||
|
self.PDF_LINEWIDTH,
|
||
|
self.PDF_LINECOLOR,
|
||
|
)
|
||
|
],
|
||
|
}
|
||
|
P.append(t)
|
||
|
|
||
|
# Global pdf style commands:
|
||
|
pdf_style = [
|
||
|
("VALIGN", (0, 0), (-1, -1), "TOP"),
|
||
|
("BOX", (0, 0), (-1, -1), 0.4, blue), # ajoute cadre extérieur bleu:
|
||
|
]
|
||
|
return col_keys, P, pdf_style, col_widths
|