1
0
forked from ScoDoc/ScoDoc

Merge branch 'master' of https://scodoc.org/git/viennet/ScoDoc into dev93

This commit is contained in:
Emmanuel Viennet 2022-04-14 06:22:15 +02:00
commit 21cfe4ebf8
3 changed files with 47 additions and 14 deletions

View File

@ -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)

View File

@ -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)

View File

@ -20,20 +20,28 @@
{% endmacro %}
{% macro render_add_logo(add_logo_form) %}
<details>
<summary>
<h3>Ajouter un logo</h3>
</summary>
<div>
{{ render_field(add_logo_form.name) }}
{{ render_field(add_logo_form.upload) }}
{{ render_field(add_logo_form.do_insert, False, onSubmit="submit_form") }}
</div>
</details>
{% if add_logo_form.errors() %}
<details open>
{% else %}
<details>
{% endif %}
<summary>
<h3>Ajouter un logo</h3>
</summary>
<div>
{{ render_field(add_logo_form.name) }}
{{ render_field(add_logo_form.upload) }}
{{ render_field(add_logo_form.do_insert, False, onSubmit="submit_form") }}
</div>
</details>
{% endmacro %}
{% macro render_logo(dept_form, logo_form) %}
<details>
{% if logo_form.errors() %}
<details open>
{% else %}
<details>
{% endif %}
{{ logo_form.hidden_tag() }}
<summary>
{% if logo_form.titre %}
@ -97,9 +105,13 @@
<div class="configuration_logo">
<h1>Bibliothèque de logos</h1>
{% for dept_entry in form.depts.entries %}
<details>
{% set dept_form = dept_entry.form %}
{{ dept_entry.form.hidden_tag() }}
{% if dept_form.errors() %}
<details open>
{% else %}
<details>
{% endif %}
<summary>
{% if dept_entry.form.is_local() %}
<h2>Département {{ dept_form.dept_name.data }}</h2>