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
|
from app.scodoc import sco_preferences
|
||||||
|
|
||||||
formsemestre_id = self.infos["formsemestre_id"]
|
formsemestre_id = self.infos["formsemestre_id"]
|
||||||
|
marque_debut_bulletin = sco_pdf.DebutBulletin(
|
||||||
|
self.infos["etud"]["nomprenom"], filigranne=self.infos["filigranne"]
|
||||||
|
)
|
||||||
objects = []
|
objects = []
|
||||||
# partie haute du bulletin
|
# partie haute du bulletin
|
||||||
objects += self.bul_title_pdf() # pylint: disable=no-member
|
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
|
# table des notes
|
||||||
objects += self.bul_table(format="pdf") # pylint: disable=no-member
|
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
|
objects += self.bul_part_below(format="pdf") # pylint: disable=no-member
|
||||||
# signatures
|
# signatures
|
||||||
objects += self.bul_signatures_pdf() # pylint: disable=no-member
|
objects += self.bul_signatures_pdf() # pylint: disable=no-member
|
||||||
|
|
||||||
if self.scale_table_in_page:
|
if self.scale_table_in_page:
|
||||||
# Réduit sur une 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())
|
# objects.append(sco_pdf.FinBulletin())
|
||||||
if not stand_alone:
|
if not stand_alone:
|
||||||
|
@ -77,7 +77,7 @@ def assemble_bulletins_pdf(
|
|||||||
story: list,
|
story: list,
|
||||||
bul_title: str,
|
bul_title: str,
|
||||||
infos,
|
infos,
|
||||||
pagesbookmarks,
|
pagesbookmarks=None,
|
||||||
filigranne=None,
|
filigranne=None,
|
||||||
server_name="",
|
server_name="",
|
||||||
):
|
):
|
||||||
@ -106,8 +106,7 @@ def assemble_bulletins_pdf(
|
|||||||
preferences=sco_preferences.SemPreferences(formsemestre_id),
|
preferences=sco_preferences.SemPreferences(formsemestre_id),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
document.build(story)
|
document.multiBuild(story)
|
||||||
# document.multiBuild(story)
|
|
||||||
data = report.getvalue()
|
data = report.getvalue()
|
||||||
return data
|
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"):
|
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
|
from app.scodoc import sco_bulletins
|
||||||
|
|
||||||
cached = sco_cache.SemBulletinsPDFCache.get(str(formsemestre_id) + "_" + version)
|
cached = sco_cache.SemBulletinsPDFCache.get(str(formsemestre_id) + "_" + version)
|
||||||
@ -182,20 +181,14 @@ def get_formsemestre_bulletins_pdf(formsemestre_id, version="selectedevals"):
|
|||||||
fragments = []
|
fragments = []
|
||||||
# Make each bulletin
|
# Make each bulletin
|
||||||
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
||||||
bookmarks = {}
|
|
||||||
filigrannes = {}
|
|
||||||
i = 1
|
|
||||||
for etud in formsemestre.get_inscrits(include_demdef=True, order=True):
|
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,
|
formsemestre,
|
||||||
etud.id,
|
etud.id,
|
||||||
format="pdfpart",
|
format="pdfpart",
|
||||||
version=version,
|
version=version,
|
||||||
)
|
)
|
||||||
fragments += frag
|
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)}
|
infos = {"DeptName": sco_preferences.get_preference("DeptName", formsemestre_id)}
|
||||||
if request:
|
if request:
|
||||||
@ -209,15 +202,13 @@ def get_formsemestre_bulletins_pdf(formsemestre_id, version="selectedevals"):
|
|||||||
fragments,
|
fragments,
|
||||||
formsemestre.titre_mois(),
|
formsemestre.titre_mois(),
|
||||||
infos,
|
infos,
|
||||||
bookmarks,
|
|
||||||
filigranne=filigrannes,
|
|
||||||
server_name=server_name,
|
server_name=server_name,
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
sco_pdf.PDFLOCK.release()
|
sco_pdf.PDFLOCK.release()
|
||||||
#
|
#
|
||||||
dt = time.strftime("%Y-%m-%d")
|
date_iso = time.strftime("%Y-%m-%d")
|
||||||
filename = "bul-%s-%s.pdf" % (formsemestre.titre_num(), dt)
|
filename = "bul-%s-%s.pdf" % (formsemestre.titre_num(), date_iso)
|
||||||
filename = scu.unescape_html(filename).replace(" ", "_").replace("&", "")
|
filename = scu.unescape_html(filename).replace(" ", "_").replace("&", "")
|
||||||
# fill cache
|
# fill cache
|
||||||
sco_cache.SemBulletinsPDFCache.set(
|
sco_cache.SemBulletinsPDFCache.set(
|
||||||
|
@ -112,8 +112,9 @@ class ScoNonEmptyFormationObject(ScoValueError):
|
|||||||
|
|
||||||
|
|
||||||
class ScoInvalidIdType(ScoValueError):
|
class ScoInvalidIdType(ScoValueError):
|
||||||
"""Pour les clients qui s'obstinnent à utiliser des bookmarks ou
|
"""Pour les clients qui s'obstinent à utiliser des bookmarks
|
||||||
historiques anciens avec des ID ScoDoc7"""
|
ou historiques anciens avec des ID ScoDoc7.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, msg=""):
|
def __init__(self, msg=""):
|
||||||
import app.scodoc.sco_utils as scu
|
import app.scodoc.sco_utils as scu
|
||||||
|
@ -190,8 +190,9 @@ class DebutBulletin(BulMarker):
|
|||||||
Element vide utilisé pour générer les bookmarks
|
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.bookmark = bookmark
|
||||||
|
self.filigranne = filigranne
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|
||||||
@ -212,19 +213,17 @@ class ScoDocPageTemplate(PageTemplate):
|
|||||||
preferences=None, # dictionnary with preferences, required
|
preferences=None, # dictionnary with preferences, required
|
||||||
):
|
):
|
||||||
"""Initialise our page template."""
|
"""Initialise our page template."""
|
||||||
from app.scodoc.sco_logos import (
|
# defered import (solve circular dependency ->sco_logo ->scodoc, ->sco_pdf
|
||||||
find_logo,
|
from app.scodoc.sco_logos import find_logo
|
||||||
) # defered import (solve circular dependency ->sco_logo ->scodoc, ->sco_pdf
|
|
||||||
|
|
||||||
self.preferences = preferences
|
self.preferences = preferences
|
||||||
self.pagesbookmarks = pagesbookmarks
|
self.pagesbookmarks = pagesbookmarks or {}
|
||||||
self.pdfmeta_author = author
|
self.pdfmeta_author = author
|
||||||
self.pdfmeta_title = title
|
self.pdfmeta_title = title
|
||||||
self.pdfmeta_subject = subject
|
self.pdfmeta_subject = subject
|
||||||
self.server_name = server_name
|
self.server_name = server_name
|
||||||
self.filigranne = filigranne
|
self.filigranne = filigranne
|
||||||
self.page_number = 1
|
self.page_number = 1
|
||||||
self.current_page_bookmark = None
|
|
||||||
self.footer_template = footer_template
|
self.footer_template = footer_template
|
||||||
if self.preferences:
|
if self.preferences:
|
||||||
self.with_page_background = self.preferences["bul_pdf_with_background"]
|
self.with_page_background = self.preferences["bul_pdf_with_background"]
|
||||||
@ -294,16 +293,11 @@ class ScoDocPageTemplate(PageTemplate):
|
|||||||
canvas.setTitle(SU(self.pdfmeta_title))
|
canvas.setTitle(SU(self.pdfmeta_title))
|
||||||
if self.pdfmeta_subject:
|
if self.pdfmeta_subject:
|
||||||
canvas.setSubject(SU(self.pdfmeta_subject))
|
canvas.setSubject(SU(self.pdfmeta_subject))
|
||||||
# if self.current_page_bookmark:
|
|
||||||
# canvas.bookmarkPage(self.current_page_bookmark)
|
bookmark = self.pagesbookmarks.get(doc.page, None)
|
||||||
# canvas.addOutlineEntry(
|
if bookmark:
|
||||||
# SU(self.current_page_bookmark), self.current_page_bookmark
|
canvas.bookmarkPage(bookmark)
|
||||||
# )
|
canvas.addOutlineEntry(SU(bookmark), bookmark)
|
||||||
# else: XXX A REMETTRE
|
|
||||||
# bookmark = self.pagesbookmarks.get(doc.page, None)
|
|
||||||
# if bookmark != None:
|
|
||||||
# canvas.bookmarkPage(bookmark)
|
|
||||||
# canvas.addOutlineEntry(SU(bookmark), bookmark)
|
|
||||||
# ---- Footer
|
# ---- Footer
|
||||||
canvas.setFont(
|
canvas.setFont(
|
||||||
self.preferences["SCOLAR_FONT"], self.preferences["SCOLAR_FONT_SIZE_FOOT"]
|
self.preferences["SCOLAR_FONT"], self.preferences["SCOLAR_FONT_SIZE_FOOT"]
|
||||||
@ -323,26 +317,30 @@ class ScoDocPageTemplate(PageTemplate):
|
|||||||
if not self.preferences:
|
if not self.preferences:
|
||||||
return
|
return
|
||||||
# ---- Filigranne (texte en diagonal en haut a gauche de chaque page)
|
# ---- 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):
|
if isinstance(self.filigranne, str):
|
||||||
filigranne = self.filigranne # same for all pages
|
filigranne = self.filigranne # same for all pages
|
||||||
else:
|
else:
|
||||||
filigranne = self.filigranne.get(doc.page, None)
|
filigranne = self.filigranne.get(doc.page, None)
|
||||||
if filigranne:
|
if filigranne:
|
||||||
canvas.saveState()
|
canvas.saveState()
|
||||||
canvas.translate(9 * cm, 27.6 * cm)
|
canvas.translate(9 * cm, 27.6 * cm)
|
||||||
canvas.rotate(30)
|
canvas.rotate(30)
|
||||||
canvas.scale(4.5, 4.5)
|
canvas.scale(4.5, 4.5)
|
||||||
canvas.setFillColorRGB(1.0, 0.65, 0.65, alpha=0.6)
|
canvas.setFillColorRGB(1.0, 0.65, 0.65, alpha=0.6)
|
||||||
canvas.drawRightString(0, 0, SU(filigranne))
|
canvas.drawRightString(0, 0, SU(filigranne))
|
||||||
canvas.restoreState()
|
canvas.restoreState()
|
||||||
|
doc.filigranne = None
|
||||||
|
|
||||||
def afterPage(self):
|
def afterPage(self):
|
||||||
"""Called after all flowables have been drawn on a page.
|
"""Called after all flowables have been drawn on a page.
|
||||||
Increment pageNum since the page has been completed.
|
Increment pageNum since the page has been completed.
|
||||||
"""
|
"""
|
||||||
self.page_number += 1
|
self.page_number += 1
|
||||||
self.current_page_bookmark = None
|
|
||||||
|
|
||||||
|
|
||||||
class BulletinDocTemplate(BaseDocTemplate):
|
class BulletinDocTemplate(BaseDocTemplate):
|
||||||
@ -359,6 +357,8 @@ class BulletinDocTemplate(BaseDocTemplate):
|
|||||||
self.canv.addOutlineEntry(
|
self.canv.addOutlineEntry(
|
||||||
SU(flowable.bookmark), flowable.bookmark, level=0, closed=None
|
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}")
|
# log(f"afterFlowable addOutlineEntry {flowable.bookmark} page {self.page}")
|
||||||
|
|
||||||
|
|
||||||
|
@ -288,13 +288,13 @@ div.logo-insidebar {
|
|||||||
}
|
}
|
||||||
div.logo-logo {
|
div.logo-logo {
|
||||||
margin-left: -5px;
|
margin-left: -5px;
|
||||||
text-align: center ;
|
text-align: center ;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.logo-logo img {
|
div.logo-logo img {
|
||||||
box-sizing: content-box;
|
box-sizing: content-box;
|
||||||
margin-top: 10px; /* -10px */
|
margin-top: 10px; /* -10px */
|
||||||
width: 135px; /* 128px */
|
width: 80px; /* adapter suivant image */
|
||||||
padding-right: 5px;
|
padding-right: 5px;
|
||||||
}
|
}
|
||||||
div.sidebar-bottom {
|
div.sidebar-bottom {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
{% if not is_apc %}
|
{% if not is_apc %}
|
||||||
<h2><a class="discretelink" href="{{
|
<h2><a class="discretelink" href="{{
|
||||||
url_for(
|
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>
|
)}}">{{etud.nomprenom}}</a></h2>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<form name="f" method="GET" action="{{request.base_url}}">
|
<form name="f" method="GET" action="{{request.base_url}}">
|
||||||
|
Loading…
Reference in New Issue
Block a user