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()
|
breakpoint()
|
||||||
# la protection contre des noms malveillants est assuré par l'utilisation de secure_filename dans la classe Logo
|
# la protection contre des noms malveillants est assuré par l'utilisation de secure_filename dans la classe Logo
|
||||||
text = re.sub(
|
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)
|
image = find_logo(logoname=text, dept_id=g.scodoc_dept_id)
|
||||||
if image 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"/>' % image.filepath,)
|
r'<img\1src="%s"/>' % image.filepath,
|
||||||
|
)
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
|
@ -48,7 +48,9 @@ from PIL import Image as PILImage
|
||||||
GLOBAL = "_SERVER" # category for server level logos
|
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.
|
"Recherche un logo 'name' existant.
|
||||||
Deux strategies:
|
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)
|
path_dir = Path(scu.SCODOC_LOGOS_DIR)
|
||||||
if dept_id:
|
if dept_id:
|
||||||
path_dir = Path(
|
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():
|
if path_dir.exists():
|
||||||
for entry in path_dir.iterdir():
|
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
|
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.logoname = secure_filename(logoname)
|
||||||
self.scodoc_dept = dept_id
|
self.scodoc_dept_id = dept_id
|
||||||
self.prefix = prefix or ""
|
self.prefix = prefix or ""
|
||||||
self.suffix = None
|
self.suffix = None
|
||||||
self.dimensions = None
|
self.dimensions = None
|
||||||
if self.scodoc_dept:
|
if self.scodoc_dept_id:
|
||||||
self.dirpath = os.path.sep.join(
|
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:
|
else:
|
||||||
self.dirpath = scu.SCODOC_LOGOS_DIR
|
self.dirpath = scu.SCODOC_LOGOS_DIR
|
||||||
|
@ -194,13 +201,12 @@ class Logo:
|
||||||
return self
|
return self
|
||||||
# if no file found, raise exception
|
# if no file found, raise exception
|
||||||
raise ScoValueError(
|
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):
|
def get_url(self):
|
||||||
if self.scodoc_dept
|
|
||||||
return url_for(
|
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])
|
PageTemplate.__init__(self, "ScolarsPageTemplate", [content])
|
||||||
self.logo = None
|
self.logo = None
|
||||||
# XXX COPIED from sco_pvpdf, to be refactored (no time now)
|
logo = find_logo(
|
||||||
# Search background in dept specific dir, then in global config dir
|
logoname="bul_pdf_background", dept_id=g.scodoc_dept_id, prefix=None
|
||||||
logo = find_logo(logoname="bul_pdf_background", dept_id=g.scodoc_dept_id, global_if_not_found=, prefix=None)
|
)
|
||||||
if logo is None:
|
if logo is None:
|
||||||
# Also try to use PV background
|
# 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:
|
if logo is not None:
|
||||||
self.background_image_filename = logo.filepath
|
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_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
|
||||||
from app.scodoc.sco_pdf import PDFLOCK
|
from app.scodoc.sco_pdf import PDFLOCK
|
||||||
from app.scodoc.sco_pdf import SU
|
from app.scodoc.sco_pdf import SU
|
||||||
|
|
||||||
|
@ -207,24 +208,34 @@ class CourrierIndividuelTemplate(PageTemplate):
|
||||||
):
|
):
|
||||||
for suffix in scu.LOGOS_IMAGES_ALLOWED_TYPES:
|
for suffix in scu.LOGOS_IMAGES_ALLOWED_TYPES:
|
||||||
if template_name == "PVJuryTemplate":
|
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:
|
else:
|
||||||
fn = image_dir + "/letter_background" + "." + suffix
|
background = find_logo(
|
||||||
if not self.background_image_filename and os.path.exists(fn):
|
logoname="letter_background",
|
||||||
self.background_image_filename = fn
|
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
|
footer = find_logo(logoname="footer", dept_id=g.scodoc_dept_id)
|
||||||
if not self.logo_footer and os.path.exists(fn):
|
if footer is not None:
|
||||||
self.logo_footer = Image(
|
self.logo_footer = Image(
|
||||||
fn,
|
footer.filepath,
|
||||||
height=LOGO_FOOTER_HEIGHT,
|
height=LOGO_FOOTER_HEIGHT,
|
||||||
width=LOGO_FOOTER_WIDTH,
|
width=LOGO_FOOTER_WIDTH,
|
||||||
)
|
)
|
||||||
|
|
||||||
fn = image_dir + "/logo_header" + "." + suffix
|
header = find_logo(logoname="header", dept_id=g.scodoc_dept_id)
|
||||||
if not self.logo_header and os.path.exists(fn):
|
if header is not None:
|
||||||
self.logo_header = Image(
|
self.logo_header = Image(
|
||||||
fn,
|
header.filepath,
|
||||||
height=LOGO_HEADER_HEIGHT,
|
height=LOGO_HEADER_HEIGHT,
|
||||||
width=LOGO_HEADER_WIDTH,
|
width=LOGO_HEADER_WIDTH,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue