. HTML does not allow logos.
"""
try:
text = (field or "") % 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 = SCODOC_LOGOS_DIR + "/logos_" + context.DeptId() + "/"
if not os.path.exists(image_dir):
image_dir = 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 makeParas(text, style, suppress_empty=suppress_empty_pars)
def get_formsemestre_bulletins_pdf(
context, formsemestre_id, REQUEST, version="selectedevals"
):
"document pdf et filename"
cached = context._getNotesCache().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 = context._getNotesCache().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] = suppress_accents(nt.get_sexnom(etudid))
i = i + 1
#
infos = {"DeptName": context.get_preference("DeptName", formsemestre_id)}
if REQUEST:
server_name = REQUEST.BASE0
else:
server_name = ""
try:
PDFLOCK.acquire()
pdfdoc = pdfassemblebulletins(
formsemestre_id,
fragments,
sem["titremois"],
infos,
bookmarks,
filigranne=filigrannes,
server_name=server_name,
context=context,
)
finally:
PDFLOCK.release()
#
dt = time.strftime("%Y-%m-%d")
filename = "bul-%s-%s.pdf" % (sem["titre_num"], dt)
filename = unescape_html(filename).replace(" ", "_").replace("&", "")
# fill cache
context._getNotesCache().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": context.get_preference("DeptName")}
if REQUEST:
server_name = REQUEST.BASE0
else:
server_name = ""
try:
PDFLOCK.acquire()
pdfdoc = pdfassemblebulletins(
None,
fragments,
etud["nomprenom"],
infos,
bookmarks,
filigranne=filigrannes,
server_name=server_name,
context=context,
)
finally:
PDFLOCK.release()
#
filename = "bul-%s" % (etud["nomprenom"])
filename = (
unescape_html(filename).replace(" ", "_").replace("&", "").replace(".", "")
+ ".pdf"
)
return pdfdoc, filename