From 6d3f276cc0c237abff48880603d9bd5946d354fa Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 17 Jan 2024 23:52:14 +0100 Subject: [PATCH] Filigranne bulletins BUT: fix #844 --- app/but/bulletin_but.py | 6 ++---- app/but/bulletin_but_court.py | 4 ++++ app/but/bulletin_but_court_pdf.py | 4 +++- app/scodoc/sco_bulletins_pdf.py | 29 +++++++++++++++++++++++++---- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/app/but/bulletin_but.py b/app/but/bulletin_but.py index c8cf061d5..5ec30c5e3 100644 --- a/app/but/bulletin_but.py +++ b/app/but/bulletin_but.py @@ -499,10 +499,8 @@ class BulletinBUT: d["etud"]["etat_civil"] = etud.etat_civil d.update(self.res.sem) etud_etat = self.res.get_etud_etat(etud.id) - d["filigranne"] = sco_bulletins_pdf.get_filigranne( - etud_etat, - self.prefs, - decision_sem=d["semestre"].get("decision"), + d["filigranne"] = sco_bulletins_pdf.get_filigranne_apc( + etud_etat, self.prefs, etud.id, res=self.res ) if etud_etat == scu.DEMISSION: d["demission"] = "(Démission)" diff --git a/app/but/bulletin_but_court.py b/app/but/bulletin_but_court.py index ea52d0f23..c8d258280 100644 --- a/app/but/bulletin_but_court.py +++ b/app/but/bulletin_but_court.py @@ -35,6 +35,7 @@ from app.decorators import ( permission_required, ) from app.models import FormSemestre, FormSemestreInscription, Identite +from app.scodoc import sco_bulletins_pdf from app.scodoc.codes_cursus import UE_STANDARD from app.scodoc.sco_exceptions import ScoNoReferentielCompetences, ScoValueError from app.scodoc.sco_logos import find_logo @@ -104,8 +105,10 @@ def _build_bulletin_but_infos( bulletins_sem = BulletinBUT(formsemestre) if fmt == "pdf": bul: dict = bulletins_sem.bulletin_etud_complet(etud) + filigranne = bul["filigranne"] else: # la même chose avec un peu moins d'infos bul: dict = bulletins_sem.bulletin_etud(etud, force_publishing=True) + filigranne = "" decision_ues = ( {x["acronyme"]: x for x in bul["semestre"]["decision_ue"]} if "semestre" in bul and "decision_ue" in bul["semestre"] @@ -131,6 +134,7 @@ def _build_bulletin_but_infos( "decision_ues": decision_ues, "ects_total": ects_total, "etud": etud, + "filigranne": filigranne, "formsemestre": formsemestre, "logo": logo, "prefs": bulletins_sem.prefs, diff --git a/app/but/bulletin_but_court_pdf.py b/app/but/bulletin_but_court_pdf.py index bef62ae4b..585280451 100644 --- a/app/but/bulletin_but_court_pdf.py +++ b/app/but/bulletin_but_court_pdf.py @@ -48,6 +48,7 @@ def make_bulletin_but_court_pdf( ects_total: float = 0.0, etud: Identite = None, formsemestre: FormSemestre = None, + filigranne="" logo: Logo = None, prefs: SemPreferences = None, title: str = "", @@ -86,6 +87,7 @@ class BulletinGeneratorBUTCourt(BulletinGeneratorStandard): decision_ues: dict = None, ects_total: float = 0.0, etud: Identite = None, + filigranne="", formsemestre: FormSemestre = None, logo: Logo = None, prefs: SemPreferences = None, @@ -95,7 +97,7 @@ class BulletinGeneratorBUTCourt(BulletinGeneratorStandard): ] = None, ues_acronyms: list[str] = None, ): - super().__init__(bul, authuser=current_user) + super().__init__(bul, authuser=current_user, filigranne=filigranne) self.bul = bul self.cursus = cursus self.decision_ues = decision_ues diff --git a/app/scodoc/sco_bulletins_pdf.py b/app/scodoc/sco_bulletins_pdf.py index f61ba8ac5..adac2988d 100644 --- a/app/scodoc/sco_bulletins_pdf.py +++ b/app/scodoc/sco_bulletins_pdf.py @@ -60,6 +60,7 @@ import traceback from flask import g, request from app import log, ScoValueError +from app.comp.res_but import ResultatsSemestreBUT from app.models import FormSemestre, Identite from app.scodoc import sco_cache from app.scodoc import codes_cursus @@ -318,14 +319,34 @@ def get_etud_bulletins_pdf(etudid, version="selectedevals"): return pdfdoc, filename -def get_filigranne(etud_etat: str, prefs, decision_sem=None) -> str: - """Texte à placer en "filigranne" sur le bulletin pdf""" +def get_filigranne( + etud_etat: str, prefs, decision_sem: str | None | bool = None +) -> str: + """Texte à placer en "filigranne" sur le bulletin pdf. + etud_etat : etat de l'inscription (I ou D) + decision_sem = code jury ou vide + """ if etud_etat == scu.DEMISSION: return "Démission" - elif etud_etat == codes_cursus.DEF: + if etud_etat == codes_cursus.DEF: return "Défaillant" - elif (prefs["bul_show_temporary"] and not decision_sem) or prefs[ + if (prefs["bul_show_temporary"] and not decision_sem) or prefs[ "bul_show_temporary_forced" ]: return prefs["bul_temporary_txt"] return "" + + +def get_filigranne_apc( + etud_etat: str, prefs, etudid: int, res: ResultatsSemestreBUT +) -> str: + """Texte à placer en "filigranne" sur le bulletin pdf. + Version optimisée pour BUT + """ + if prefs["bul_show_temporary_forced"]: + return get_filigranne(etud_etat, prefs) + if prefs["bul_show_temporary"]: + # requete les décisions de jury + decision_sem = res.etud_has_decision(etudid) + return get_filigranne(etud_etat, prefs, decision_sem=decision_sem) + return get_filigranne(etud_etat, prefs)