introducing ScoPDFFormatError for friendlier PDF errors

This commit is contained in:
Emmanuel Viennet 2022-01-13 22:36:40 +01:00
parent 55bd15a67b
commit b6cedbd6b6
5 changed files with 24 additions and 5 deletions

View File

@ -58,7 +58,7 @@ from app.scodoc import sco_utils as scu
from app.scodoc import sco_excel from app.scodoc import sco_excel
from app.scodoc import sco_pdf from app.scodoc import sco_pdf
from app.scodoc import sco_xml from app.scodoc import sco_xml
from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_exceptions import ScoPDFFormatError
from app.scodoc.sco_pdf import SU from app.scodoc.sco_pdf import SU
from app import log from app import log
@ -551,7 +551,7 @@ class GenTable(object):
[Paragraph(SU(str(x)), CellStyle) for x in line] for line in data_list [Paragraph(SU(str(x)), CellStyle) for x in line] for line in data_list
] ]
except ValueError as exc: except ValueError as exc:
raise ScoValueError(f"Erreur dans un format pdf: <br/>{str(exc)}") from exc raise ScoPDFFormatError(str(exc)) from exc
pdf_style_list += self.pdf_table_style pdf_style_list += self.pdf_table_style
T = Table(Pt, repeatRows=1, colWidths=self.pdf_col_widths, style=pdf_style_list) T = Table(Pt, repeatRows=1, colWidths=self.pdf_col_widths, style=pdf_style_list)

View File

@ -60,6 +60,21 @@ class ScoFormatError(ScoValueError):
pass pass
class ScoPDFFormatError(ScoValueError):
"erreur génération PDF (templates platypus, ...)"
def __init__(self, msg, dest_url=None):
super().__init__(
f"""Erreur dans un format pdf:
<p>{msg}</p>
<p>Vérifiez les paramètres (polices de caractères, balisage)
dans les paramètres ou préférences.
</p>
""",
dest_url=dest_url,
)
class ScoInvalidDept(ScoValueError): class ScoInvalidDept(ScoValueError):
"""departement invalide""" """departement invalide"""

View File

@ -815,7 +815,7 @@ def tab_absences_html(groups_infos, etat=None):
% (groups_infos.base_url, groups_infos.groups_titles), % (groups_infos.base_url, groups_infos.groups_titles),
"""<li><a class="stdlink" href="trombino?%s&format=pdf">Trombinoscope en PDF</a></li>""" """<li><a class="stdlink" href="trombino?%s&format=pdf">Trombinoscope en PDF</a></li>"""
% groups_infos.groups_query_args, % groups_infos.groups_query_args,
"""<li><a class="stdlink" href="pdf_trombino_tours?%s&format=pdf">Trombinoscope en PDF (format "IUT de Tours", beta)</a></li>""" """<li><a class="stdlink" href="pdf_trombino_tours?%s&format=pdf">Trombinoscope en PDF (format "IUT de Tours")</a></li>"""
% groups_infos.groups_query_args, % groups_infos.groups_query_args,
"""<li><a class="stdlink" href="pdf_feuille_releve_absences?%s&format=pdf">Feuille relevé absences hebdomadaire (beta)</a></li>""" """<li><a class="stdlink" href="pdf_feuille_releve_absences?%s&format=pdf">Feuille relevé absences hebdomadaire (beta)</a></li>"""
% groups_infos.groups_query_args, % groups_infos.groups_query_args,

View File

@ -762,7 +762,7 @@ class BasePreferences(object):
{ {
"initvalue": "Helvetica", "initvalue": "Helvetica",
"title": "Police de caractère principale", "title": "Police de caractère principale",
"explanation": "pour les pdf", "explanation": "pour les pdf (Helvetica est recommandée)",
"size": 25, "size": 25,
"category": "pdf", "category": "pdf",
}, },

View File

@ -44,6 +44,7 @@ from app.scodoc import sco_groups_view
from app.scodoc import sco_preferences from app.scodoc import sco_preferences
from app.scodoc import sco_trombino from app.scodoc import sco_trombino
from app.scodoc import sco_etud from app.scodoc import sco_etud
from app.scodoc.sco_exceptions import ScoPDFFormatError
from app.scodoc.sco_pdf import * from app.scodoc.sco_pdf import *
@ -268,7 +269,10 @@ def pdf_trombino_tours(
preferences=sco_preferences.SemPreferences(), preferences=sco_preferences.SemPreferences(),
) )
) )
document.build(objects) try:
document.build(objects)
except (ValueError, KeyError) as exc:
raise ScoPDFFormatError(str(exc)) from exc
data = report.getvalue() data = report.getvalue()
return scu.sendPDFFile(data, filename) return scu.sendPDFFile(data, filename)