From 2770db1beefe1c5117a10568a7d84c2f4c117480 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 16 Mar 2022 18:51:22 +0100 Subject: [PATCH] =?UTF-8?q?Bul.=20BUT=20PDF:=20affichage=20UE=20bonus=20av?= =?UTF-8?q?ec=20d=C3=A9tails?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/but/bulletin_but_pdf.py | 244 +++++++++++++++++++----------------- sco_version.py | 2 +- 2 files changed, 130 insertions(+), 116 deletions(-) diff --git a/app/but/bulletin_but_pdf.py b/app/but/bulletin_but_pdf.py index ea4610cb7..3cdf62646 100644 --- a/app/but/bulletin_but_pdf.py +++ b/app/but/bulletin_but_pdf.py @@ -11,6 +11,7 @@ from reportlab.platypus import Paragraph, Spacer from app.scodoc.sco_pdf import blue, cm, mm 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_bulletins_standard import BulletinGeneratorStandard @@ -116,86 +117,7 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard): ] col_keys = ["titre", "coef", "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": Paragraph( - f"""{moy_ue.get("value", "-") if moy_ue is not None else "-"}""" - ), - "_css_row_class": "note_bold", - "_pdf_row_markup": ["b"], - "_pdf_style": [ - ( - "LINEABOVE", - (0, 0), - (-1, 0), - self.PDF_LINEWIDTH, - self.PDF_LINECOLOR, - ), - ("BACKGROUND", (0, 0), (-1, 0), title_bg), - ("BOTTOMPADDING", (0, 0), (-1, 0), 7), - ], - } - rows.append(t) - # 2eme ligne titre UE (bonus/malus/ects) - if "ECTS" in ue: - ects_txt = ( - f'ECTS: {ue["ECTS"]["acquis"]:.3g} / {ue["ECTS"]["total"]:.3g}' - ) - else: - ects_txt = "" - t = { - "titre": f"""Bonus: {ue['bonus']} - Malus: { - ue["malus"]}""", - "coef": ects_txt, - "_coef_pdf": Paragraph(f"""{ects_txt}"""), - "_coef_colspan": 2, - # "_css_row_class": "", - # "_pdf_row_markup": [""], - "_pdf_style": [ - ("BACKGROUND", (0, 0), (-1, 0), title_bg), - ( - "LINEBELOW", - (0, 0), - (-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) - # Liste chaque ressource puis SAE - for mod_type in ("ressources", "saes"): - for mod_code, mod in ue[mod_type].items(): - t = { - "titre": f"{mod_code} {self.infos[mod_type][mod_code]['titre']}", - "moyenne": Paragraph( - f'{mod["moyenne"]}' - ), - "coef": mod["coef"], - "_coef_pdf": Paragraph( - f"{mod['coef']}" - ), - "_pdf_style": [ - ( - "LINEBELOW", - (0, 0), - (-1, 0), - self.PDF_LINEWIDTH, - (0.7, 0.7, 0.7), # gris clair - ) - ], - } - rows.append(t) + self.ue_rows(rows, ue_acronym, ue, title_bg) # Global pdf style commands: pdf_style = [ ("VALIGN", (0, 0), (-1, -1), "TOP"), @@ -203,6 +125,90 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard): ] 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 + moy_ue = ue.get("moyenne") + t = { + "titre": f"{ue_acronym} - {ue['titre']}", + "moyenne": Paragraph( + f"""{moy_ue.get("value", "-") if moy_ue is not None else "-"}""" + ), + "_css_row_class": "note_bold", + "_pdf_row_markup": ["b"], + "_pdf_style": [ + ( + "LINEABOVE", + (0, 0), + (-1, 0), + self.PDF_LINEWIDTH, + self.PDF_LINECOLOR, + ), + ("BACKGROUND", (0, 0), (-1, 0), title_bg), + ("BOTTOMPADDING", (0, 0), (-1, 0), 7), + ], + } + 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) + if "ECTS" in ue: + ects_txt = f'ECTS: {ue["ECTS"]["acquis"]:.3g} / {ue["ECTS"]["total"]:.3g}' + else: + ects_txt = "" + t = { + "titre": f"""Bonus: {ue['bonus']} - Malus: { + ue["malus"]}""", + "coef": ects_txt, + "_coef_pdf": Paragraph(f"""{ects_txt}"""), + "_coef_colspan": 2, + "_pdf_style": [ + ("BACKGROUND", (0, 0), (-1, 0), title_bg), + ("LINEBELOW", (0, 0), (-1, 0), self.PDF_LINEWIDTH, self.PDF_LINECOLOR), + # cadre autour du bonus/malus, gris clair + ("BOX", (0, 0), (0, 0), self.PDF_LINEWIDTH, (0.7, 0.7, 0.7)), + ], + } + rows.append(t) + + # Liste chaque ressource puis chaque SAE + for mod_type in ("ressources", "saes"): + for mod_code, mod in ue[mod_type].items(): + t = { + "titre": f"{mod_code} {self.infos[mod_type][mod_code]['titre']}", + "moyenne": Paragraph(f'{mod["moyenne"]}'), + "coef": mod["coef"], + "_coef_pdf": Paragraph( + f"{mod['coef']}" + ), + "_pdf_style": [ + ( + "LINEBELOW", + (0, 0), + (-1, 0), + self.PDF_LINEWIDTH, + (0.7, 0.7, 0.7), # gris clair + ) + ], + } + rows.append(t) + + def ue_sport_rows(self, rows: list, ue: dict, title_bg: tuple): + "Lignes décrivant l'UE bonus dans la table de synthèse" + # UE BONUS + for mod_code, mod in ue["modules"].items(): + rows.append( + { + "titre": f"{mod_code} {mod['titre']}", + } + ) + self.evaluations_rows(rows, mod["evaluations"]) + def but_table_ressources(self): """La table de synthèse; pour chaque ressources, note et liste d'évaluations Renvoie: colkeys, P, pdf_style, colWidths @@ -227,7 +233,10 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard): - largeurs de colonnes pour PDF """ # 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: col_keys = ["titre"] + ue_acros + ["coef", "moyenne"] # Largeurs des colonnes: @@ -289,43 +298,48 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard): } rows.append(t) # Evaluations: - for e in mod["evaluations"]: - t = { - "titre": f"{e['description']}", - "moyenne": e["note"]["value"], - "coef": e["coef"], - "_coef_pdf": Paragraph( - f"{e['coef']}" - ), - "_pdf_style": [ - ( - "LINEBELOW", - (0, 0), - (-1, 0), - self.PDF_LINEWIDTH, - (0.7, 0.7, 0.7), # gris clair - ) - ], - } - col_idx = 1 # 1ere col. poids - for ue_acro in ue_acros: - t[ue_acro] = Paragraph( - f"""{e["poids"].get(ue_acro, "") or ""}""" - ) - t["_pdf_style"].append( - ( - "BOX", - (col_idx, 0), - (col_idx, 0), - self.PDF_LINEWIDTH, - (0.7, 0.7, 0.7), # gris clair - ), - ) - col_idx += 1 - rows.append(t) + 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 = { + "titre": f"{e['description']}", + "moyenne": e["note"]["value"], + "coef": e["coef"], + "_coef_pdf": Paragraph( + f"{e['coef']}" + ), + "_pdf_style": [ + ( + "LINEBELOW", + (0, 0), + (-1, 0), + self.PDF_LINEWIDTH, + (0.7, 0.7, 0.7), # gris clair + ) + ], + } + col_idx = 1 # 1ere col. poids + for ue_acro in ue_acros: + t[ue_acro] = Paragraph( + f"""{e["poids"].get(ue_acro, "") or ""}""" + ) + t["_pdf_style"].append( + ( + "BOX", + (col_idx, 0), + (col_idx, 0), + self.PDF_LINEWIDTH, + (0.7, 0.7, 0.7), # gris clair + ), + ) + col_idx += 1 + rows.append(t) diff --git a/sco_version.py b/sco_version.py index d586d6088..e962db1f0 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.1.80" +SCOVERSION = "9.1.81" SCONAME = "ScoDoc"