adapt sco_bulletin_pdf.py
This commit is contained in:
parent
ee4cebb5bb
commit
dca2486ecc
|
@ -68,6 +68,7 @@ from app.scodoc import sco_pdf
|
||||||
from app.scodoc import sco_preferences
|
from app.scodoc import sco_preferences
|
||||||
from app.scodoc import sco_etud
|
from app.scodoc import sco_etud
|
||||||
import sco_version
|
import sco_version
|
||||||
|
from app.scodoc.sco_logos import find_logo
|
||||||
|
|
||||||
|
|
||||||
def pdfassemblebulletins(
|
def pdfassemblebulletins(
|
||||||
|
@ -141,24 +142,15 @@ def process_field(field, cdict, style, suppress_empty_pars=False, format="pdf"):
|
||||||
return text
|
return text
|
||||||
# --- PDF format:
|
# --- PDF format:
|
||||||
# handle logos:
|
# handle logos:
|
||||||
image_dir = scu.SCODOC_LOGOS_DIR + "/logos_" + g.scodoc_dept + "/"
|
breakpoint()
|
||||||
if not os.path.exists(image_dir):
|
# la protection contre des noms malveillants est assuré par l'utilisation de secure_filename dans la classe Logo
|
||||||
image_dir = scu.SCODOC_LOGOS_DIR + "/" # use global logos
|
|
||||||
if not os.path.exists(image_dir):
|
|
||||||
log(f"Warning: missing global logo directory ({image_dir})")
|
|
||||||
image_dir = None
|
|
||||||
|
|
||||||
text = re.sub(
|
text = re.sub(
|
||||||
r"<(\s*)logo(.*?)src\s*=\s*(.*?)>", r"<\1logo\2\3>", text
|
r"<(\s*)logo(.*?)src\s*=\s*(.*?)>", r"<\1logo\2\3>", text) # remove forbidden src attribute
|
||||||
) # remove forbidden src attribute
|
image = find_logo(logoname=text, dept_id=g.scodoc_dept_id)
|
||||||
if image_dir is not None:
|
if image is not None:
|
||||||
text = re.sub(
|
text = re.sub(
|
||||||
r'<\s*logo(.*?)name\s*=\s*"(\w*?)"(.*?)/?>',
|
r'<\s*logo(.*?)name\s*=\s*"(\w*?)"(.*?)/?>',
|
||||||
r'<img\1src="%s/logo_\2.jpg"\3/>' % image_dir,
|
r'<img\1src="%s"/>' % image.filepath,)
|
||||||
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))
|
# log('field: %s' % (text))
|
||||||
return sco_pdf.makeParas(text, style, suppress_empty=suppress_empty_pars)
|
return sco_pdf.makeParas(text, style, suppress_empty=suppress_empty_pars)
|
||||||
|
|
Loading…
Reference in New Issue