Bul. BUT: amélioration, inverse colonnes droites

This commit is contained in:
Emmanuel Viennet 2022-03-10 20:44:01 +01:00
parent 5a56138e55
commit f61a528d12
2 changed files with 68 additions and 32 deletions

View File

@ -6,8 +6,7 @@
"""Génération bulletin BUT au format PDF standard """Génération bulletin BUT au format PDF standard
""" """
import itertools from reportlab.platypus import Paragraph, Spacer
from reportlab.platypus import KeepInFrame, Paragraph, Spacer
from app.scodoc.sco_pdf import blue, cm, mm from app.scodoc.sco_pdf import blue, cm, mm
@ -85,6 +84,7 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
"titre": "Unités d'enseignement", "titre": "Unités d'enseignement",
"moyenne": "Note/20", "moyenne": "Note/20",
"coef": "Coef.", "coef": "Coef.",
"_coef_pdf": Paragraph("<para align=right><b><i>Coef.</i></b></para>"),
"_css_row_class": "note_bold", "_css_row_class": "note_bold",
"_pdf_row_markup": ["b"], "_pdf_row_markup": ["b"],
"_pdf_style": [ "_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(): for ue_acronym, ue in self.infos["ues"].items():
# 1er ligne titre UE # 1er ligne titre UE
moy_ue = ue.get("moyenne") moy_ue = ue.get("moyenne")
@ -123,16 +123,16 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
} }
rows.append(t) rows.append(t)
# 2eme ligne titre UE (bonus/malus/ects) # 2eme ligne titre UE (bonus/malus/ects)
ects_txt = f'ECTS: {ue["ECTS"]["acquis"]:.3g} / {ue["ECTS"]["total"]:.3g}'
t = { t = {
"titre": f"""Bonus: {ue['bonus']} - Malus: { "titre": f"""Bonus: {ue['bonus']} - Malus: {
ue["malus"]}""", ue["malus"]}""",
"moyenne": f"""ECTS: {ue["ECTS"]["acquis"]} / {ue["ECTS"]["total"]}""", "coef": ects_txt,
"_moyenne_colspan": 2, "_coef_pdf": Paragraph(f"""<para align=right>{ects_txt}</para>"""),
"_coef_colspan": 2,
# "_css_row_class": "", # "_css_row_class": "",
# "_pdf_row_markup": [""], # "_pdf_row_markup": [""],
"_pdf_style": [ "_pdf_style": [
("ALIGN", (0, 0), (1, 0), "RIGHT"),
("TEXTCOLOR", (0, 0), (-1, 0), blue),
("BACKGROUND", (0, 0), (-1, 0), title_bg), ("BACKGROUND", (0, 0), (-1, 0), title_bg),
( (
"LINEBELOW", "LINEBELOW",
@ -141,6 +141,14 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
self.PDF_LINEWIDTH, self.PDF_LINEWIDTH,
self.PDF_LINECOLOR, 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)
@ -195,19 +203,30 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
- pdf_style : commandes table Platypus - pdf_style : commandes table Platypus
- largeurs de colonnes pour PDF - 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 = { col_widths = {
"titre": None, "titre": None,
# "poids": None,
"moyenne": 2 * cm, "moyenne": 2 * cm,
"coef": 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) title_bg = tuple(x / 255.0 for x in title_bg)
# elems pour générer table avec gen_table (liste de dicts) # elems pour générer table avec gen_table (liste de dicts)
rows = [
# Ligne de titres # Ligne de titres
{ t = {
"titre": title, "titre": title,
# "_titre_colspan": 1 + len(ue_acros),
"moyenne": "Note/20", "moyenne": "Note/20",
"coef": "Coef.", "coef": "Coef.",
"_coef_pdf": Paragraph("<para align=right><i>Coef.</i></para>"),
"_css_row_class": "note_bold", "_css_row_class": "note_bold",
"_pdf_row_markup": ["b"], "_pdf_row_markup": ["b"],
"_pdf_style": [ "_pdf_style": [
@ -222,13 +241,16 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
), ),
], ],
} }
] for ue_acro in ue_acros:
col_keys = ["titre", "moyenne", "coef"] # noms des colonnes à afficher t[ue_acro] = Paragraph(
f"<para align=right fontSize={poids_fontsize}><i>{ue_acro}</i></para>"
)
rows = [t]
for mod_code, mod in self.infos[mod_type].items(): for mod_code, mod in self.infos[mod_type].items():
# 1er ligne titre module # 1er ligne titre module
t = { t = {
"titre": f"{mod_code} - {mod['titre']}", "titre": f"{mod_code} - {mod['titre']}",
"moyenne": "", # pas de moyenne "_titre_colspan": 2 + len(ue_acros),
"_css_row_class": "note_bold", "_css_row_class": "note_bold",
"_pdf_row_markup": ["b"], "_pdf_row_markup": ["b"],
"_pdf_style": [ "_pdf_style": [
@ -251,7 +273,7 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
"moyenne": e["note"]["value"], "moyenne": e["note"]["value"],
"coef": e["coef"], "coef": e["coef"],
"_coef_pdf": Paragraph( "_coef_pdf": Paragraph(
f"<para align=right><i>{e['coef']}</i></para>" f"<para align=right fontSize={poids_fontsize}><i>{e['coef']}</i></para>"
), ),
"_pdf_style": [ "_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"""<para align=right fontSize={poids_fontsize}><i>{e["poids"].get(ue_acro, "")}</i></para>"""
)
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) rows.append(t)
# Global pdf style commands: # Global pdf style commands:
pdf_style = [ pdf_style = [

View File

@ -1885,7 +1885,6 @@ def formsemestre_bulletins_choice(
formsemestre_id, title="", explanation="", choose_mail=False formsemestre_id, title="", explanation="", choose_mail=False
): ):
"""Choix d'une version de bulletin""" """Choix d'une version de bulletin"""
sem = sco_formsemestre.get_formsemestre(formsemestre_id)
H = [ H = [
html_sco_header.html_sem_header(title), html_sco_header.html_sem_header(title),
""" """