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
"""
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("<para align=right><b><i>Coef.</i></b></para>"),
"_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"""<para align=right>{ects_txt}</para>"""),
"_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("<para align=right><i>Coef.</i></para>"),
"_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"<para align=right fontSize={poids_fontsize}><i>{ue_acro}</i></para>"
)
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"<para align=right><i>{e['coef']}</i></para>"
f"<para align=right fontSize={poids_fontsize}><i>{e['coef']}</i></para>"
),
"_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)
# Global pdf style commands:
pdf_style = [

View File

@ -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),
"""