From 3f01048f59f2579c503740e3c2cb962983cf1432 Mon Sep 17 00:00:00 2001 From: Jean-Marie Place Date: Wed, 20 Oct 2021 15:44:47 +0200 Subject: [PATCH] wip --- app/templates/configuration.html | 35 +++++++++----- app/views/scodoc.py | 78 +++++++++++++++++++++----------- 2 files changed, 76 insertions(+), 37 deletions(-) diff --git a/app/templates/configuration.html b/app/templates/configuration.html index 6dcf1c51f..44d6861de 100644 --- a/app/templates/configuration.html +++ b/app/templates/configuration.html @@ -16,6 +16,16 @@ {% endmacro %} +{% macro render_logo(logo, logo_field) %} + +{% endmacro %} + {% block app_content %} {% if scodoc_dept %} @@ -34,20 +44,23 @@ {% endif %} + +
{{ form.submit() }}
+{#

Logo en-tête

#} +{#

image placée en haut de certains documents documents PDF. Image actuelle:

#} +{#
pas de logo chargé
#} +{# {{ render_field(form.logo_header) }}#} +{#

Logo pied de page

#} +{#

image placée en pied de page de certains documents documents PDF. Image actuelle:

#} +{#
pas de logo chargé
#} +{# {{ render_field(form.logo_footer) }}#} -
{{ form.submit() }}
{% endblock %} \ No newline at end of file diff --git a/app/views/scodoc.py b/app/views/scodoc.py index 2ccac9283..aa3568b60 100644 --- a/app/views/scodoc.py +++ b/app/views/scodoc.py @@ -176,6 +176,28 @@ def about(scodoc_dept=None): # ---- CONFIGURATION +class Logo: + def __init__(self, name, titre, description, source, form): + self.titre = titre, + self.description = description + self.source = source + unbound = FileField( + name, + label="Modifier l'image:", + description=description, + validators=[ + FileAllowed( + scu.LOGOS_IMAGES_ALLOWED_TYPES, + f"n'accepte que les fichiers image {','.join([e for e in scu.LOGOS_IMAGES_ALLOWED_TYPES])}", + ), + ], + ) + self.field = form.Meta.bind_field( + form=form, + unbound_field=unbound, + options={}, + ) + class ScoDocConfigurationForm(FlaskForm): "Panneau de configuration général" @@ -187,30 +209,34 @@ class ScoDocConfigurationForm(FlaskForm): ], ) - logo_header = FileField( - label="Modifier l'image:", - description="logo placé en haut des documents PDF", - validators=[ - FileAllowed( - scu.LOGOS_IMAGES_ALLOWED_TYPES, - f"n'accepte que les fichiers image {','.join([e for e in scu.LOGOS_IMAGES_ALLOWED_TYPES])}", - ) - ], - ) - - logo_footer = FileField( - label="Modifier l'image:", - description="logo placé en pied des documents PDF", - validators=[ - FileAllowed( - scu.LOGOS_IMAGES_ALLOWED_TYPES, - f"n'accepte que les fichiers image {','.join([e for e in scu.LOGOS_IMAGES_ALLOWED_TYPES])}", - ) - ], - ) - + # logo_header = FileField( + # label="Modifier l'image:", + # description="logo placé en haut des documents PDF", + # validators=[ + # FileAllowed( + # scu.LOGOS_IMAGES_ALLOWED_TYPES, + # f"n'accepte que les fichiers image {','.join([e for e in scu.LOGOS_IMAGES_ALLOWED_TYPES])}", + # ) + # ], + # ) + # + # logo_footer = FileField( + # label="Modifier l'image:", + # description="logo placé en pied des documents PDF", + # validators=[ + # FileAllowed( + # scu.LOGOS_IMAGES_ALLOWED_TYPES, + # f"n'accepte que les fichiers image {','.join([e for e in scu.LOGOS_IMAGES_ALLOWED_TYPES])}", + # ) + # ], + # ) submit = SubmitField("Enregistrer") + def __init__(self, *args, scodoc_dept=None, **kwargs): + breakpoint() + super().__init__(*args, **kwargs) + self.header = Logo(name='header', titre="Logo en-tête", description="logo placé en haut des documents PDF", source=url_for('scodoc.logo_header', scodoc_dept=None), form=self) + self.footer = Logo(name='footer', titre="Logo en-tête", description="logo placé en pied des documents PDF", source=url_for('scodoc.logo_footer', scodoc_dept=None), form=self) # Notes pour variables config: (valeurs par défaut des paramètres de département) # Chaines simples @@ -239,13 +265,13 @@ def configuration(): ) if form.validate_on_submit(): ScoDocSiteConfig.set_bonus_sport_func(form.bonus_sport_func_name.data) - if form.logo_header.data: + if form.header.field.data: sco_logos.store_image( - form.logo_header.data, os.path.join(scu.SCODOC_LOGOS_DIR, "logo_header") + form.header.field.data, os.path.join(scu.SCODOC_LOGOS_DIR, "logo_header") ) - if form.logo_footer.data: + if form.footer.field.data: sco_logos.store_image( - form.logo_footer.data, os.path.join(scu.SCODOC_LOGOS_DIR, "logo_footer") + form.footer.field.data, os.path.join(scu.SCODOC_LOGOS_DIR, "logo_footer") ) app.clear_scodoc_cache() flash(f"Configuration enregistrée")