From 8ef265baab8346d40a01e6bd80038c006de572e6 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 13 Mar 2022 23:00:50 +0100 Subject: [PATCH] Bul. PDF: pied de page --- app/scodoc/sco_bulletins_generator.py | 4 +++- app/scodoc/sco_config.py | 4 +++- app/scodoc/sco_pdf.py | 27 ++++++++++++++++++++------- app/views/scodoc.py | 2 +- tools/scodoc_config.py | 4 +++- tools/scodoc_config_tmpl.py | 2 +- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/scodoc/sco_bulletins_generator.py b/app/scodoc/sco_bulletins_generator.py index 50c1c0b4..d3193ade 100644 --- a/app/scodoc/sco_bulletins_generator.py +++ b/app/scodoc/sco_bulletins_generator.py @@ -163,7 +163,9 @@ class BulletinGenerator: formsemestre_id = self.infos["formsemestre_id"] marque_debut_bulletin = sco_pdf.DebutBulletin( - self.infos["etud"]["nomprenom"], filigranne=self.infos["filigranne"] + self.infos["etud"]["nomprenom"], + filigranne=self.infos["filigranne"], + footer_content=f"""ScoDoc - Bulletin de {self.infos["etud"]["nomprenom"]} - {time.strftime("%d/%m/%Y %H:%M")}""", ) story = [] # partie haute du bulletin diff --git a/app/scodoc/sco_config.py b/app/scodoc/sco_config.py index dd69b971..95b9dcc9 100644 --- a/app/scodoc/sco_config.py +++ b/app/scodoc/sco_config.py @@ -46,7 +46,9 @@ CONFIG.LOGO_HEADER_HEIGHT = 28 # # server_url: URL du serveur ScoDoc # scodoc_name: le nom du logiciel (ScoDoc actuellement, voir sco_version.py) -CONFIG.DEFAULT_PDF_FOOTER_TEMPLATE = "Edité par %(scodoc_name)s le %(day)s/%(month)s/%(year)s à %(hour)sh%(minute)s sur %(server_url)s" +CONFIG.DEFAULT_PDF_FOOTER_TEMPLATE = ( + "Edité par %(scodoc_name)s le %(day)s/%(month)s/%(year)s à %(hour)sh%(minute)s" +) # ------------- Capitalisation des UEs ------------- diff --git a/app/scodoc/sco_pdf.py b/app/scodoc/sco_pdf.py index 1ff79709..19a77814 100755 --- a/app/scodoc/sco_pdf.py +++ b/app/scodoc/sco_pdf.py @@ -190,9 +190,10 @@ class DebutBulletin(BulMarker): Element vide utilisé pour générer les bookmarks """ - def __init__(self, bookmark=None, filigranne=None): + def __init__(self, bookmark=None, filigranne=None, footer_content=None): self.bookmark = bookmark self.filigranne = filigranne + self.footer_content = footer_content super().__init__() @@ -298,24 +299,34 @@ class ScoDocPageTemplate(PageTemplate): if bookmark: canvas.bookmarkPage(bookmark) canvas.addOutlineEntry(SU(bookmark), bookmark) - # ---- Footer + + def draw_footer(self, canvas, content): + """Print the footer""" canvas.setFont( self.preferences["SCOLAR_FONT"], self.preferences["SCOLAR_FONT_SIZE_FOOT"] ) - d = _makeTimeDict() - d["scodoc_name"] = sco_version.SCONAME - d["server_url"] = self.server_name - footer_str = SU(self.footer_template % d) canvas.drawString( self.preferences["pdf_footer_x"] * mm, self.preferences["pdf_footer_y"] * mm, - footer_str, + content, ) canvas.restoreState() + def footer_string(self) -> str: + """String contenu du pied de page""" + d = _makeTimeDict() + d["scodoc_name"] = sco_version.SCONAME + d["server_url"] = self.server_name + return SU(self.footer_template % d) + def afterDrawPage(self, canvas, doc): if not self.preferences: return + # ---- Footer + foot_content = None + if hasattr(doc, "current_footer"): + foot_content = doc.current_footer + self.draw_footer(canvas, foot_content or self.footer_string()) # ---- Filigranne (texte en diagonal en haut a gauche de chaque page) filigranne = None if hasattr(doc, "filigranne"): @@ -352,7 +363,9 @@ class BulletinDocTemplate(BaseDocTemplate): def afterFlowable(self, flowable): """Called by Reportlab after each flowable""" if isinstance(flowable, DebutBulletin): + self.current_footer = "" if flowable.bookmark: + self.current_footer = flowable.footer_content self.canv.bookmarkPage(flowable.bookmark) self.canv.addOutlineEntry( SU(flowable.bookmark), flowable.bookmark, level=0, closed=None diff --git a/app/views/scodoc.py b/app/views/scodoc.py index d1c842dd..3dc07fea 100644 --- a/app/views/scodoc.py +++ b/app/views/scodoc.py @@ -248,7 +248,7 @@ def about(scodoc_dept=None): # INSTITUTION_ADDRESS = "Web www.sor.bonne.top - 11, rue Simon Crubelier - 75017 Paris" # INSTITUTION_CITY = "Paris" # Textareas: -# DEFAULT_PDF_FOOTER_TEMPLATE = "Edité par %(scodoc_name)s le %(day)s/%(month)s/%(year)s à %(hour)sh%(minute)s sur %(server_url)s" +# DEFAULT_PDF_FOOTER_TEMPLATE = "Edité par %(scodoc_name)s le %(day)s/%(month)s/%(year)s à %(hour)sh%(minute)s" # Booléens # always_require_ine diff --git a/tools/scodoc_config.py b/tools/scodoc_config.py index 2937dfd4..eca69468 100644 --- a/tools/scodoc_config.py +++ b/tools/scodoc_config.py @@ -63,7 +63,9 @@ CONFIG.LOGO_HEADER_HEIGHT = 28 # taille verticale dans le document en millimetr # server_url: URL du serveur ScoDoc # scodoc_name: le nom du logiciel (ScoDoc actuellement, voir sco_version.py) -CONFIG.DEFAULT_PDF_FOOTER_TEMPLATE = "Edité par %(scodoc_name)s le %(day)s/%(month)s/%(year)s à %(hour)sh%(minute)s sur %(server_url)s" +CONFIG.DEFAULT_PDF_FOOTER_TEMPLATE = ( + "Edité par %(scodoc_name)s le %(day)s/%(month)s/%(year)s à %(hour)sh%(minute)s" +) # diff --git a/tools/scodoc_config_tmpl.py b/tools/scodoc_config_tmpl.py index 84c5e0d6..8b06f51a 100644 --- a/tools/scodoc_config_tmpl.py +++ b/tools/scodoc_config_tmpl.py @@ -55,7 +55,7 @@ CONFIG = CFG() # server_url: URL du serveur ScoDoc # scodoc_name: le nom du logiciel (ScoDoc actuellement, voir sco_version.py) -# CONFIG.DEFAULT_PDF_FOOTER_TEMPLATE = "Edité par %(scodoc_name)s le %(day)s/%(month)s/%(year)s à %(hour)sh%(minute)s sur %(server_url)s" +# CONFIG.DEFAULT_PDF_FOOTER_TEMPLATE = "Edité par %(scodoc_name)s le %(day)s/%(month)s/%(year)s à %(hour)sh%(minute)s" #