From f219b8d0034257354b2ff9aced9c786621d5d5ed Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sun, 7 Nov 2021 09:07:51 +0100 Subject: [PATCH] adaptation de code de traitement des templates pdf --- app/scodoc/sco_pdf.py | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/app/scodoc/sco_pdf.py b/app/scodoc/sco_pdf.py index 77e6f4e1b..54ed29b26 100755 --- a/app/scodoc/sco_pdf.py +++ b/app/scodoc/sco_pdf.py @@ -60,11 +60,8 @@ from reportlab.lib.pagesizes import letter, A4, landscape from flask import g import app.scodoc.sco_utils as scu -from app.scodoc.sco_utils import ( - CONFIG, - SCODOC_LOGOS_DIR, - LOGOS_IMAGES_ALLOWED_TYPES, -) +from app.scodoc.sco_logos import find_logo +from app.scodoc.sco_utils import CONFIG from app import log from app.scodoc.sco_exceptions import ScoGenError, ScoValueError import sco_version @@ -219,20 +216,16 @@ class ScolarsPageTemplate(PageTemplate): ) PageTemplate.__init__(self, "ScolarsPageTemplate", [content]) self.logo = None - # XXX COPIED from sco_pvpdf, to be refactored (no time now) - # Search background in dept specific dir, then in global config dir - for image_dir in ( - SCODOC_LOGOS_DIR + "/logos_" + g.scodoc_dept + "/", - SCODOC_LOGOS_DIR + "/", # global logos - ): - for suffix in LOGOS_IMAGES_ALLOWED_TYPES: - fn = image_dir + "/bul_pdf_background" + "." + suffix - if not self.background_image_filename and os.path.exists(fn): - self.background_image_filename = fn - # Also try to use PV background - fn = image_dir + "/letter_background" + "." + suffix - if not self.background_image_filename and os.path.exists(fn): - self.background_image_filename = fn + logo = find_logo( + logoname="bul_pdf_background", dept_id=g.scodoc_dept_id, prefix=None + ) + if logo is None: + # Also try to use PV background + logo = find_logo( + logoname="letter_background", dept_id=g.scodoc_dept_id, prefix=None + ) + if logo is not None: + self.background_image_filename = logo.filepath def beforeDrawPage(self, canvas, doc): """Draws (optional) background, logo and contribution message on each page.