From 6082f1dbd9f9adcd5fc4e60e682eb12a7d36254a Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 6 Sep 2022 13:47:37 +0200 Subject: [PATCH] Message erreur si signature pdf invalide --- app/scodoc/sco_pvpdf.py | 22 ++++++++++++++++------ sco_version.py | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/scodoc/sco_pvpdf.py b/app/scodoc/sco_pvpdf.py index e086ee9922..39056469c4 100644 --- a/app/scodoc/sco_pvpdf.py +++ b/app/scodoc/sco_pvpdf.py @@ -31,6 +31,7 @@ import io import re from PIL import Image as PILImage +from PIL import UnidentifiedImageError import reportlab from reportlab.lib.units import cm, mm @@ -51,6 +52,7 @@ from app.scodoc import sco_codes_parcours from app.scodoc import sco_etud from app.scodoc import sco_pdf from app.scodoc import sco_preferences +from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_logos import find_logo from app.scodoc.sco_cursus_dut import SituationEtudCursus from app.scodoc.sco_pdf import SU @@ -416,9 +418,14 @@ def pdf_lettres_individuelles( etud: Identite = Identite.query.get(decision["identite"]["etudid"]) params["nomEtud"] = etud.nomprenom bookmarks[npages + 1] = scu.suppress_accents(etud.nomprenom) - objects += pdf_lettre_individuelle( - dpv["formsemestre"], decision, etud, params, signature - ) + try: + objects += pdf_lettre_individuelle( + dpv["formsemestre"], decision, etud, params, signature + ) + except UnidentifiedImageError as exc: + raise ScoValueError( + "Fichier image (signature ou logo ?) invalide !" + ) from exc objects.append(PageBreak()) npages += 1 if npages == 0: @@ -606,9 +613,12 @@ def pdf_lettre_individuelle(sem, decision, etud: Identite, params, signature=Non ) if signature: - objects.append( - _make_signature_image(signature, params["htab1"], formsemestre_id) - ) + try: + objects.append( + _make_signature_image(signature, params["htab1"], formsemestre_id) + ) + except UnidentifiedImageError as exc: + raise ScoValueError("Image signature invalide !") from exc return objects diff --git a/sco_version.py b/sco_version.py index 88cf2c366b..8a5130f846 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.3.33" +SCOVERSION = "9.3.34" SCONAME = "ScoDoc"