forked from ScoDoc/ScoDoc
introducing ScoPDFFormatError for friendlier PDF errors
This commit is contained in:
parent
55bd15a67b
commit
b6cedbd6b6
@ -58,7 +58,7 @@ from app.scodoc import sco_utils as scu
|
||||
from app.scodoc import sco_excel
|
||||
from app.scodoc import sco_pdf
|
||||
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 import log
|
||||
|
||||
@ -551,7 +551,7 @@ class GenTable(object):
|
||||
[Paragraph(SU(str(x)), CellStyle) for x in line] for line in data_list
|
||||
]
|
||||
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
|
||||
T = Table(Pt, repeatRows=1, colWidths=self.pdf_col_widths, style=pdf_style_list)
|
||||
|
||||
|
@ -60,6 +60,21 @@ class ScoFormatError(ScoValueError):
|
||||
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):
|
||||
"""departement invalide"""
|
||||
|
||||
|
@ -815,7 +815,7 @@ def tab_absences_html(groups_infos, etat=None):
|
||||
% (groups_infos.base_url, groups_infos.groups_titles),
|
||||
"""<li><a class="stdlink" href="trombino?%s&format=pdf">Trombinoscope en PDF</a></li>"""
|
||||
% 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,
|
||||
"""<li><a class="stdlink" href="pdf_feuille_releve_absences?%s&format=pdf">Feuille relevé absences hebdomadaire (beta)</a></li>"""
|
||||
% groups_infos.groups_query_args,
|
||||
|
@ -762,7 +762,7 @@ class BasePreferences(object):
|
||||
{
|
||||
"initvalue": "Helvetica",
|
||||
"title": "Police de caractère principale",
|
||||
"explanation": "pour les pdf",
|
||||
"explanation": "pour les pdf (Helvetica est recommandée)",
|
||||
"size": 25,
|
||||
"category": "pdf",
|
||||
},
|
||||
|
@ -44,6 +44,7 @@ from app.scodoc import sco_groups_view
|
||||
from app.scodoc import sco_preferences
|
||||
from app.scodoc import sco_trombino
|
||||
from app.scodoc import sco_etud
|
||||
from app.scodoc.sco_exceptions import ScoPDFFormatError
|
||||
from app.scodoc.sco_pdf import *
|
||||
|
||||
|
||||
@ -268,7 +269,10 @@ def pdf_trombino_tours(
|
||||
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()
|
||||
|
||||
return scu.sendPDFFile(data, filename)
|
||||
|
Loading…
Reference in New Issue
Block a user