. HTML does not allow logos.
"""
try:
text = (field or "") % scu.WrapDict(
cdict
) # note that None values are mapped to empty strings
except:
log("process_field: invalid format=%s" % field)
text = (
" ", text)
return text
# --- PDF format:
# handle logos:
image_dir = scu.SCODOC_LOGOS_DIR + "/logos_" + sco_core.get_dept_id() + "/"
if not os.path.exists(image_dir):
image_dir = scu.SCODOC_LOGOS_DIR + "/" # use global 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*?)"(.*?)/?>',
r'' % image_dir,
text,
)
# nota: le match sur \w*? donne le nom du logo et interdit les .. et autres
# tentatives d'acceder à d'autres fichiers !
# log('field: %s' % (text))
return sco_pdf.makeParas(text, style, suppress_empty=suppress_empty_pars)
def get_formsemestre_bulletins_pdf(
context, formsemestre_id, REQUEST, version="selectedevals"
):
"document pdf et filename"
cached = sco_core.get_notes_cache(
context,
).get_bulletins_pdf(formsemestre_id, version)
if cached:
return cached[1], cached[0]
fragments = []
sem = sco_formsemestre.get_formsemestre(context, formsemestre_id)
# Make each bulletin
nt = sco_core.get_notes_cache(context).get_NotesTable(
context, formsemestre_id
) # > get_etudids, get_sexnom
bookmarks = {}
filigrannes = {}
i = 1
for etudid in nt.get_etudids():
frag, filigranne = sco_bulletins.do_formsemestre_bulletinetud(
context,
formsemestre_id,
etudid,
format="pdfpart",
version=version,
REQUEST=REQUEST,
)
fragments += frag
filigrannes[i] = filigranne
bookmarks[i] = scu.suppress_accents(nt.get_sexnom(etudid))
i = i + 1
#
infos = {
"DeptName": sco_preferences.get_preference(context, "DeptName", formsemestre_id)
}
if REQUEST:
server_name = REQUEST.BASE0
else:
server_name = ""
try:
sco_pdf.PDFLOCK.acquire()
pdfdoc = pdfassemblebulletins(
formsemestre_id,
fragments,
sem["titremois"],
infos,
bookmarks,
filigranne=filigrannes,
server_name=server_name,
context=context,
)
finally:
sco_pdf.PDFLOCK.release()
#
dt = time.strftime("%Y-%m-%d")
filename = "bul-%s-%s.pdf" % (sem["titre_num"], dt)
filename = scu.unescape_html(filename).replace(" ", "_").replace("&", "")
# fill cache
sco_core.get_notes_cache(
context,
).store_bulletins_pdf(formsemestre_id, version, filename, pdfdoc)
return pdfdoc, filename
def get_etud_bulletins_pdf(context, etudid, REQUEST, version="selectedevals"):
"Bulletins pdf de tous les semestres de l'étudiant, et filename"
etud = context.getEtudInfo(etudid=etudid, filled=1)[0]
fragments = []
bookmarks = {}
filigrannes = {}
i = 1
for sem in etud["sems"]:
frag, filigranne = sco_bulletins.do_formsemestre_bulletinetud(
context,
sem["formsemestre_id"],
etudid,
format="pdfpart",
version=version,
REQUEST=REQUEST,
)
fragments += frag
filigrannes[i] = filigranne
bookmarks[i] = sem["session_id"] # eg RT-DUT-FI-S1-2015
i = i + 1
infos = {"DeptName": sco_preferences.get_preference(context, "DeptName")}
if REQUEST:
server_name = REQUEST.BASE0
else:
server_name = ""
try:
sco_pdf.PDFLOCK.acquire()
pdfdoc = pdfassemblebulletins(
None,
fragments,
etud["nomprenom"],
infos,
bookmarks,
filigranne=filigrannes,
server_name=server_name,
context=context,
)
finally:
sco_pdf.PDFLOCK.release()
#
filename = "bul-%s" % (etud["nomprenom"])
filename = (
scu.unescape_html(filename).replace(" ", "_").replace("&", "").replace(".", "")
+ ".pdf"
)
return pdfdoc, filename