. HTML does not allow logos.
"""
try:
# None values are mapped to empty strings by WrapDict
text = (field or "") % WrapDict(cdict)
except KeyError as exc:
missing_key = exc.args[0] if len(exc.args) > 0 else "?"
log(
f"""process_field: KeyError {missing_key} on field={field!r}
values={pprint.pformat(cdict)}
"""
)
text = f""" ", text)
return text
# --- PDF format:
# handle logos:
text = re.sub(
r"<(\s*)logo(.*?)src\s*=\s*(.*?)>", r"<\1logo\2\3>", text
) # remove forbidden src attribute
text = re.sub(
r'(<\s*logo(.*?)name\s*=\s*"(\w*?)"(.*?)/?>)',
replacement_function,
text,
)
# nota: le match sur \w*? donne le nom du logo et interdit les .. et autres
# tentatives d'acceder à d'autres fichiers !
# la protection contre des noms malveillants est aussi assurée par l'utilisation de
# secure_filename dans la classe Logo
# log('field: %s' % (text))
return sco_pdf.make_paras(
text, style, suppress_empty=suppress_empty_pars, field_name=field_name
)
def get_formsemestre_bulletins_pdf(formsemestre_id, version="selectedevals"):
"Document pdf avec tous les bulletins du semestre, et filename"
from app.but import bulletin_but_court
from app.scodoc import sco_bulletins
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
versions = (
scu.BULLETINS_VERSIONS_BUT
if formsemestre.formation.is_apc()
else scu.BULLETINS_VERSIONS
)
if version not in versions:
raise ScoValueError("version de bulletin demandée invalide !")
cached = sco_cache.SemBulletinsPDFCache.get(str(formsemestre_id) + "_" + version)
if cached:
return cached[1], cached[0]
fragments = []
# Make each bulletin
for etud in formsemestre.get_inscrits(include_demdef=True, order=True):
if version == "butcourt":
frag = bulletin_but_court.bulletin_but_court_pdf_frag(etud, formsemestre)
else:
frag, _ = sco_bulletins.do_formsemestre_bulletinetud(
formsemestre,
etud,
fmt="pdfpart",
version=version,
)
fragments += frag
#
infos = {"DeptName": sco_preferences.get_preference("DeptName", formsemestre_id)}
if request:
server_name = request.url_root
else:
server_name = ""
try:
sco_pdf.PDFLOCK.acquire()
pdfdoc = assemble_bulletins_pdf(
formsemestre_id,
fragments,
formsemestre.titre_mois(),
infos,
server_name=server_name,
)
finally:
sco_pdf.PDFLOCK.release()
#
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(
str(formsemestre_id) + "_" + version, (filename, pdfdoc)
)
return pdfdoc, filename
def get_etud_bulletins_pdf(etudid, version="selectedevals"):
"Bulletins pdf de tous les semestres de l'étudiant, et filename"
from app.scodoc import sco_bulletins
etud = Identite.get_etud(etudid)
fragments = []
bookmarks = {}
filigrannes = {}
i = 1
for formsemestre in etud.get_formsemestres():
frag, filigranne = sco_bulletins.do_formsemestre_bulletinetud(
formsemestre,
etud,
fmt="pdfpart",
version=version,
)
fragments += frag
filigrannes[i] = filigranne
bookmarks[i] = formsemestre.session_id() # eg RT-DUT-FI-S1-2015
i = i + 1
infos = {"DeptName": sco_preferences.get_preference("DeptName")}
if request:
server_name = request.url_root
else:
server_name = ""
try:
sco_pdf.PDFLOCK.acquire()
pdfdoc = assemble_bulletins_pdf(
None,
fragments,
etud.nomprenom,
infos,
bookmarks,
filigranne=filigrannes,
server_name=server_name,
)
finally:
sco_pdf.PDFLOCK.release()
#
filename = f"bul-{etud.nomprenom}"
filename = (
scu.unescape_html(filename).replace(" ", "_").replace("&", "").replace(".", "")
+ ".pdf"
)
return pdfdoc, filename
def get_filigranne(etud_etat: str, prefs, decision_sem=None) -> str:
"""Texte à placer en "filigranne" sur le bulletin pdf"""
if etud_etat == scu.DEMISSION:
return "Démission"
elif etud_etat == codes_cursus.DEF:
return "Défaillant"
elif (prefs["bul_show_temporary"] and not decision_sem) or prefs[
"bul_show_temporary_forced"
]:
return prefs["bul_temporary_txt"]
return ""