Améliore messages erreur bulletins pdf

This commit is contained in:
Emmanuel Viennet 2022-07-09 22:40:46 +02:00
parent d5ff4f79a8
commit 51178795e2
3 changed files with 16 additions and 5 deletions

View File

@ -324,7 +324,7 @@ def dict_decision_jury(etud: Identite, formsemestre: FormSemestre) -> dict:
decisions["decision_rcue"] = [v.to_dict_bul() for v in validations_rcues] decisions["decision_rcue"] = [v.to_dict_bul() for v in validations_rcues]
decisions["descr_decisions_rcue"] = ", ".join( decisions["descr_decisions_rcue"] = ", ".join(
[ [
f"""{dec_rcue["niveau"]["competence"]["titre"]} {dec_rcue["niveau"]["ordre"]}: {dec_rcue["code"]}""" f"""{dec_rcue["niveau"]["competence"]["titre"]} {dec_rcue["niveau"]["ordre"]}: {dec_rcue["code"]}"""
for dec_rcue in decisions["decision_rcue"] for dec_rcue in decisions["decision_rcue"]
] ]
) )

View File

@ -140,6 +140,15 @@ def process_field(field, cdict, style, suppress_empty_pars=False, format="pdf"):
text = (field or "") % scu.WrapDict( text = (field or "") % scu.WrapDict(
cdict cdict
) # note that None values are mapped to empty strings ) # note that None values are mapped to empty strings
except KeyError as exc:
log(
f"""process_field: KeyError on field={field!r}
values={pprint.pformat(cdict)}
"""
)
if len(exc.args) > 0:
missing_field = exc.args[0]
text = f"""<para><i>format invalide: champs</i> {missing_field} <i>inexistant !</i></para>"""
except: # pylint: disable=bare-except except: # pylint: disable=bare-except
log( log(
f"""process_field: invalid format. field={field!r} f"""process_field: invalid format. field={field!r}
@ -148,7 +157,6 @@ def process_field(field, cdict, style, suppress_empty_pars=False, format="pdf"):
) )
# ne sera pas visible si lien vers pdf: # ne sera pas visible si lien vers pdf:
scu.flash_once(f"Attention: format PDF invalide (champs {field}") scu.flash_once(f"Attention: format PDF invalide (champs {field}")
raise ValueError
text = ( text = (
"<para><i>format invalide !</i></para><para>" "<para><i>format invalide !</i></para><para>"
+ traceback.format_exc() + traceback.format_exc()

View File

@ -34,7 +34,7 @@ from PIL import Image as PILImage
import reportlab import reportlab
from reportlab.lib.units import cm, mm from reportlab.lib.units import cm, mm
from reportlab.lib.enums import TA_RIGHT, TA_JUSTIFY from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_JUSTIFY
from reportlab.platypus import Paragraph, Spacer, Frame, PageBreak from reportlab.platypus import Paragraph, Spacer, Frame, PageBreak
from reportlab.platypus import Table, TableStyle, Image from reportlab.platypus import Table, TableStyle, Image
from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate
@ -339,8 +339,11 @@ def _simulate_br(paragraph_txt: str, para="<para>") -> str:
"""Reportlab bug turnaround (could be removed in a future version). """Reportlab bug turnaround (could be removed in a future version).
p is a string with Reportlab intra-paragraph XML tags. p is a string with Reportlab intra-paragraph XML tags.
Replaces <br/> (currently ignored by Reportlab) by </para><para> Replaces <br/> (currently ignored by Reportlab) by </para><para>
Also replaces <br> by <br/>
""" """
return ("</para>" + para).join(re.split(r"<.*?br.*?/>", paragraph_txt)) return ("</para>" + para).join(
re.split(r"<.*?br.*?/>", paragraph_txt.replace("<br>", "<br/>"))
)
def _make_signature_image(signature, leftindent, formsemestre_id) -> Table: def _make_signature_image(signature, leftindent, formsemestre_id) -> Table:
@ -480,7 +483,7 @@ def pdf_lettre_individuelle(sem, decision, etud: Identite, params, signature=Non
style.fontSize = 14 style.fontSize = 14
style.fontName = sco_preferences.get_preference("PV_FONTNAME", formsemestre_id) style.fontName = sco_preferences.get_preference("PV_FONTNAME", formsemestre_id)
style.leading = 18 style.leading = 18
style.alignment = TA_JUSTIFY style.alignment = TA_LEFT
params["semestre_id"] = formsemestre.semestre_id params["semestre_id"] = formsemestre.semestre_id
params["decision_sem_descr"] = decision["decision_sem_descr"] params["decision_sem_descr"] = decision["decision_sem_descr"]