From 63a18176eaea1a68a57c8fdc6c5780838da18db4 Mon Sep 17 00:00:00 2001 From: viennet Date: Thu, 15 Oct 2020 21:18:51 +0200 Subject: [PATCH] PV jury: fonds de page par departement --- sco_preferences.py | 13 ++++++++- sco_pvpdf.py | 71 +++++++++++++++++++++++----------------------- 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/sco_preferences.py b/sco_preferences.py index f28b0103a..67f06915e 100644 --- a/sco_preferences.py +++ b/sco_preferences.py @@ -779,7 +779,7 @@ vu l'arrêté n° %(Decnum)s du Président de l'%(UnivName)s; vu la délibération de la commission %(Type)s en date du %(Date)s présidée par le Chef du département; """, "title": """Paragraphe d'introduction sur le PV""", - "explanation": """Balises remplacées: %(Univname)s = nom de l'université, %(DecNum)s = numéro de l'arrêté, %(Date)s = date de la commission, %(Type)s = type de commission (passage ou délivrance) """, + "explanation": """Balises remplacées: %(Univname)s = nom de l'université, %(DecNum)s = numéro de l'arrêté, %(Date)s = date de la commission, %(Type)s = type de commission (passage ou délivrance), %(VDICode)s = code diplôme""", "input_type": "textarea", "cols": 80, "rows": 10, @@ -816,6 +816,17 @@ vu la délibération de la commission %(Type)s en date du %(Date)s présidée pa "category": "pvpdf", }, ), + ( + "PV_TITLE_WITH_VDI", + { + "initvalue": 0, # legacy + "title": "Indiquer VDI et code dans le titre du PV", + "explanation": "il est souvent préférable de l'inclure dans le paragraphe d'introduction.", + "input_type": "boolcheckbox", + "labels": ["non", "oui"], + "category": "pvpdf", + }, + ), # marges PV paysages (en millimètres) ( "pv_left_margin", diff --git a/sco_pvpdf.py b/sco_pvpdf.py index f953f8b72..351721fef 100644 --- a/sco_pvpdf.py +++ b/sco_pvpdf.py @@ -138,12 +138,12 @@ class CourrierIndividuelTemplate(PageTemplate): def __init__( self, document, + context=None, pagesbookmarks={}, author=None, title=None, subject=None, margins=(0, 0, 0, 0), # additional margins in mm (left,top,right, bottom) - image_dir="", preferences=None, # dictionnary with preferences, required force_header=False, force_footer=False, # always add a footer (whatever the preferences, use for PV) @@ -154,7 +154,6 @@ class CourrierIndividuelTemplate(PageTemplate): self.pdfmeta_author = author self.pdfmeta_title = title self.pdfmeta_subject = subject - self.image_dir = image_dir self.preferences = preferences self.force_header = force_header self.force_footer = force_footer @@ -187,29 +186,34 @@ class CourrierIndividuelTemplate(PageTemplate): self.background_image_filename = None self.logo_footer = None self.logo_header = None - for suffix in LOGOS_IMAGES_ALLOWED_TYPES: - if template_name == "PVJuryTemplate": - fn = image_dir + "/pvjury_background" + "." + suffix - else: - fn = image_dir + "/letter_background" + "." + suffix - if os.path.exists(fn): - self.background_image_filename = fn + # Search logos in dept specific dir, then in global config dir + for image_dir in ( + SCODOC_LOGOS_DIR + "/logos_" + context.DeptId() + "/", + SCODOC_LOGOS_DIR + "/", # global logos + ): + for suffix in LOGOS_IMAGES_ALLOWED_TYPES: + if template_name == "PVJuryTemplate": + fn = image_dir + "/pvjury_background" + "." + suffix + else: + fn = image_dir + "/letter_background" + "." + suffix + if not self.background_image_filename and os.path.exists(fn): + self.background_image_filename = fn - fn = image_dir + "/logo_footer" + "." + suffix - if os.path.exists(fn): - self.logo_footer = Image( - fn, - height=LOGO_FOOTER_HEIGHT, - width=LOGO_FOOTER_WIDTH, - ) + fn = image_dir + "/logo_footer" + "." + suffix + if not self.logo_footer and os.path.exists(fn): + self.logo_footer = Image( + fn, + height=LOGO_FOOTER_HEIGHT, + width=LOGO_FOOTER_WIDTH, + ) - fn = image_dir + "/logo_header" + "." + suffix - if os.path.exists(fn): - self.logo_header = Image( - fn, - height=LOGO_HEADER_HEIGHT, - width=LOGO_HEADER_WIDTH, - ) + fn = image_dir + "/logo_header" + "." + suffix + if not self.logo_header and os.path.exists(fn): + self.logo_header = Image( + fn, + height=LOGO_HEADER_HEIGHT, + width=LOGO_HEADER_WIDTH, + ) def beforeDrawPage(self, canvas, doc): """Draws a logo and an contribution message on each page.""" @@ -258,11 +262,11 @@ class PVTemplate(CourrierIndividuelTemplate): def __init__( self, document, + context=None, author=None, title=None, subject=None, margins=None, # additional margins in mm (left,top,right, bottom) - image_dir="", preferences=None, # dictionnary with preferences, required ): if margins is None: @@ -275,11 +279,11 @@ class PVTemplate(CourrierIndividuelTemplate): CourrierIndividuelTemplate.__init__( self, document, + context=context, author=author, title=title, subject=subject, margins=margins, - image_dir=image_dir, preferences=preferences, force_header=True, force_footer=True, @@ -369,18 +373,15 @@ def pdf_lettres_individuelles( # ----- Build PDF report = cStringIO.StringIO() # in-memory document, no disk file document = BaseDocTemplate(report) - image_dir = SCODOC_LOGOS_DIR + "/logos_" + context.DeptId() + "/" - if not os.path.exists(image_dir): - image_dir = SCODOC_LOGOS_DIR + "/" # use global logos document.addPageTemplates( CourrierIndividuelTemplate( document, + context=context, author="%s %s (E. Viennet)" % (SCONAME, SCOVERSION), title="Lettres décision %s" % sem["titreannee"], subject="Décision jury", margins=margins, pagesbookmarks=bookmarks, - image_dir=image_dir, preferences=prefs, ) ) @@ -642,16 +643,13 @@ def pvjury_pdf( report = cStringIO.StringIO() # in-memory document, no disk file document = BaseDocTemplate(report) document.pagesize = landscape(A4) - image_dir = SCODOC_LOGOS_DIR + "/logos_" + context.DeptId() + "/" - if not os.path.exists(image_dir): - image_dir = SCODOC_LOGOS_DIR + "/" # use global logos document.addPageTemplates( PVTemplate( document, + context=context, author="%s %s (E. Viennet)" % (SCONAME, SCOVERSION), title=SU("PV du jury de %s" % sem["titre_num"]), subject="PV jury", - image_dir=image_dir, preferences=context.get_preferences(formsemestre_id), ) ) @@ -730,8 +728,11 @@ def _pvjury_pdf_type( objects += makeParas( """Semestre: %s""" % sem["titre"], style ) - if VDICode: - objects += makeParas("""%s""" % VDICode, style) + if context.get_preference("PV_TITLE_WITH_VDI", formsemestre_id): + objects += makeParas( + """VDI et Code: %s""" % (VDICode or ""), style + ) + if date_jury: objects += makeParas( """Jury tenu le %s""" % date_jury, style