actions delete/update/insert... ok
|
@ -75,8 +75,10 @@ class LogoUpdate(Action):
|
|||
|
||||
@staticmethod
|
||||
def build_action(parameters):
|
||||
if parameters["dept_id"] == GLOBAL:
|
||||
parameters["dept_id"] = None
|
||||
dept_id = parameters["dept_key"]
|
||||
if dept_id == GLOBAL:
|
||||
dept_id = None
|
||||
parameters["dept_id"] = dept_id
|
||||
if parameters["upload"] is not None:
|
||||
return LogoUpdate(parameters)
|
||||
return None
|
||||
|
@ -103,7 +105,8 @@ class LogoDelete(Action):
|
|||
|
||||
@staticmethod
|
||||
def build_action(parameters):
|
||||
if parameters["dept_id"] == GLOBAL:
|
||||
parameters["dept_id"] = parameters["dept_key"]
|
||||
if parameters["dept_key"] == GLOBAL:
|
||||
parameters["dept_id"] = None
|
||||
if parameters["do_delete"]:
|
||||
return LogoDelete(parameters)
|
||||
|
@ -115,32 +118,37 @@ class LogoDelete(Action):
|
|||
|
||||
class LogoInsert(Action):
|
||||
"""Action: add a new logo
|
||||
dept_id: dept_id or '_',
|
||||
dept_key: dept_id or '_',
|
||||
logo_id: logo_id,
|
||||
upload: image file replacement
|
||||
"""
|
||||
|
||||
def __init__(self, parameters):
|
||||
super().__init__(
|
||||
"Ajout du logo {name} pour le département {dept_id} ({upload}).",
|
||||
f"Ajout du logo {parameters['name']} pour le département {parameters['dept_key']} ({parameters['upload']}).",
|
||||
parameters,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def build_action(parameters):
|
||||
if parameters["dept_id"] == GLOBAL:
|
||||
if parameters["dept_key"] == GLOBAL:
|
||||
parameters["dept_id"] = None
|
||||
if parameters["upload"] and parameters["name"]:
|
||||
logo = find_logo(logoname=parameters["name"], dept_id=parameters["dept_id"])
|
||||
logo = find_logo(
|
||||
logoname=parameters["name"], dept_id=parameters["dept_key"]
|
||||
)
|
||||
if logo is None:
|
||||
return LogoInsert(parameters)
|
||||
return None
|
||||
|
||||
def execute(self):
|
||||
dept_id = self.parameters["dept_key"]
|
||||
if dept_id == GLOBAL:
|
||||
dept_id = None
|
||||
write_logo(
|
||||
stream=self.parameters["upload"],
|
||||
name=self.parameters["name"],
|
||||
dept_id=self.parameters["dept_id"],
|
||||
dept_id=dept_id,
|
||||
)
|
||||
|
||||
|
||||
|
@ -150,7 +158,7 @@ class BonusSportUpdate(Action):
|
|||
|
||||
def __init__(self, parameters):
|
||||
super().__init__(
|
||||
"Changement du calcul de bonus sport ({bonus_sport_func_name}).",
|
||||
f"Changement du calcul de bonus sport pour ({parameters['bonus_sport_func_name']}).",
|
||||
parameters,
|
||||
)
|
||||
|
||||
|
|
|
@ -99,15 +99,27 @@ CSSSTYLES = html_sco_header.BOOTSTRAP_MULTISELECT_CSS
|
|||
GLOBAL = "_"
|
||||
|
||||
|
||||
def dept_id_to_key(dept_id):
|
||||
if dept_id is None:
|
||||
return GLOBAL
|
||||
return dept_id
|
||||
|
||||
|
||||
def dept_key_to_id(dept_key):
|
||||
if dept_key == GLOBAL:
|
||||
return None
|
||||
return dept_key
|
||||
|
||||
|
||||
class AddLogoForm(FlaskForm):
|
||||
"""Formulaire permettant l'ajout d'un logo (dans un département)"""
|
||||
|
||||
dept_id = HiddenField()
|
||||
dept_key = HiddenField()
|
||||
name = StringField(
|
||||
label="Nom",
|
||||
validators=[
|
||||
validators.regexp(
|
||||
"[A-Z0-9-]*",
|
||||
r"^[a-zA-Z0-9-]*$",
|
||||
re.IGNORECASE,
|
||||
"Ne doit comporter que lettres, chiffres ou -",
|
||||
),
|
||||
|
@ -122,7 +134,7 @@ class AddLogoForm(FlaskForm):
|
|||
validators=[
|
||||
FileAllowed(
|
||||
scu.LOGOS_IMAGES_ALLOWED_TYPES,
|
||||
f"n'accepte que les fichiers image {','.join(scu.LOGOS_IMAGES_ALLOWED_TYPES)}",
|
||||
f"n'accepte que les fichiers image {', '.join(scu.LOGOS_IMAGES_ALLOWED_TYPES)}",
|
||||
),
|
||||
validators.required("Fichier image manquant"),
|
||||
],
|
||||
|
@ -133,9 +145,11 @@ class AddLogoForm(FlaskForm):
|
|||
kwargs["meta"] = {"csrf": False}
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def select_action(self, add_data):
|
||||
if add_data["do_insert"] and self.validate():
|
||||
return LogoInsert.build_action(add_data)
|
||||
def select_action(self):
|
||||
if self.data["do_insert"]:
|
||||
breakpoint()
|
||||
if self.validate():
|
||||
return LogoInsert.build_action(self.data)
|
||||
return None
|
||||
|
||||
|
||||
|
@ -150,46 +164,43 @@ class LogoForm(FlaskForm):
|
|||
validators=[
|
||||
FileAllowed(
|
||||
scu.LOGOS_IMAGES_ALLOWED_TYPES,
|
||||
f"n'accepte que les fichiers image {','.join(scu.LOGOS_IMAGES_ALLOWED_TYPES)}",
|
||||
f"n'accepte que les fichiers image {', '.join(scu.LOGOS_IMAGES_ALLOWED_TYPES)}",
|
||||
)
|
||||
],
|
||||
)
|
||||
do_delete = SubmitField("Supprimer l'image")
|
||||
|
||||
def dept_id(self):
|
||||
if self.dept_key.data == GLOBAL:
|
||||
return None
|
||||
return self.dept_key.data
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs["meta"] = {"csrf": False}
|
||||
super().__init__(*args, **kwargs)
|
||||
self.logo = find_logo(logoname=self.logo_id.data, dept_id=self.dept_key.data).select()
|
||||
self.logo = find_logo(
|
||||
logoname=self.logo_id.data, dept_id=dept_key_to_id(self.dept_key.data)
|
||||
).select()
|
||||
self.description = None
|
||||
self.titre = None
|
||||
self.titre = None
|
||||
self.can_delete = True
|
||||
if self.dept_key.data == GLOBAL:
|
||||
if self.logo_id.data == 'header':
|
||||
if self.logo_id.data == "header":
|
||||
self.can_delete = False
|
||||
self.description = ""
|
||||
self.titre = "Logo en-tête"
|
||||
if self.logo_id.data == 'footer':
|
||||
if self.logo_id.data == "footer":
|
||||
self.can_delete = False
|
||||
self.titre = "Logo pied de page"
|
||||
self.description = ""
|
||||
else:
|
||||
if self.logo_id.data == 'header':
|
||||
if self.logo_id.data == "header":
|
||||
self.description = "Se substitue au header défini au niveau global"
|
||||
self.titre = "Logo en-tête"
|
||||
if self.logo_id.data == 'footer':
|
||||
if self.logo_id.data == "footer":
|
||||
self.description = "Se substitue au footer défini au niveau global"
|
||||
self.titre = "Logo pied de page"
|
||||
|
||||
def select_action(self, logo_data):
|
||||
if logo_data["logo_id"] and self.can_delete:
|
||||
return LogoDelete.build_action(logo_data)
|
||||
if logo_data["upload"] and self.upload.validate(form=self):
|
||||
return LogoUpdate.build_action(logo_data)
|
||||
def select_action(self):
|
||||
if self.do_delete.data and self.can_delete:
|
||||
return LogoDelete.build_action(self.data)
|
||||
if self.upload.data and self.validate():
|
||||
return LogoUpdate.build_action(self.data)
|
||||
return None
|
||||
|
||||
|
||||
|
@ -208,15 +219,13 @@ class DeptForm(FlaskForm):
|
|||
return None
|
||||
return True
|
||||
|
||||
def select_action(self, dept_data):
|
||||
action = self.add_logo.form.select_action(dept_data["add_logo"])
|
||||
def select_action(self):
|
||||
action = self.add_logo.form.select_action()
|
||||
if action:
|
||||
return action
|
||||
if action:
|
||||
return action
|
||||
for logo_data in dept_data["logos"]:
|
||||
logo_form = self.index[logo_data["logo_id"]]
|
||||
action = logo_form.select_action(logo_data)
|
||||
for logo_entry in self.logos.entries:
|
||||
logo_form = logo_entry.form
|
||||
action = logo_form.select_action()
|
||||
if action:
|
||||
return action
|
||||
return None
|
||||
|
@ -239,6 +248,7 @@ def _make_dept_id_name():
|
|||
depts.append((dept.id, dept.acronym))
|
||||
return depts
|
||||
|
||||
|
||||
def _ordered_logos(modele):
|
||||
"""sort logoname alphabetically but header and footer moved at start. (since there is no space in logoname)"""
|
||||
|
||||
|
@ -252,13 +262,13 @@ def _ordered_logos(modele):
|
|||
order = sorted(modele.keys(), key=sort)
|
||||
return order
|
||||
|
||||
|
||||
def _make_dept_data(dept_id, dept_name, modele):
|
||||
data = {}
|
||||
dept_key = dept_id or dept_name
|
||||
dept_key = dept_id_to_key(dept_id)
|
||||
data = {
|
||||
"dept_key": dept_key,
|
||||
"dept_name": dept_name,
|
||||
"add_logo": {"dept_id": dept_key},
|
||||
"add_logo": {"dept_key": dept_key},
|
||||
}
|
||||
logos = []
|
||||
if modele is not None:
|
||||
|
@ -267,6 +277,7 @@ def _make_dept_data(dept_id, dept_name, modele):
|
|||
data["logos"] = logos
|
||||
return data
|
||||
|
||||
|
||||
def _make_depts_data(modele):
|
||||
data = []
|
||||
for dept_id, dept_name in _make_dept_id_name():
|
||||
|
@ -277,6 +288,7 @@ def _make_depts_data(modele):
|
|||
)
|
||||
return data
|
||||
|
||||
|
||||
def _make_data(bonus_sport, modele):
|
||||
data = {
|
||||
"bonus_sport_func_name": bonus_sport,
|
||||
|
@ -284,6 +296,7 @@ def _make_data(bonus_sport, modele):
|
|||
}
|
||||
return data
|
||||
|
||||
|
||||
class ScoDocConfigurationForm(FlaskForm):
|
||||
"Panneau de configuration général"
|
||||
bonus_sport_func_name = SelectField(
|
||||
|
@ -340,30 +353,34 @@ class ScoDocConfigurationForm(FlaskForm):
|
|||
return None
|
||||
return dept_form.get_form(logoname)
|
||||
|
||||
def select_action(self, data):
|
||||
if BonusSportUpdate.build_action(data) and self.bonus_sport_func_name.validate(
|
||||
form=self
|
||||
def select_action(self):
|
||||
if (
|
||||
self.data["bonus_sport_func_name"]
|
||||
!= ScoDocSiteConfig.get_bonus_sport_func_name()
|
||||
):
|
||||
return BonusSportUpdate(data)
|
||||
for dept_data in data["depts"]:
|
||||
dept_form = self.index[str(dept_data["dept_key"])]
|
||||
action = dept_form.select_action(dept_data)
|
||||
return BonusSportUpdate(self.data)
|
||||
for dept_entry in self.depts:
|
||||
dept_form = dept_entry.form
|
||||
action = dept_form.select_action()
|
||||
if action:
|
||||
return action
|
||||
return None
|
||||
|
||||
|
||||
def configuration():
|
||||
"""Panneau de configuration général"""
|
||||
auth_name = str(current_user)
|
||||
if not current_user.is_administrator():
|
||||
raise AccessDenied("invalid user (%s) must be SuperAdmin" % auth_name)
|
||||
form = ScoDocConfigurationForm(data=_make_data(
|
||||
bonus_sport=ScoDocSiteConfig.get_bonus_sport_func_name(),
|
||||
modele=sco_logos.list_logos(),
|
||||
))
|
||||
form = ScoDocConfigurationForm(
|
||||
data=_make_data(
|
||||
bonus_sport=ScoDocSiteConfig.get_bonus_sport_func_name(),
|
||||
modele=sco_logos.list_logos(),
|
||||
)
|
||||
)
|
||||
if form.is_submitted():
|
||||
breakpoint()
|
||||
action = form.select_action(form.data)
|
||||
action = form.select_action()
|
||||
if action:
|
||||
action.execute()
|
||||
flash(action.message)
|
||||
|
|
|
@ -236,7 +236,7 @@ def feuille_preparation_jury(formsemestre_id):
|
|||
if sco_preferences.get_preference("prepa_jury_nip"):
|
||||
cells.append(ws.make_cell(etud["code_nip"]))
|
||||
if sco_preferences.get_preference("prepa_jury_ine"):
|
||||
cells.append(ws.make_cell(["code_ine"]))
|
||||
cells.append(ws.make_cell(etud["code_ine"]))
|
||||
cells += ws.make_row(
|
||||
[
|
||||
etudid,
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
Usage: <span style="font-family: system-ui">{{ logo_form.logo.get_usage() }}</span>
|
||||
</td><td class=""img-action">
|
||||
<p>Modifier l'image</p>
|
||||
<span class="wtf-field">{{ render_field(logo_form.upload, False) }}</span>
|
||||
<span class="wtf-field">{{ render_field(logo_form.upload, False, onchange="submit_form()") }}</span>
|
||||
{% if logo_form.can_delete %}
|
||||
<p>Supprimer l'image</p>
|
||||
{{ render_field(logo_form.do_delete, False, onSubmit="submit_form()") }}
|
||||
|
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 3.4 KiB |