Bul. BUT PDF: affichage UE bonus avec détails

This commit is contained in:
Emmanuel Viennet 2022-03-16 18:51:22 +01:00
parent 9b08357893
commit 2770db1bee
2 changed files with 130 additions and 116 deletions

View File

@ -11,6 +11,7 @@ from reportlab.platypus import Paragraph, Spacer
from app.scodoc.sco_pdf import blue, cm, mm from app.scodoc.sco_pdf import blue, cm, mm
from app.scodoc import gen_tables from app.scodoc import gen_tables
from app.scodoc.sco_codes_parcours import UE_SPORT
from app.scodoc.sco_utils import fmt_note from app.scodoc.sco_utils import fmt_note
from app.scodoc.sco_bulletins_standard import BulletinGeneratorStandard from app.scodoc.sco_bulletins_standard import BulletinGeneratorStandard
@ -116,6 +117,16 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
] ]
col_keys = ["titre", "coef", "moyenne"] # noms des colonnes à afficher col_keys = ["titre", "coef", "moyenne"] # noms des colonnes à afficher
for ue_acronym, ue in self.infos["ues"].items(): for ue_acronym, ue in self.infos["ues"].items():
self.ue_rows(rows, ue_acronym, ue, title_bg)
# 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, rows, pdf_style, col_widths
def ue_rows(self, rows: list, ue_acronym: str, ue: dict, title_bg: tuple):
"Décrit une UE dans la table synthèse: titre, sous-titre et liste modules"
# 1er ligne titre UE # 1er ligne titre UE
moy_ue = ue.get("moyenne") moy_ue = ue.get("moyenne")
t = { t = {
@ -138,11 +149,16 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
], ],
} }
rows.append(t) rows.append(t)
if ue["type"] == UE_SPORT:
self.ue_sport_rows(rows, ue, title_bg)
else:
self.ue_std_rows(rows, ue, title_bg)
def ue_std_rows(self, rows: list, ue: dict, title_bg: tuple):
"Lignes décrivant une UE standard dans la table de synthèse"
# 2eme ligne titre UE (bonus/malus/ects) # 2eme ligne titre UE (bonus/malus/ects)
if "ECTS" in ue: if "ECTS" in ue:
ects_txt = ( ects_txt = f'ECTS: {ue["ECTS"]["acquis"]:.3g} / {ue["ECTS"]["total"]:.3g}'
f'ECTS: {ue["ECTS"]["acquis"]:.3g} / {ue["ECTS"]["total"]:.3g}'
)
else: else:
ects_txt = "" ects_txt = ""
t = { t = {
@ -151,36 +167,21 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
"coef": ects_txt, "coef": ects_txt,
"_coef_pdf": Paragraph(f"""<para align=left>{ects_txt}</para>"""), "_coef_pdf": Paragraph(f"""<para align=left>{ects_txt}</para>"""),
"_coef_colspan": 2, "_coef_colspan": 2,
# "_css_row_class": "",
# "_pdf_row_markup": [""],
"_pdf_style": [ "_pdf_style": [
("BACKGROUND", (0, 0), (-1, 0), title_bg), ("BACKGROUND", (0, 0), (-1, 0), title_bg),
( ("LINEBELOW", (0, 0), (-1, 0), self.PDF_LINEWIDTH, self.PDF_LINECOLOR),
"LINEBELOW", # cadre autour du bonus/malus, gris clair
(0, 0), ("BOX", (0, 0), (0, 0), self.PDF_LINEWIDTH, (0.7, 0.7, 0.7)),
(-1, 0),
self.PDF_LINEWIDTH,
self.PDF_LINECOLOR,
),
# cadre autour du bonus/malus
(
"BOX",
(0, 0),
(0, 0),
self.PDF_LINEWIDTH,
(0.7, 0.7, 0.7), # gris clair
),
], ],
} }
rows.append(t) rows.append(t)
# Liste chaque ressource puis SAE
# Liste chaque ressource puis chaque SAE
for mod_type in ("ressources", "saes"): for mod_type in ("ressources", "saes"):
for mod_code, mod in ue[mod_type].items(): for mod_code, mod in ue[mod_type].items():
t = { t = {
"titre": f"{mod_code} {self.infos[mod_type][mod_code]['titre']}", "titre": f"{mod_code} {self.infos[mod_type][mod_code]['titre']}",
"moyenne": Paragraph( "moyenne": Paragraph(f'<para align=right>{mod["moyenne"]}</para>'),
f'<para align=right>{mod["moyenne"]}</para>'
),
"coef": mod["coef"], "coef": mod["coef"],
"_coef_pdf": Paragraph( "_coef_pdf": Paragraph(
f"<para align=right><i>{mod['coef']}</i></para>" f"<para align=right><i>{mod['coef']}</i></para>"
@ -196,12 +197,17 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
], ],
} }
rows.append(t) rows.append(t)
# Global pdf style commands:
pdf_style = [ def ue_sport_rows(self, rows: list, ue: dict, title_bg: tuple):
("VALIGN", (0, 0), (-1, -1), "TOP"), "Lignes décrivant l'UE bonus dans la table de synthèse"
("BOX", (0, 0), (-1, -1), 0.4, blue), # ajoute cadre extérieur bleu: # UE BONUS
] for mod_code, mod in ue["modules"].items():
return col_keys, rows, pdf_style, col_widths rows.append(
{
"titre": f"{mod_code} {mod['titre']}",
}
)
self.evaluations_rows(rows, mod["evaluations"])
def but_table_ressources(self): def but_table_ressources(self):
"""La table de synthèse; pour chaque ressources, note et liste d'évaluations """La table de synthèse; pour chaque ressources, note et liste d'évaluations
@ -227,7 +233,10 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
- largeurs de colonnes pour PDF - largeurs de colonnes pour PDF
""" """
# UE à utiliser pour les poids (# colonne/UE) # UE à utiliser pour les poids (# colonne/UE)
ue_acros = list(self.infos["ues"].keys()) # ['RT1.1', 'RT2.1', 'RT3.1'] ue_infos = self.infos["ues"]
ue_acros = list(
[k for k in ue_infos if ue_infos[k]["type"] != UE_SPORT]
) # ['RT1.1', 'RT2.1', 'RT3.1']
# Colonnes à afficher: # Colonnes à afficher:
col_keys = ["titre"] + ue_acros + ["coef", "moyenne"] col_keys = ["titre"] + ue_acros + ["coef", "moyenne"]
# Largeurs des colonnes: # Largeurs des colonnes:
@ -289,7 +298,18 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
} }
rows.append(t) rows.append(t)
# Evaluations: # Evaluations:
for e in mod["evaluations"]: self.evaluations_rows(rows, mod["evaluations"], ue_acros)
# 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, rows, pdf_style, col_widths
def evaluations_rows(self, rows, evaluations, ue_acros=()):
"lignes des évaluations"
for e in evaluations:
t = { t = {
"titre": f"{e['description']}", "titre": f"{e['description']}",
"moyenne": e["note"]["value"], "moyenne": e["note"]["value"],
@ -323,9 +343,3 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
) )
col_idx += 1 col_idx += 1
rows.append(t) rows.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, rows, pdf_style, col_widths

View File

@ -1,7 +1,7 @@
# -*- mode: python -*- # -*- mode: python -*-
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
SCOVERSION = "9.1.80" SCOVERSION = "9.1.81"
SCONAME = "ScoDoc" SCONAME = "ScoDoc"