123 lines
4.2 KiB
Python
123 lines
4.2 KiB
Python
##############################################################################
|
|
# ScoDoc
|
|
# Copyright (c) 1999 - 2023 Emmanuel Viennet. All rights reserved.
|
|
# See LICENSE
|
|
##############################################################################
|
|
|
|
"""Génération bulletin BUT PDF synthétique en une page
|
|
|
|
On génère du PDF avec reportLab en utilisant les classes
|
|
ScoDoc BulletinGenerator et GenTable.
|
|
|
|
"""
|
|
from flask_login import current_user
|
|
|
|
from reportlab.lib.colors import blue
|
|
from reportlab.lib.units import cm, mm
|
|
from reportlab.platypus import Paragraph, Spacer
|
|
|
|
from app.but import cursus_but
|
|
from app.models import FormSemestre, Identite, ScolarFormSemestreValidation
|
|
|
|
from app.scodoc.sco_bulletins_standard import BulletinGeneratorStandard
|
|
from app.scodoc.sco_logos import Logo
|
|
from app.scodoc import gen_tables, sco_pdf, sco_preferences
|
|
from app.scodoc.sco_pdf import PDFLOCK
|
|
|
|
|
|
def make_bulletin_but_court_pdf(
|
|
bul: dict = None,
|
|
cursus: cursus_but.EtudCursusBUT = None,
|
|
decision_ues: dict = None,
|
|
ects_total: float = 0.0,
|
|
etud: Identite = None,
|
|
formsemestre: FormSemestre = None,
|
|
logo: Logo = None,
|
|
title: str = "",
|
|
ue_validation_by_niveau: dict[tuple[int, str], ScolarFormSemestreValidation] = None,
|
|
) -> bytes:
|
|
# A priori ce verrou n'est plus nécessaire avec Flask (multi-process)
|
|
# mais...
|
|
try:
|
|
PDFLOCK.acquire()
|
|
bul_generator = BulletinGeneratorBUTCourt(**locals())
|
|
bul_pdf = bul_generator.generate(format="pdf")
|
|
finally:
|
|
PDFLOCK.release()
|
|
return bul_pdf
|
|
|
|
|
|
class BulletinGeneratorBUTCourt(BulletinGeneratorStandard):
|
|
"""Ce générateur de bulletin BUT court est assez différent des autres bulletins.
|
|
Ne génére que du PDF.
|
|
Il reprend la mise en page et certains éléments (pied de page, signature).
|
|
"""
|
|
|
|
# spécialisation du BulletinGeneratorStandard, ne pas présenter à l'utilisateur:
|
|
list_in_menu = False
|
|
scale_table_in_page = True # pas de mise à l'échelle pleine page auto
|
|
multi_pages = False # une page par bulletin
|
|
small_fontsize = "8"
|
|
|
|
def __init__(
|
|
self,
|
|
bul: dict = None,
|
|
cursus: cursus_but.EtudCursusBUT = None,
|
|
decision_ues: dict = None,
|
|
ects_total: float = 0.0,
|
|
etud: Identite = None,
|
|
formsemestre: FormSemestre = None,
|
|
logo: Logo = None,
|
|
title: str = "",
|
|
ue_validation_by_niveau: dict[
|
|
tuple[int, str], ScolarFormSemestreValidation
|
|
] = None,
|
|
):
|
|
# données pour anciens codes bulletins... à moderniser
|
|
infos = {
|
|
"etud": etud.to_dict_bul(),
|
|
"filigranne": None,
|
|
"formsemestre_id": formsemestre.id,
|
|
"nbabs": 0,
|
|
"nbabsjust": 0,
|
|
}
|
|
super().__init__(infos, authuser=current_user)
|
|
self.bul = bul
|
|
self.cursus = cursus
|
|
self.decision_ues = decision_ues
|
|
self.ects_total = ects_total
|
|
self.etud = etud
|
|
self.formsemestre = formsemestre
|
|
self.logo = logo
|
|
self.title = title
|
|
self.ue_validation_by_niveau = ue_validation_by_niveau
|
|
|
|
def bul_table(self, fmt=None):
|
|
"""Génère la table centrale du bulletin de notes
|
|
Renvoie: une liste d'objets PLATYPUS (eg instance de Table).
|
|
L'argument fmt est ici ignoré (toujours en PDF)
|
|
"""
|
|
ue_table = self.build_ue_table()
|
|
|
|
return ue_table.gen(format="pdf")
|
|
|
|
def build_ue_table(self) -> gen_tables.GenTable:
|
|
"""Table avec les résultats d'UE du semestre courant"""
|
|
columns_ids = ("titre", "UE1", "UE2")
|
|
rows = [
|
|
{"titre": "ligne 1", "UE1": "12.", "UE2": "13"},
|
|
{"titre": "ligne 2", "UE1": "14.", "UE2": "15"},
|
|
]
|
|
pdf_style = [
|
|
("VALIGN", (0, 0), (-1, -1), "TOP"),
|
|
("BOX", (0, 0), (-1, -1), 0.4, blue), # ajoute cadre extérieur bleu
|
|
]
|
|
col_widths = {"titre": 3 * cm, "UE1": 1 * cm, "UE2": 1 * cm}
|
|
return gen_tables.GenTable(
|
|
rows=rows,
|
|
columns_ids=columns_ids,
|
|
pdf_table_style=pdf_style,
|
|
pdf_col_widths=[col_widths[k] for k in columns_ids],
|
|
preferences=sco_preferences.SemPreferences(self.formsemestre.id),
|
|
)
|