From e0a3c31f9cb0bd0372f9c9be519b260c1445cdfc Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 13 Mar 2022 22:22:54 +0100 Subject: [PATCH] =?UTF-8?q?Bul.=20BUT=20PDF:=20d=C3=A9buts=20sur=20pages?= =?UTF-8?q?=20impaires?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/but/bulletin_but_pdf.py | 3 ++- app/scodoc/sco_bulletins_generator.py | 39 ++++++++++++++++++--------- app/scodoc/sco_pdf.py | 1 - 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/app/but/bulletin_but_pdf.py b/app/but/bulletin_but_pdf.py index 2bbb5bcc8..4c271acc9 100644 --- a/app/but/bulletin_but_pdf.py +++ b/app/but/bulletin_but_pdf.py @@ -23,7 +23,8 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard): """ list_in_menu = False # spécialisation du BulletinGeneratorStandard, ne pas présenter à l'utilisateur - scale_table_in_page = False + scale_table_in_page = False # pas de mise à l'échelle pleine page auto + multi_pages = True # plusieurs pages par bulletins small_fontsize = "8" def bul_table(self, format="html"): diff --git a/app/scodoc/sco_bulletins_generator.py b/app/scodoc/sco_bulletins_generator.py index 219741b94..50c1c0b4e 100644 --- a/app/scodoc/sco_bulletins_generator.py +++ b/app/scodoc/sco_bulletins_generator.py @@ -49,7 +49,14 @@ import traceback import reportlab -from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Frame, PageBreak +from reportlab.platypus import ( + SimpleDocTemplate, + DocIf, + Paragraph, + Spacer, + Frame, + PageBreak, +) from reportlab.platypus import Table, TableStyle, Image, KeepInFrame from flask import request @@ -72,6 +79,7 @@ class BulletinGenerator: description = "superclass for bulletins" # description for user interface list_in_menu = True # la classe doit-elle est montrée dans le menu de config ? scale_table_in_page = True # rescale la table sur 1 page + multi_pages = False def __init__( self, @@ -157,28 +165,35 @@ class BulletinGenerator: marque_debut_bulletin = sco_pdf.DebutBulletin( self.infos["etud"]["nomprenom"], filigranne=self.infos["filigranne"] ) - objects = [] + story = [] # partie haute du bulletin - objects += self.bul_title_pdf() # pylint: disable=no-member - index_obj_debut = len(objects) + story += self.bul_title_pdf() # pylint: disable=no-member + index_obj_debut = len(story) # table des notes - objects += self.bul_table(format="pdf") # pylint: disable=no-member + story += self.bul_table(format="pdf") # pylint: disable=no-member # infos sous la table - objects += self.bul_part_below(format="pdf") # pylint: disable=no-member + story += self.bul_part_below(format="pdf") # pylint: disable=no-member # signatures - objects += self.bul_signatures_pdf() # pylint: disable=no-member + story += self.bul_signatures_pdf() # pylint: disable=no-member if self.scale_table_in_page: # Réduit sur une page - objects = [marque_debut_bulletin, KeepInFrame(0, 0, objects, mode="shrink")] + story = [marque_debut_bulletin, KeepInFrame(0, 0, story, mode="shrink")] else: # Insere notre marqueur qui permet de générer les bookmarks et filigrannes: - objects.insert(index_obj_debut, marque_debut_bulletin) + story.insert(index_obj_debut, marque_debut_bulletin) # # objects.append(sco_pdf.FinBulletin()) if not stand_alone: - objects.append(PageBreak()) # insert page break at end - return objects + if self.multi_pages: + # Bulletins sur plusieurs page, force début suivant sur page impaire + story.append( + DocIf("doc.page%2 == 1", [PageBreak(), PageBreak()], [PageBreak()]) + ) + else: + story.append(PageBreak()) # insert page break at end + + return story else: # Generation du document PDF sem = sco_formsemestre.get_formsemestre(formsemestre_id) @@ -198,7 +213,7 @@ class BulletinGenerator: preferences=sco_preferences.SemPreferences(formsemestre_id), ) ) - document.build(objects) + document.build(story) data = report.getvalue() return data diff --git a/app/scodoc/sco_pdf.py b/app/scodoc/sco_pdf.py index ac1338aad..1ff797092 100755 --- a/app/scodoc/sco_pdf.py +++ b/app/scodoc/sco_pdf.py @@ -359,7 +359,6 @@ class BulletinDocTemplate(BaseDocTemplate): ) if flowable.filigranne: self.filigranne = flowable.filigranne - # log(f"afterFlowable addOutlineEntry {flowable.bookmark} page {self.page}") def _makeTimeDict():