From dab0f78279cc930537ade4f76e01ea713e26b1d1 Mon Sep 17 00:00:00 2001 From: Jean-Marie PLACE Date: Thu, 14 Apr 2022 10:52:38 +0200 Subject: [PATCH] fix ad local header ; deployed errored fields --- app/forms/main/config_logos.py | 23 +++++++++++++++++++- app/scodoc/sco_config_actions.py | 2 +- app/templates/config_logos.html | 36 +++++++++++++++++++++----------- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/app/forms/main/config_logos.py b/app/forms/main/config_logos.py index db69ae35..daea5de1 100644 --- a/app/forms/main/config_logos.py +++ b/app/forms/main/config_logos.py @@ -151,7 +151,7 @@ class AddLogoForm(FlaskForm): dept_id = dept_key_to_id(self.dept_key.data) if dept_id == GLOBAL: dept_id = None - if find_logo(logoname=name.data, dept_id=dept_id) is not None: + if find_logo(logoname=name.data, dept_id=dept_id, strict=True) is not None: raise validators.ValidationError("Un logo de même nom existe déjà") def select_action(self): @@ -160,6 +160,14 @@ class AddLogoForm(FlaskForm): return LogoInsert.build_action(self.data) return None + def errors(self): + if self.do_insert.data: + if self.name.errors: + return True + if self.upload.errors: + return True + return False + class LogoForm(FlaskForm): """Embed both presentation of a logo (cf. template file configuration.html) @@ -211,6 +219,11 @@ class LogoForm(FlaskForm): return LogoUpdate.build_action(self.data) return None + def errors(self): + if self.upload.data and self.upload.errors: + return True + return False + class DeptForm(FlaskForm): dept_key = HiddenField() @@ -244,6 +257,14 @@ class DeptForm(FlaskForm): return self return self.index.get(logoname, None) + def errors(self): + if self.add_logo.errors(): + return True + for logo_form in self.logos: + if logo_form.errors(): + return True + return False + def _make_dept_id_name(): """Cette section assure que tous les départements sont traités (y compris ceux qu'ont pas de logo au départ) diff --git a/app/scodoc/sco_config_actions.py b/app/scodoc/sco_config_actions.py index f6ea9637..e0e9133e 100644 --- a/app/scodoc/sco_config_actions.py +++ b/app/scodoc/sco_config_actions.py @@ -136,7 +136,7 @@ class LogoInsert(Action): parameters["dept_id"] = None if parameters["upload"] and parameters["name"]: logo = find_logo( - logoname=parameters["name"], dept_id=parameters["dept_key"] + logoname=parameters["name"], dept_id=parameters["dept_key"], strict=True ) if logo is None: return LogoInsert(parameters) diff --git a/app/templates/config_logos.html b/app/templates/config_logos.html index a4974ca7..04d4d266 100644 --- a/app/templates/config_logos.html +++ b/app/templates/config_logos.html @@ -20,20 +20,28 @@ {% endmacro %} {% macro render_add_logo(add_logo_form) %} -
- -

Ajouter un logo

-
-
- {{ render_field(add_logo_form.name) }} - {{ render_field(add_logo_form.upload) }} - {{ render_field(add_logo_form.do_insert, False, onSubmit="submit_form") }} -
-
+ {% if add_logo_form.errors() %} +
+ {% else %} +
+ {% endif %} + +

Ajouter un logo

+
+
+ {{ render_field(add_logo_form.name) }} + {{ render_field(add_logo_form.upload) }} + {{ render_field(add_logo_form.do_insert, False, onSubmit="submit_form") }} +
+
{% endmacro %} {% macro render_logo(dept_form, logo_form) %} -
+ {% if logo_form.errors() %} +
+ {% else %} +
+ {% endif %} {{ logo_form.hidden_tag() }} {% if logo_form.titre %} @@ -97,9 +105,13 @@