wip before alpha testing
This commit is contained in:
parent
bb9679e0fc
commit
0d0ba5ae60
|
@ -145,12 +145,14 @@ def process_field(field, cdict, style, suppress_empty_pars=False, format="pdf"):
|
|||
breakpoint()
|
||||
# la protection contre des noms malveillants est assuré par l'utilisation de secure_filename dans la classe Logo
|
||||
text = re.sub(
|
||||
r"<(\s*)logo(.*?)src\s*=\s*(.*?)>", r"<\1logo\2\3>", text) # remove forbidden src attribute
|
||||
r"<(\s*)logo(.*?)src\s*=\s*(.*?)>", r"<\1logo\2\3>", text
|
||||
) # remove forbidden src attribute
|
||||
image = find_logo(logoname=text, dept_id=g.scodoc_dept_id)
|
||||
if image is not None:
|
||||
text = re.sub(
|
||||
r'<\s*logo(.*?)name\s*=\s*"(\w*?)"(.*?)/?>',
|
||||
r'<img\1src="%s"/>' % image.filepath,)
|
||||
r'<img\1src="%s"/>' % image.filepath,
|
||||
)
|
||||
|
||||
# log('field: %s' % (text))
|
||||
return sco_pdf.makeParas(text, style, suppress_empty=suppress_empty_pars)
|
||||
|
|
|
@ -48,7 +48,9 @@ from PIL import Image as PILImage
|
|||
GLOBAL = "_SERVER" # category for server level logos
|
||||
|
||||
|
||||
def find_logo(logoname, dept_id=None, global_if_not_found=True, prefix=scu.LOGO_FILE_PREFIX):
|
||||
def find_logo(
|
||||
logoname, dept_id=None, global_if_not_found=True, prefix=scu.LOGO_FILE_PREFIX
|
||||
):
|
||||
"""
|
||||
"Recherche un logo 'name' existant.
|
||||
Deux strategies:
|
||||
|
@ -105,7 +107,9 @@ def _list_dept_logos(dept_id=None, prefix=scu.LOGO_FILE_PREFIX):
|
|||
path_dir = Path(scu.SCODOC_LOGOS_DIR)
|
||||
if dept_id:
|
||||
path_dir = Path(
|
||||
os.path.sep.join([scu.SCODOC_LOGOS_DIR, LOGOS_DIR_PREFIX + str(dept_id)])
|
||||
os.path.sep.join(
|
||||
[scu.SCODOC_LOGOS_DIR, scu.LOGOS_DIR_PREFIX + str(dept_id)]
|
||||
)
|
||||
)
|
||||
if path_dir.exists():
|
||||
for entry in path_dir.iterdir():
|
||||
|
@ -133,13 +137,16 @@ class Logo:
|
|||
Le format est renseigné au moment de la lecture (read) ou de la création (create) de l'objet
|
||||
"""
|
||||
self.logoname = secure_filename(logoname)
|
||||
self.scodoc_dept = dept_id
|
||||
self.scodoc_dept_id = dept_id
|
||||
self.prefix = prefix or ""
|
||||
self.suffix = None
|
||||
self.dimensions = None
|
||||
if self.scodoc_dept:
|
||||
if self.scodoc_dept_id:
|
||||
self.dirpath = os.path.sep.join(
|
||||
[scu.SCODOC_LOGOS_DIR, scu.LOGOS_DIR_PREFIX + secure_filename(str(dept_id))]
|
||||
[
|
||||
scu.SCODOC_LOGOS_DIR,
|
||||
scu.LOGOS_DIR_PREFIX + secure_filename(str(dept_id)),
|
||||
]
|
||||
)
|
||||
else:
|
||||
self.dirpath = scu.SCODOC_LOGOS_DIR
|
||||
|
@ -194,13 +201,12 @@ class Logo:
|
|||
return self
|
||||
# if no file found, raise exception
|
||||
raise ScoValueError(
|
||||
"Logo %s not found for dept %s" % (self.logoname, self.scodoc_dept)
|
||||
"Logo %s not found for dept %s" % (self.logoname, self.scodoc_dept_id)
|
||||
)
|
||||
|
||||
def get_url(self):
|
||||
if self.scodoc_dept
|
||||
return url_for(
|
||||
"scodoc.logo_custom", scodoc_dept=self.scodoc_dept, name=self.logoname
|
||||
"scodoc.logo_custom", scodoc_dept=self.scodoc_dept_id, name=self.logoname
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -220,12 +220,14 @@ class ScolarsPageTemplate(PageTemplate):
|
|||
)
|
||||
PageTemplate.__init__(self, "ScolarsPageTemplate", [content])
|
||||
self.logo = None
|
||||
# XXX COPIED from sco_pvpdf, to be refactored (no time now)
|
||||
# Search background in dept specific dir, then in global config dir
|
||||
logo = find_logo(logoname="bul_pdf_background", dept_id=g.scodoc_dept_id, global_if_not_found=, prefix=None)
|
||||
logo = find_logo(
|
||||
logoname="bul_pdf_background", dept_id=g.scodoc_dept_id, prefix=None
|
||||
)
|
||||
if logo is None:
|
||||
# Also try to use PV background
|
||||
logo = find_logo(logoname="letter_background", dept_id=g.scodoc_dept_id, global_if_not_found=, prefix=None)
|
||||
logo = find_logo(
|
||||
logoname="letter_background", dept_id=g.scodoc_dept_id, prefix=None
|
||||
)
|
||||
if logo is not None:
|
||||
self.background_image_filename = logo.filepath
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ from app.scodoc import sco_pdf
|
|||
from app.scodoc import sco_preferences
|
||||
from app.scodoc import sco_etud
|
||||
import sco_version
|
||||
from app.scodoc.sco_logos import find_logo
|
||||
from app.scodoc.sco_pdf import PDFLOCK
|
||||
from app.scodoc.sco_pdf import SU
|
||||
|
||||
|
@ -207,24 +208,34 @@ class CourrierIndividuelTemplate(PageTemplate):
|
|||
):
|
||||
for suffix in scu.LOGOS_IMAGES_ALLOWED_TYPES:
|
||||
if template_name == "PVJuryTemplate":
|
||||
fn = image_dir + "/pvjury_background" + "." + suffix
|
||||
background = find_logo(
|
||||
logoname="pvjury_background",
|
||||
dept_id=g.scodoc_dept_id,
|
||||
prefix="",
|
||||
global_if_not_found=True,
|
||||
)
|
||||
else:
|
||||
fn = image_dir + "/letter_background" + "." + suffix
|
||||
if not self.background_image_filename and os.path.exists(fn):
|
||||
self.background_image_filename = fn
|
||||
background = find_logo(
|
||||
logoname="letter_background",
|
||||
dept_id=g.scodoc_dept_id,
|
||||
prefix="",
|
||||
global_if_not_found=True,
|
||||
)
|
||||
if not self.background_image_filename and background is not None:
|
||||
self.background_image_filename = background.filepath
|
||||
|
||||
fn = image_dir + "/logo_footer" + "." + suffix
|
||||
if not self.logo_footer and os.path.exists(fn):
|
||||
footer = find_logo(logoname="footer", dept_id=g.scodoc_dept_id)
|
||||
if footer is not None:
|
||||
self.logo_footer = Image(
|
||||
fn,
|
||||
footer.filepath,
|
||||
height=LOGO_FOOTER_HEIGHT,
|
||||
width=LOGO_FOOTER_WIDTH,
|
||||
)
|
||||
|
||||
fn = image_dir + "/logo_header" + "." + suffix
|
||||
if not self.logo_header and os.path.exists(fn):
|
||||
header = find_logo(logoname="header", dept_id=g.scodoc_dept_id)
|
||||
if header is not None:
|
||||
self.logo_header = Image(
|
||||
fn,
|
||||
header.filepath,
|
||||
height=LOGO_HEADER_HEIGHT,
|
||||
width=LOGO_HEADER_WIDTH,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue