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.
"""
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('<div class="bull_appreciations">')
for app in self.infos["appreciations_list"]:
if can_edit_app:
mlink = (
'<a class="stdlink" href="appreciation_add_form?id=%s">modifier</a> <a class="stdlink" href="appreciation_add_form?id=%s&suppress=1">supprimer</a>'
% (app["id"], app["id"])
)
mlink = f"""<a class="stdlink" href="{
url_for('notes.appreciation_add_form', scodoc_dept=g.scodoc_dept, 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:
mlink = ""
H.append(
'<p><span class="bull_appreciations_date">%s</span>%s<span class="bull_appreciations_link">%s</span></p>'
% (app["date"], app["comment"], mlink)
f"""<p><span class="bull_appreciations_date">{app["date"]}</span>{
app["comment"]}<span class="bull_appreciations_link">{mlink}</span>
</p>"""
)
if can_edit_app:
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
)
H.append("</div>")
# 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"]:

View File

@ -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