raffinement message d états logos

This commit is contained in:
Jean-Marie Place 2021-12-11 18:31:37 +01:00
parent 235ca69a82
commit 95aa0f6523
2 changed files with 17 additions and 70 deletions

View File

@ -61,6 +61,14 @@ class Action:
GLOBAL = "_"
def _libelle_dept(dept_key=None, dept_name=None):
if dept_key == GLOBAL:
lib_dept = f"au niveau global"
else:
lib_dept = f"pour le département {dept_name}"
return lib_dept
class LogoUpdate(Action):
"""Action: change a logo
dept_id: dept_id or '_',
@ -70,7 +78,7 @@ class LogoUpdate(Action):
def __init__(self, parameters):
super().__init__(
f"Modification du logo {parameters['logo_id']} pour le département {parameters['dept_id']}",
f"Modification du logo {parameters['logo_id']} {_libelle_dept(parameters['dept_key'], parameters['dept_name'])}",
parameters,
)
@ -101,7 +109,7 @@ class LogoDelete(Action):
def __init__(self, parameters):
super().__init__(
f"Suppression du logo {parameters['logo_id']} pour le département {parameters['dept_id']}.",
f"Suppression du logo {parameters['logo_id']} {_libelle_dept(parameters['dept_key'], parameters['dept_name'])}",
parameters,
)
@ -128,7 +136,7 @@ class LogoInsert(Action):
def __init__(self, parameters):
super().__init__(
f"Ajout du logo {parameters['name']} pour le département {parameters['dept_key']} ({parameters['upload']}).",
f"Ajout du logo {parameters['name']} {_libelle_dept(parameters['dept_key'], parameters['dept_name'])} ({parameters['upload']}).",
parameters,
)

View File

@ -58,40 +58,6 @@ JAVASCRIPTS = html_sco_header.BOOTSTRAP_MULTISELECT_JS + []
CSSSTYLES = html_sco_header.BOOTSTRAP_MULTISELECT_CSS
# class ItemForm(FlaskForm):
# """Unused Generic class to document common behavior for classes
# * ScoConfigurationForm
# * DeptForm
# * LogoForm
# Some or all of these implements:
# * Composite design pattern (ScoConfigurationForm and DeptForm)
# - a FieldList(FormField(ItemForm))
# - FieldListItem are created by browsing the model
# - index dictionnary to provide direct access to a SubItemForm
# - the direct access method (get_form)
# * have some information added to be displayed
# - information are collected from a model object
# Common methods:
# * build(model) (not for LogoForm who has no child)
# for each child:
# * create en entry in the FieldList for each subitem found
# * update self.index
# * fill_in additional information into the form
# * recursively calls build for each chid
# some spécific information may be added after standard processing
# (typically header/footer description)
# * preview(data)
# check the data from a post and build a list of operations that has to be done.
# for a two phase process:
# * phase 1 (list all opérations)
# * phase 2 (may be confirmation and execure)
# - if no op found: return to the form with a message 'Aucune modification trouvée'
# - only one operation found: execute and go to main page
# - more than 1 operation found. asked form confirmation (and execution if confirmed)
#
# Someday we'll have time to refactor as abstract classes but Abstract FieldList makes this a bit complicated
# """
# Terminology:
# dept_id : identifies a dept in modele (= list_logos()). None designates globals logos
# dept_key : identifies a dept in this form only (..index[dept_key], and fields 'dept_key').
@ -115,6 +81,7 @@ class AddLogoForm(FlaskForm):
"""Formulaire permettant l'ajout d'un logo (dans un département)"""
dept_key = HiddenField()
dept_name = HiddenField()
name = StringField(
label="Nom",
validators=[
@ -164,6 +131,7 @@ class LogoForm(FlaskForm):
and all its data and UI action (change, delete)"""
dept_key = HiddenField()
dept_name = HiddenField()
logo_id = HiddenField()
upload = FileField(
label="Remplacer l'image",
@ -274,12 +242,14 @@ def _make_dept_data(dept_id, dept_name, modele):
data = {
"dept_key": dept_key,
"dept_name": dept_name,
"add_logo": {"dept_key": dept_key},
"add_logo": {"dept_key": dept_key, "dept_name": dept_name},
}
logos = []
if modele is not None:
for name in _ordered_logos(modele):
logos.append({"dept_key": dept_key, "logo_id": name})
logos.append(
{"dept_key": dept_key, "dept_name": dept_name, "logo_id": name}
)
data["logos"] = logos
return data
@ -317,37 +287,6 @@ class ScoDocConfigurationForm(FlaskForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# def _set_global_logos_infos(self):
# "specific processing for globals items"
# global_header = self.get_form(logoname="header")
# global_header.description = (
# "image placée en haut de certains documents documents PDF."
# )
# global_header.titre = "Logo en-tête"
# global_header.can_delete = False
# global_footer = self.get_form(logoname="footer")
# global_footer.description = (
# "image placée en pied de page de certains documents documents PDF."
# )
# global_footer.titre = "Logo pied de page"
# global_footer.can_delete = False
# def _build_dept(self, dept_id, dept_name, modele):
# dept_key = dept_id or GLOBAL
# data = {"dept_key": dept_key}
# entry = self.depts.append_entry(data)
# entry.form.build(dept_name, modele.get(dept_id, {}))
# self.index[str(dept_key)] = entry.form
# def build(self, modele):
# "Build the Form hierachy (DeptForm, LogoForm) and add extra data (from modele)"
# # if entries already initialized (POST). keep subforms
# self.index = {}
# # create entries in FieldList (one entry per dept
# for dept_id, dept_name in self.dept_id_name:
# self._build_dept(dept_id=dept_id, dept_name=dept_name, modele=modele)
# self._set_global_logos_infos()
def get_form(self, dept_key=GLOBAL, logoname=None):
"""Retourne un formulaire:
* pour un département (get_form(dept_id)) ou à un logo (get_form(dept_id, logname))