1
0
forked from ScoDoc/ScoDoc

améliore légèrement le traitement des exceptions pdf

This commit is contained in:
Emmanuel Viennet 2023-08-28 17:02:21 +02:00
parent 1cf9d87fb9
commit 36a5c15e3a
2 changed files with 51 additions and 28 deletions

View File

@ -46,16 +46,20 @@ de la forme %(XXX)s sont remplacées par la valeur de XXX, pour XXX dans:
Balises img: actuellement interdites. Balises img: actuellement interdites.
""" """
from flask import url_for, g from flask import g, url_for
from reportlab.platypus import KeepTogether, Paragraph, Spacer, Table
from reportlab.lib.units import cm, mm
from reportlab.lib.colors import Color, blue 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 import app.scodoc.sco_utils as scu
from app.scodoc.sco_pdf import SU, make_paras from app.scodoc import (
from app.scodoc import sco_preferences gen_tables,
from app.scodoc.sco_permissions import Permission sco_bulletins_generator,
sco_bulletins_pdf,
sco_evaluations,
sco_groups,
sco_preferences,
)
from app.scodoc.codes_cursus import ( from app.scodoc.codes_cursus import (
UE_COLORS, UE_COLORS,
UE_DEFAULT_COLOR, UE_DEFAULT_COLOR,
@ -63,17 +67,17 @@ from app.scodoc.codes_cursus import (
UE_SPORT, UE_SPORT,
UE_STANDARD, UE_STANDARD,
) )
from app.scodoc import sco_bulletins_generator from app.scodoc.sco_exceptions import ScoPDFFormatError
from app.scodoc import sco_bulletins_pdf from app.scodoc.sco_pdf import SU, make_paras
from app.scodoc import sco_groups from app.scodoc.sco_permissions import Permission
from app.scodoc import sco_evaluations
from app.scodoc import gen_tables
# Important: Le nom de la classe ne doit pas changer (bien le choisir), # 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) # car il sera stocké en base de données (dans les préférences)
class BulletinGeneratorStandard(sco_bulletins_generator.BulletinGenerator): 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"] supported_formats = ["html", "pdf"]
def bul_title_pdf(self) -> list: def bul_title_pdf(self) -> list:
@ -158,31 +162,47 @@ class BulletinGeneratorStandard(sco_bulletins_generator.BulletinGenerator):
H.append('<div class="bull_appreciations">') H.append('<div class="bull_appreciations">')
for app in self.infos["appreciations_list"]: for app in self.infos["appreciations_list"]:
if can_edit_app: if can_edit_app:
mlink = ( mlink = f"""<a class="stdlink" href="{
'<a class="stdlink" href="appreciation_add_form?id=%s">modifier</a> <a class="stdlink" href="appreciation_add_form?id=%s&suppress=1">supprimer</a>' url_for('notes.appreciation_add_form', scodoc_dept=g.scodoc_dept, id=app['id'])
% (app["id"], app["id"]) }">modifier</a>
) <a class="stdlink" href="{
url_for('notes.appreciation_add_form', scodoc_dept=g.scodoc_dept, id=app['id'], suppress=1)
}">supprimer</a>"""
else: else:
mlink = "" mlink = ""
H.append( H.append(
'<p><span class="bull_appreciations_date">%s</span>%s<span class="bull_appreciations_link">%s</span></p>' f"""<p><span class="bull_appreciations_date">{app["date"]}</span>{
% (app["date"], app["comment"], mlink) app["comment"]}<span class="bull_appreciations_link">{mlink}</span>
</p>"""
) )
if can_edit_app: if can_edit_app:
H.append( H.append(
'<p><a class="stdlink" href="appreciation_add_form?etudid=%(etudid)s&formsemestre_id=%(formsemestre_id)s">Ajouter une appréciation</a></p>' f"""<p><a class="stdlink" href="{
url_for('notes.appreciation_add_form', scodoc_dept=g.scodoc_dept,
etudid=self.infos['etudid'],
formsemestre_id=self.infos['formsemestre_id']
)
}">Ajouter une appréciation</a></p>"""
% self.infos % self.infos
) )
H.append("</div>") H.append("</div>")
# Appréciations sur PDF: # Appréciations sur PDF:
if self.infos.get("appreciations_list", False): if self.infos.get("appreciations_list", False):
story.append(Spacer(1, 3 * mm)) story.append(Spacer(1, 3 * mm))
story.append( try:
Paragraph( story.append(
SU("Appréciation : " + "\n".join(self.infos["appreciations_txt"])), Paragraph(
self.CellStyle, 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 # ----- DECISION JURY
if self.preferences["bul_show_decision"]: if self.preferences["bul_show_decision"]:

View File

@ -55,10 +55,10 @@ from reportlab.lib import styles
from flask import g 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 import sco_utils as scu
from app.scodoc.sco_utils import CONFIG from app.scodoc.sco_utils import CONFIG
from app import log
from app.scodoc.sco_exceptions import ScoGenError, ScoValueError
import sco_version import sco_version
PAGE_HEIGHT = defaultPageSize[1] 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 if m.group(1): # non empty paragraph
r.append(para) r.append(para)
paras = r 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: except OSError as e:
msg = str(e) msg = str(e)
# If a file is missing, try to display the invalid name # If a file is missing, try to display the invalid name