forked from ScoDoc/DocScoDoc
Bulletins PDF: nouvelle gestion des bookmarks et filigranes
This commit is contained in:
parent
55c4f2c799
commit
0c1c6de7bc
@ -154,10 +154,13 @@ class BulletinGenerator:
|
||||
from app.scodoc import sco_preferences
|
||||
|
||||
formsemestre_id = self.infos["formsemestre_id"]
|
||||
marque_debut_bulletin = sco_pdf.DebutBulletin(
|
||||
self.infos["etud"]["nomprenom"], filigranne=self.infos["filigranne"]
|
||||
)
|
||||
objects = []
|
||||
# partie haute du bulletin
|
||||
objects += self.bul_title_pdf() # pylint: disable=no-member
|
||||
objects += [sco_pdf.DebutBulletin(self.infos["etud"]["nomprenom"])]
|
||||
index_obj_debut = len(objects)
|
||||
|
||||
# table des notes
|
||||
objects += self.bul_table(format="pdf") # pylint: disable=no-member
|
||||
@ -165,10 +168,12 @@ class BulletinGenerator:
|
||||
objects += self.bul_part_below(format="pdf") # pylint: disable=no-member
|
||||
# signatures
|
||||
objects += self.bul_signatures_pdf() # pylint: disable=no-member
|
||||
|
||||
if self.scale_table_in_page:
|
||||
# Réduit sur une page
|
||||
objects = [KeepInFrame(0, 0, objects, mode="shrink")]
|
||||
objects = [marque_debut_bulletin, KeepInFrame(0, 0, objects, mode="shrink")]
|
||||
else:
|
||||
# Insere notre marqueur qui permet de générer les bookmarks et filigrannes:
|
||||
objects.insert(index_obj_debut, marque_debut_bulletin)
|
||||
#
|
||||
# objects.append(sco_pdf.FinBulletin())
|
||||
if not stand_alone:
|
||||
|
@ -77,7 +77,7 @@ def assemble_bulletins_pdf(
|
||||
story: list,
|
||||
bul_title: str,
|
||||
infos,
|
||||
pagesbookmarks,
|
||||
pagesbookmarks=None,
|
||||
filigranne=None,
|
||||
server_name="",
|
||||
):
|
||||
@ -106,8 +106,7 @@ def assemble_bulletins_pdf(
|
||||
preferences=sco_preferences.SemPreferences(formsemestre_id),
|
||||
)
|
||||
)
|
||||
document.build(story)
|
||||
# document.multiBuild(story)
|
||||
document.multiBuild(story)
|
||||
data = report.getvalue()
|
||||
return data
|
||||
|
||||
@ -173,7 +172,7 @@ def process_field(field, cdict, style, suppress_empty_pars=False, format="pdf"):
|
||||
|
||||
|
||||
def get_formsemestre_bulletins_pdf(formsemestre_id, version="selectedevals"):
|
||||
"document pdf et filename"
|
||||
"Document pdf avec tous les bulletins du semestre, et filename"
|
||||
from app.scodoc import sco_bulletins
|
||||
|
||||
cached = sco_cache.SemBulletinsPDFCache.get(str(formsemestre_id) + "_" + version)
|
||||
@ -182,20 +181,14 @@ def get_formsemestre_bulletins_pdf(formsemestre_id, version="selectedevals"):
|
||||
fragments = []
|
||||
# Make each bulletin
|
||||
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
||||
bookmarks = {}
|
||||
filigrannes = {}
|
||||
i = 1
|
||||
for etud in formsemestre.get_inscrits(include_demdef=True, order=True):
|
||||
frag, filigranne = sco_bulletins.do_formsemestre_bulletinetud(
|
||||
frag, _ = sco_bulletins.do_formsemestre_bulletinetud(
|
||||
formsemestre,
|
||||
etud.id,
|
||||
format="pdfpart",
|
||||
version=version,
|
||||
)
|
||||
fragments += frag
|
||||
filigrannes[i] = filigranne
|
||||
bookmarks[i] = etud.sex_nom(no_accents=True)
|
||||
i = i + 1
|
||||
#
|
||||
infos = {"DeptName": sco_preferences.get_preference("DeptName", formsemestre_id)}
|
||||
if request:
|
||||
@ -209,15 +202,13 @@ def get_formsemestre_bulletins_pdf(formsemestre_id, version="selectedevals"):
|
||||
fragments,
|
||||
formsemestre.titre_mois(),
|
||||
infos,
|
||||
bookmarks,
|
||||
filigranne=filigrannes,
|
||||
server_name=server_name,
|
||||
)
|
||||
finally:
|
||||
sco_pdf.PDFLOCK.release()
|
||||
#
|
||||
dt = time.strftime("%Y-%m-%d")
|
||||
filename = "bul-%s-%s.pdf" % (formsemestre.titre_num(), dt)
|
||||
date_iso = time.strftime("%Y-%m-%d")
|
||||
filename = "bul-%s-%s.pdf" % (formsemestre.titre_num(), date_iso)
|
||||
filename = scu.unescape_html(filename).replace(" ", "_").replace("&", "")
|
||||
# fill cache
|
||||
sco_cache.SemBulletinsPDFCache.set(
|
||||
|
@ -112,8 +112,9 @@ class ScoNonEmptyFormationObject(ScoValueError):
|
||||
|
||||
|
||||
class ScoInvalidIdType(ScoValueError):
|
||||
"""Pour les clients qui s'obstinnent à utiliser des bookmarks ou
|
||||
historiques anciens avec des ID ScoDoc7"""
|
||||
"""Pour les clients qui s'obstinent à utiliser des bookmarks
|
||||
ou historiques anciens avec des ID ScoDoc7.
|
||||
"""
|
||||
|
||||
def __init__(self, msg=""):
|
||||
import app.scodoc.sco_utils as scu
|
||||
|
@ -190,8 +190,9 @@ class DebutBulletin(BulMarker):
|
||||
Element vide utilisé pour générer les bookmarks
|
||||
"""
|
||||
|
||||
def __init__(self, bookmark=None):
|
||||
def __init__(self, bookmark=None, filigranne=None):
|
||||
self.bookmark = bookmark
|
||||
self.filigranne = filigranne
|
||||
super().__init__()
|
||||
|
||||
|
||||
@ -212,19 +213,17 @@ class ScoDocPageTemplate(PageTemplate):
|
||||
preferences=None, # dictionnary with preferences, required
|
||||
):
|
||||
"""Initialise our page template."""
|
||||
from app.scodoc.sco_logos import (
|
||||
find_logo,
|
||||
) # defered import (solve circular dependency ->sco_logo ->scodoc, ->sco_pdf
|
||||
# defered import (solve circular dependency ->sco_logo ->scodoc, ->sco_pdf
|
||||
from app.scodoc.sco_logos import find_logo
|
||||
|
||||
self.preferences = preferences
|
||||
self.pagesbookmarks = pagesbookmarks
|
||||
self.pagesbookmarks = pagesbookmarks or {}
|
||||
self.pdfmeta_author = author
|
||||
self.pdfmeta_title = title
|
||||
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"]
|
||||
@ -294,16 +293,11 @@ class ScoDocPageTemplate(PageTemplate):
|
||||
canvas.setTitle(SU(self.pdfmeta_title))
|
||||
if self.pdfmeta_subject:
|
||||
canvas.setSubject(SU(self.pdfmeta_subject))
|
||||
# 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)
|
||||
|
||||
bookmark = self.pagesbookmarks.get(doc.page, None)
|
||||
if bookmark:
|
||||
canvas.bookmarkPage(bookmark)
|
||||
canvas.addOutlineEntry(SU(bookmark), bookmark)
|
||||
# ---- Footer
|
||||
canvas.setFont(
|
||||
self.preferences["SCOLAR_FONT"], self.preferences["SCOLAR_FONT_SIZE_FOOT"]
|
||||
@ -323,7 +317,11 @@ class ScoDocPageTemplate(PageTemplate):
|
||||
if not self.preferences:
|
||||
return
|
||||
# ---- Filigranne (texte en diagonal en haut a gauche de chaque page)
|
||||
if self.filigranne:
|
||||
filigranne = None
|
||||
if hasattr(doc, "filigranne"):
|
||||
# filigranne crée par DebutBulletin
|
||||
filigranne = doc.filigranne
|
||||
if not filigranne and self.filigranne:
|
||||
if isinstance(self.filigranne, str):
|
||||
filigranne = self.filigranne # same for all pages
|
||||
else:
|
||||
@ -336,13 +334,13 @@ class ScoDocPageTemplate(PageTemplate):
|
||||
canvas.setFillColorRGB(1.0, 0.65, 0.65, alpha=0.6)
|
||||
canvas.drawRightString(0, 0, SU(filigranne))
|
||||
canvas.restoreState()
|
||||
doc.filigranne = None
|
||||
|
||||
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):
|
||||
@ -359,6 +357,8 @@ class BulletinDocTemplate(BaseDocTemplate):
|
||||
self.canv.addOutlineEntry(
|
||||
SU(flowable.bookmark), flowable.bookmark, level=0, closed=None
|
||||
)
|
||||
if flowable.filigranne:
|
||||
self.filigranne = flowable.filigranne
|
||||
# log(f"afterFlowable addOutlineEntry {flowable.bookmark} page {self.page}")
|
||||
|
||||
|
||||
|
@ -294,7 +294,7 @@ div.logo-logo {
|
||||
div.logo-logo img {
|
||||
box-sizing: content-box;
|
||||
margin-top: 10px; /* -10px */
|
||||
width: 135px; /* 128px */
|
||||
width: 80px; /* adapter suivant image */
|
||||
padding-right: 5px;
|
||||
}
|
||||
div.sidebar-bottom {
|
||||
|
@ -7,7 +7,7 @@
|
||||
{% if not is_apc %}
|
||||
<h2><a class="discretelink" href="{{
|
||||
url_for(
|
||||
"scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etudid,
|
||||
"scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etud.id,
|
||||
)}}">{{etud.nomprenom}}</a></h2>
|
||||
{% endif %}
|
||||
<form name="f" method="GET" action="{{request.base_url}}">
|
||||
|
Loading…
Reference in New Issue
Block a user