diff --git a/app/but/bulletin_but_pdf.py b/app/but/bulletin_but_pdf.py
index ea3291c8d..2bbb5bcc8 100644
--- a/app/but/bulletin_but_pdf.py
+++ b/app/but/bulletin_but_pdf.py
@@ -24,6 +24,7 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
list_in_menu = False # spécialisation du BulletinGeneratorStandard, ne pas présenter à l'utilisateur
scale_table_in_page = False
+ small_fontsize = "8"
def bul_table(self, format="html"):
"""Génère la table centrale du bulletin de notes
@@ -77,16 +78,28 @@ class BulletinGeneratorStandardBUT(BulletinGeneratorStandard):
"coef": 2 * cm,
}
title_bg = tuple(x / 255.0 for x in title_bg)
+ nota_bene = "La moyenne des ressources et SAÉs dans une UE dépend des poids donnés aux évaluations."
# elems pour générer table avec gen_table (liste de dicts)
rows = [
# Ligne de titres
{
"titre": "Unités d'enseignement",
- "moyenne": "Note/20",
+ "moyenne": Paragraph("
@@ -130,7 +130,7 @@ class BulletinGeneratorStandard(sco_bulletins_generator.BulletinGenerator): """ % self.infos ) - Op.append( + story.append( Paragraph( SU( "%(nbabs)s absences (1/2 journées), dont %(nbabsjust)s justifiées." @@ -141,7 +141,7 @@ class BulletinGeneratorStandard(sco_bulletins_generator.BulletinGenerator): ) else: H.append("""
Pas d'absences signalées.
""") - Op.append(Paragraph(SU("Pas d'absences signalées."), self.CellStyle)) + story.append(Paragraph(SU("Pas d'absences signalées."), self.CellStyle)) # ---- APPRECIATIONS # le dir. des etud peut ajouter des appreciations, @@ -168,10 +168,10 @@ class BulletinGeneratorStandard(sco_bulletins_generator.BulletinGenerator): % self.infos ) H.append("") - # Appreciations sur PDF: + # Appréciations sur PDF: if self.infos.get("appreciations_list", False): - Op.append(Spacer(1, 3 * mm)) - Op.append( + story.append(Spacer(1, 3 * mm)) + story.append( Paragraph( SU("Appréciation : " + "\n".join(self.infos["appreciations_txt"])), self.CellStyle, @@ -180,7 +180,7 @@ class BulletinGeneratorStandard(sco_bulletins_generator.BulletinGenerator): # ----- DECISION JURY if self.preferences["bul_show_decision"]: - Op += sco_bulletins_pdf.process_field( + story += sco_bulletins_pdf.process_field( self.preferences["bul_pdf_caption"], self.infos, self.FieldStyle, @@ -196,7 +196,12 @@ class BulletinGeneratorStandard(sco_bulletins_generator.BulletinGenerator): # ----- if format == "pdf": - return [KeepTogether(Op)] + if self.scale_table_in_page: + # le scaling (pour tenir sur une page) semble incompatible avec + # le KeepTogether() + return story + else: + return [KeepTogether(story)] elif format == "html": return "\n".join(H) diff --git a/app/scodoc/sco_pdf.py b/app/scodoc/sco_pdf.py index 3949f50a9..4f674e6c9 100755 --- a/app/scodoc/sco_pdf.py +++ b/app/scodoc/sco_pdf.py @@ -175,7 +175,27 @@ def bold_paras(L, tag="b", close=None): return [b + (x or "") + close for x in L] -class ScolarsPageTemplate(PageTemplate): +class BulMarker(Flowable): + """Custom Flowables pour nos bulletins PDF: invisibles, juste pour se repérer""" + + def wrap(self, *args): + return (0, 0) + + def draw(self): + return + + +class DebutBulletin(BulMarker): + """Début d'un bulletin. + Element vide utilisé pour générer les bookmarks + """ + + def __init__(self, bookmark=None): + self.bookmark = bookmark + super().__init__() + + +class ScoDocPageTemplate(PageTemplate): """Our own page template.""" def __init__( @@ -203,6 +223,8 @@ class ScolarsPageTemplate(PageTemplate): self.pdfmeta_subject = subject self.server_name = server_name self.filigranne = filigranne + self.page_number = 1 + self.current_page_bookmark = None self.footer_template = footer_template if self.preferences: self.with_page_background = self.preferences["bul_pdf_with_background"] @@ -217,7 +239,7 @@ class ScolarsPageTemplate(PageTemplate): document.pagesize[0] - 20.0 * mm - left * mm - right * mm, document.pagesize[1] - 18.0 * mm - top * mm - bottom * mm, ) - PageTemplate.__init__(self, "ScolarsPageTemplate", [content]) + super().__init__("ScoDocPageTemplate", [content]) self.logo = None logo = find_logo( logoname="bul_pdf_background", dept_id=g.scodoc_dept_id @@ -265,21 +287,6 @@ class ScolarsPageTemplate(PageTemplate): ) = self.logo canvas.drawImage(image, inch, doc.pagesize[1] - inch, width, height) - # ---- Filigranne (texte en diagonal en haut a gauche de chaque page) - if self.filigranne: - if isinstance(self.filigranne, str): - filigranne = self.filigranne # same for all pages - else: - filigranne = self.filigranne.get(doc.page, None) - if filigranne: - canvas.saveState() - canvas.translate(9 * cm, 27.6 * cm) - canvas.rotate(30) - canvas.scale(4.5, 4.5) - canvas.setFillColorRGB(1.0, 0.65, 0.65) - canvas.drawRightString(0, 0, SU(filigranne)) - canvas.restoreState() - # ---- Add some meta data and bookmarks if self.pdfmeta_author: canvas.setAuthor(SU(self.pdfmeta_author)) @@ -287,12 +294,16 @@ class ScolarsPageTemplate(PageTemplate): canvas.setTitle(SU(self.pdfmeta_title)) if self.pdfmeta_subject: canvas.setSubject(SU(self.pdfmeta_subject)) - bm = self.pagesbookmarks.get(doc.page, None) - if bm != None: - key = bm - txt = SU(bm) - canvas.bookmarkPage(key) - canvas.addOutlineEntry(txt, bm) + # if self.current_page_bookmark: + # canvas.bookmarkPage(self.current_page_bookmark) + # canvas.addOutlineEntry( + # SU(self.current_page_bookmark), self.current_page_bookmark + # ) + # else: XXX A REMETTRE + # bookmark = self.pagesbookmarks.get(doc.page, None) + # if bookmark != None: + # canvas.bookmarkPage(bookmark) + # canvas.addOutlineEntry(SU(bookmark), bookmark) # ---- Footer canvas.setFont( self.preferences["SCOLAR_FONT"], self.preferences["SCOLAR_FONT_SIZE_FOOT"] @@ -308,6 +319,48 @@ class ScolarsPageTemplate(PageTemplate): ) canvas.restoreState() + def afterDrawPage(self, canvas, doc): + if not self.preferences: + return + # ---- Filigranne (texte en diagonal en haut a gauche de chaque page) + if self.filigranne: + if isinstance(self.filigranne, str): + filigranne = self.filigranne # same for all pages + else: + filigranne = self.filigranne.get(doc.page, None) + if filigranne: + canvas.saveState() + canvas.translate(9 * cm, 27.6 * cm) + canvas.rotate(30) + canvas.scale(4.5, 4.5) + canvas.setFillColorRGB(1.0, 0.65, 0.65, alpha=0.6) + canvas.drawRightString(0, 0, SU(filigranne)) + canvas.restoreState() + + def afterPage(self): + """Called after all flowables have been drawn on a page. + Increment pageNum since the page has been completed. + """ + self.page_number += 1 + self.current_page_bookmark = None + + +class BulletinDocTemplate(BaseDocTemplate): + """Doc template pour les bulletins PDF + ajoute la gestion des bookmarks + """ + + # inspired by https://www.reportlab.com/snippets/13/ + def afterFlowable(self, flowable): + """Called by Reportlab after each flowable""" + if isinstance(flowable, DebutBulletin): + if flowable.bookmark: + self.canv.bookmarkPage(flowable.bookmark) + self.canv.addOutlineEntry( + SU(flowable.bookmark), flowable.bookmark, level=0, closed=None + ) + # log(f"afterFlowable addOutlineEntry {flowable.bookmark} page {self.page}") + def _makeTimeDict(): # ... suboptimal but we don't care @@ -333,7 +386,7 @@ def pdf_basic_page( report = io.BytesIO() # in-memory document, no disk file document = BaseDocTemplate(report) document.addPageTemplates( - ScolarsPageTemplate( + ScoDocPageTemplate( document, title=title, author="%s %s (E. Viennet)" % (sco_version.SCONAME, sco_version.SCOVERSION), diff --git a/app/scodoc/sco_trombino.py b/app/scodoc/sco_trombino.py index 9132336ea..e9102fc67 100644 --- a/app/scodoc/sco_trombino.py +++ b/app/scodoc/sco_trombino.py @@ -378,7 +378,7 @@ def _trombino_pdf(groups_infos): # Build document document = BaseDocTemplate(report) document.addPageTemplates( - sco_pdf.ScolarsPageTemplate( + sco_pdf.ScoDocPageTemplate( document, preferences=sco_preferences.SemPreferences(sem["formsemestre_id"]), ) @@ -458,7 +458,7 @@ def _listeappel_photos_pdf(groups_infos): # Build document document = BaseDocTemplate(report) document.addPageTemplates( - sco_pdf.ScolarsPageTemplate( + sco_pdf.ScoDocPageTemplate( document, preferences=sco_preferences.SemPreferences(sem["formsemestre_id"]), ) diff --git a/app/scodoc/sco_trombino_tours.py b/app/scodoc/sco_trombino_tours.py index 3861bb74f..c1ff7bccc 100644 --- a/app/scodoc/sco_trombino_tours.py +++ b/app/scodoc/sco_trombino_tours.py @@ -264,7 +264,7 @@ def pdf_trombino_tours( filename = "trombino-%s-%s.pdf" % (DeptName, groups_infos.groups_filename) document = BaseDocTemplate(report) document.addPageTemplates( - ScolarsPageTemplate( + ScoDocPageTemplate( document, preferences=sco_preferences.SemPreferences(), ) @@ -460,7 +460,7 @@ def pdf_feuille_releve_absences( else: document = BaseDocTemplate(report, pagesize=taille) document.addPageTemplates( - ScolarsPageTemplate( + ScoDocPageTemplate( document, preferences=sco_preferences.SemPreferences(), )