diff --git a/app/scodoc/sco_bulletins_standard.py b/app/scodoc/sco_bulletins_standard.py index 83b33a0e04..0039dba5ef 100644 --- a/app/scodoc/sco_bulletins_standard.py +++ b/app/scodoc/sco_bulletins_standard.py @@ -46,16 +46,20 @@ de la forme %(XXX)s sont remplacées par la valeur de XXX, pour XXX dans: Balises img: actuellement interdites. """ -from flask import url_for, g - -from reportlab.platypus import KeepTogether, Paragraph, Spacer, Table -from reportlab.lib.units import cm, mm +from flask import g, url_for from reportlab.lib.colors import Color, blue +from reportlab.lib.units import cm, mm +from reportlab.platypus import KeepTogether, Paragraph, Spacer, Table import app.scodoc.sco_utils as scu -from app.scodoc.sco_pdf import SU, make_paras -from app.scodoc import sco_preferences -from app.scodoc.sco_permissions import Permission +from app.scodoc import ( + gen_tables, + sco_bulletins_generator, + sco_bulletins_pdf, + sco_evaluations, + sco_groups, + sco_preferences, +) from app.scodoc.codes_cursus import ( UE_COLORS, UE_DEFAULT_COLOR, @@ -63,17 +67,17 @@ from app.scodoc.codes_cursus import ( UE_SPORT, UE_STANDARD, ) -from app.scodoc import sco_bulletins_generator -from app.scodoc import sco_bulletins_pdf -from app.scodoc import sco_groups -from app.scodoc import sco_evaluations -from app.scodoc import gen_tables +from app.scodoc.sco_exceptions import ScoPDFFormatError +from app.scodoc.sco_pdf import SU, make_paras +from app.scodoc.sco_permissions import Permission # Important: Le nom de la classe ne doit pas changer (bien le choisir), # car il sera stocké en base de données (dans les préférences) class BulletinGeneratorStandard(sco_bulletins_generator.BulletinGenerator): - description = "standard ScoDoc (version 2011)" # la description doit être courte: elle apparait dans le menu de paramètrage ScoDoc + "Les bulletins standards" + # la description doit être courte: elle apparait dans le menu de paramètrage ScoDoc + description = "standard ScoDoc (version 2011)" supported_formats = ["html", "pdf"] def bul_title_pdf(self) -> list: @@ -158,31 +162,47 @@ class BulletinGeneratorStandard(sco_bulletins_generator.BulletinGenerator): H.append('
') for app in self.infos["appreciations_list"]: if can_edit_app: - mlink = ( - 'modifier supprimer' - % (app["id"], app["id"]) - ) + mlink = f"""modifier + supprimer""" else: mlink = "" H.append( - '

%s%s%s

' - % (app["date"], app["comment"], mlink) + f"""

{app["date"]}{ + app["comment"]}{mlink} +

""" ) if can_edit_app: H.append( - '

Ajouter une appréciation

' + f"""

Ajouter une appréciation

""" % self.infos ) H.append("
") # Appréciations sur PDF: if self.infos.get("appreciations_list", False): story.append(Spacer(1, 3 * mm)) - story.append( - Paragraph( - SU("Appréciation : " + "\n".join(self.infos["appreciations_txt"])), - self.CellStyle, + try: + story.append( + Paragraph( + SU( + "Appréciation : " + + "\n".join(self.infos["appreciations_txt"]) + ), + self.CellStyle, + ) ) - ) + except AttributeError as exc: + raise ScoPDFFormatError( + "Appréciation invalide bloquant la génération du pdf" + ) from exc # ----- DECISION JURY if self.preferences["bul_show_decision"]: diff --git a/app/scodoc/sco_pdf.py b/app/scodoc/sco_pdf.py index 841f8b3fa5..631d71b072 100755 --- a/app/scodoc/sco_pdf.py +++ b/app/scodoc/sco_pdf.py @@ -55,10 +55,10 @@ from reportlab.lib import styles from flask import g +from app import log +from app.scodoc.sco_exceptions import ScoGenError, ScoPDFFormatError, ScoValueError from app.scodoc import sco_utils as scu from app.scodoc.sco_utils import CONFIG -from app import log -from app.scodoc.sco_exceptions import ScoGenError, ScoValueError import sco_version PAGE_HEIGHT = defaultPageSize[1] @@ -136,7 +136,10 @@ def make_paras(txt: str, style, suppress_empty=False) -> list[Paragraph]: if m.group(1): # non empty paragraph r.append(para) paras = r - result = [Paragraph(SU(s), style) for s in paras] + try: + result = [Paragraph(SU(s), style) for s in paras] + except AttributeError as exc: + raise ScoPDFFormatError("PDF: paragraphe avec balisage invalide") from exc except OSError as e: msg = str(e) # If a file is missing, try to display the invalid name