From f61a528d126061c2af644a8e113a4de58a394cc8 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 10 Mar 2022 20:44:01 +0100 Subject: [PATCH] =?UTF-8?q?Bul.=20BUT:=20am=C3=A9lioration,=20inverse=20co?= =?UTF-8?q?lonnes=20droites?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/but/bulletin_but_pdf.py | 99 +++++++++++++++++++++++++------------ app/views/notes.py | 1 - 2 files changed, 68 insertions(+), 32 deletions(-) diff --git a/app/but/bulletin_but_pdf.py b/app/but/bulletin_but_pdf.py index 5263091a..ea3291c8 100644 --- a/app/but/bulletin_but_pdf.py +++ b/app/but/bulletin_but_pdf.py @@ -6,8 +6,7 @@ """Génération bulletin BUT au format PDF standard """ -import itertools -from reportlab.platypus import KeepInFrame, Paragraph, Spacer +from reportlab.platypus import Paragraph, Spacer from app.scodoc.sco_pdf import blue, cm, mm @@ -85,6 +84,7 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard): "titre": "Unités d'enseignement", "moyenne": "Note/20", "coef": "Coef.", + "_coef_pdf": Paragraph("Coef."), "_css_row_class": "note_bold", "_pdf_row_markup": ["b"], "_pdf_style": [ @@ -100,7 +100,7 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard): ], } ] - col_keys = ["titre", "moyenne", "coef"] # noms des colonnes à afficher + 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") @@ -123,16 +123,16 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard): } rows.append(t) # 2eme ligne titre UE (bonus/malus/ects) + ects_txt = f'ECTS: {ue["ECTS"]["acquis"]:.3g} / {ue["ECTS"]["total"]:.3g}' t = { "titre": f"""Bonus: {ue['bonus']} - Malus: { ue["malus"]}""", - "moyenne": f"""ECTS: {ue["ECTS"]["acquis"]} / {ue["ECTS"]["total"]}""", - "_moyenne_colspan": 2, + "coef": ects_txt, + "_coef_pdf": Paragraph(f"""{ects_txt}"""), + "_coef_colspan": 2, # "_css_row_class": "", # "_pdf_row_markup": [""], "_pdf_style": [ - ("ALIGN", (0, 0), (1, 0), "RIGHT"), - ("TEXTCOLOR", (0, 0), (-1, 0), blue), ("BACKGROUND", (0, 0), (-1, 0), title_bg), ( "LINEBELOW", @@ -141,6 +141,14 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard): 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) @@ -195,40 +203,54 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard): - pdf_style : commandes table Platypus - largeurs de colonnes pour PDF """ + poids_fontsize = "8" + # UE à utiliser pour les poids (# colonne/UE) + ue_acros = list(self.infos["ues"].keys()) # ['RT1.1', 'RT2.1', 'RT3.1'] + # Colonnes à afficher: + col_keys = ["titre"] + ue_acros + ["coef", "moyenne"] + # Largeurs des colonnes: col_widths = { "titre": None, + # "poids": None, "moyenne": 2 * cm, "coef": 2 * cm, } + for ue_acro in ue_acros: + col_widths[ue_acro] = 12 * mm # largeur col. poids + title_bg = tuple(x / 255.0 for x in title_bg) # elems pour générer table avec gen_table (liste de dicts) - rows = [ - # Ligne de titres - { - "titre": title, - "moyenne": "Note/20", - "coef": "Coef.", - "_css_row_class": "note_bold", - "_pdf_row_markup": ["b"], - "_pdf_style": [ - ("BACKGROUND", (0, 0), (-1, 0), title_bg), - ("BOTTOMPADDING", (0, 0), (-1, 0), 7), - ( - "LINEBELOW", - (0, 0), - (-1, 0), - self.PDF_LINEWIDTH, - blue, - ), - ], - } - ] - col_keys = ["titre", "moyenne", "coef"] # noms des colonnes à afficher + # Ligne de titres + t = { + "titre": title, + # "_titre_colspan": 1 + len(ue_acros), + "moyenne": "Note/20", + "coef": "Coef.", + "_coef_pdf": Paragraph("Coef."), + "_css_row_class": "note_bold", + "_pdf_row_markup": ["b"], + "_pdf_style": [ + ("BACKGROUND", (0, 0), (-1, 0), title_bg), + ("BOTTOMPADDING", (0, 0), (-1, 0), 7), + ( + "LINEBELOW", + (0, 0), + (-1, 0), + self.PDF_LINEWIDTH, + blue, + ), + ], + } + for ue_acro in ue_acros: + t[ue_acro] = Paragraph( + f"{ue_acro}" + ) + rows = [t] for mod_code, mod in self.infos[mod_type].items(): # 1er ligne titre module t = { "titre": f"{mod_code} - {mod['titre']}", - "moyenne": "", # pas de moyenne + "_titre_colspan": 2 + len(ue_acros), "_css_row_class": "note_bold", "_pdf_row_markup": ["b"], "_pdf_style": [ @@ -251,7 +273,7 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard): "moyenne": e["note"]["value"], "coef": e["coef"], "_coef_pdf": Paragraph( - f"{e['coef']}" + f"{e['coef']}" ), "_pdf_style": [ ( @@ -263,6 +285,21 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard): ) ], } + col_idx = 1 # 1ere col. poids + for ue_acro in ue_acros: + t[ue_acro] = Paragraph( + f"""{e["poids"].get(ue_acro, "")}""" + ) + 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) # Global pdf style commands: pdf_style = [ diff --git a/app/views/notes.py b/app/views/notes.py index dfc8e644..345511ce 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -1885,7 +1885,6 @@ def formsemestre_bulletins_choice( formsemestre_id, title="", explanation="", choose_mail=False ): """Choix d'une version de bulletin""" - sem = sco_formsemestre.get_formsemestre(formsemestre_id) H = [ html_sco_header.html_sem_header(title), """