diff --git a/app/forms/main/config_apo.py b/app/forms/main/config_apo.py index a655f450f7..6151f2f311 100644 --- a/app/forms/main/config_apo.py +++ b/app/forms/main/config_apo.py @@ -28,7 +28,6 @@ """ Formulaires configuration Exports Apogée (codes) """ -import re from flask import flash, url_for, redirect, render_template from flask_wtf import FlaskForm diff --git a/app/forms/main/config_forms.py b/app/forms/main/config_logos.py similarity index 92% rename from app/forms/main/config_forms.py rename to app/forms/main/config_logos.py index 26548f08da..91a73747ae 100644 --- a/app/forms/main/config_forms.py +++ b/app/forms/main/config_logos.py @@ -47,7 +47,6 @@ from app.scodoc.sco_config_actions import ( LogoDelete, LogoUpdate, LogoInsert, - BonusSportUpdate, ) from flask_login import current_user @@ -296,23 +295,15 @@ def _make_depts_data(modele): return data -def _make_data(bonus_sport, modele): +def _make_data(modele): data = { - "bonus_sport_func_name": bonus_sport, "depts": _make_depts_data(modele=modele), } return data -class ScoDocConfigurationForm(FlaskForm): - "Panneau de configuration général" - bonus_sport_func_name = SelectField( - label="Fonction de calcul des bonus sport&culture", - choices=[ - (x, x if x else "Aucune") - for x in ScoDocSiteConfig.get_bonus_sport_class_names() - ], - ) +class LogosConfigurationForm(FlaskForm): + "Panneau de configuration des logos" depts = FieldList(FormField(DeptForm)) def __init__(self, *args, **kwargs): @@ -361,11 +352,6 @@ class ScoDocConfigurationForm(FlaskForm): return dept_form.get_form(logoname) def select_action(self): - if ( - self.data["bonus_sport_func_name"] - != ScoDocSiteConfig.get_bonus_sport_class_name() - ): - return BonusSportUpdate(self.data) for dept_entry in self.depts: dept_form = dept_entry.form action = dept_form.select_action() @@ -374,14 +360,11 @@ class ScoDocConfigurationForm(FlaskForm): 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( +def config_logos(): + "Page de configuration des logos" + # nb: le contrôle d'accès (SuperAdmin) doit être fait dans la vue + form = LogosConfigurationForm( data=_make_data( - bonus_sport=ScoDocSiteConfig.get_bonus_sport_class_name(), modele=sco_logos.list_logos(), ) ) @@ -392,11 +375,11 @@ def configuration(): flash(action.message) return redirect( url_for( - "scodoc.configuration", + "scodoc.configure_logos", ) ) return render_template( - "configuration.html", + "config_logos.html", scodoc_dept=None, title="Configuration ScoDoc", form=form, diff --git a/app/forms/main/config_main.py b/app/forms/main/config_main.py new file mode 100644 index 0000000000..e0b349e49d --- /dev/null +++ b/app/forms/main/config_main.py @@ -0,0 +1,76 @@ +# -*- mode: python -*- +# -*- coding: utf-8 -*- + +############################################################################## +# +# ScoDoc +# +# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Emmanuel Viennet emmanuel.viennet@viennet.net +# +############################################################################## + +""" +Formulaires configuration Exports Apogée (codes) +""" + +from flask import flash, url_for, redirect, request, render_template +from flask_wtf import FlaskForm +from wtforms import SelectField, SubmitField + +import app +from app.models import ScoDocSiteConfig + + +class ScoDocConfigurationForm(FlaskForm): + "Panneau de configuration des logos" + bonus_sport_func_name = SelectField( + label="Fonction de calcul des bonus sport&culture", + choices=[ + (x, x if x else "Aucune") + for x in ScoDocSiteConfig.get_bonus_sport_class_names() + ], + ) + submit = SubmitField("Valider") + cancel = SubmitField("Annuler", render_kw={"formnovalidate": True}) + + +def configuration(): + "Page de configuration principale" + # nb: le contrôle d'accès (SuperAdmin) doit être fait dans la vue + form = ScoDocConfigurationForm( + data={ + "bonus_sport_func_name": ScoDocSiteConfig.get_bonus_sport_class_name(), + } + ) + if request.method == "POST" and form.cancel.data: # cancel button + return redirect(url_for("scodoc.index")) + if form.validate_on_submit(): + if ( + form.data["bonus_sport_func_name"] + != ScoDocSiteConfig.get_bonus_sport_class_name() + ): + ScoDocSiteConfig.set_bonus_sport_class(form.data["bonus_sport_func_name"]) + app.clear_scodoc_cache() + flash(f"Fonction bonus sport&culture configurée.") + return redirect(url_for("scodoc.index")) + + return render_template( + "configuration.html", + form=form, + ) diff --git a/app/scodoc/sco_config_actions.py b/app/scodoc/sco_config_actions.py index 949567ecad..f6ea96371c 100644 --- a/app/scodoc/sco_config_actions.py +++ b/app/scodoc/sco_config_actions.py @@ -152,28 +152,3 @@ class LogoInsert(Action): name=self.parameters["name"], dept_id=dept_id, ) - - -class BonusSportUpdate(Action): - """Action: Change bonus_sport_function_name. - bonus_sport_function_name: the new value""" - - def __init__(self, parameters): - super().__init__( - f"Changement du calcul de bonus sport pour ({parameters['bonus_sport_func_name']}).", - parameters, - ) - - @staticmethod - def build_action(parameters): - if ( - parameters["bonus_sport_func_name"] - != ScoDocSiteConfig.get_bonus_sport_class_name() - ): - return [BonusSportUpdate(parameters)] - return [] - - def execute(self): - current_app.logger.info(self.message) - ScoDocSiteConfig.set_bonus_sport_func(self.parameters["bonus_sport_func_name"]) - app.clear_scodoc_cache() diff --git a/app/scodoc/sco_preferences.py b/app/scodoc/sco_preferences.py index 6aba9694d9..dbbdd0ac5e 100644 --- a/app/scodoc/sco_preferences.py +++ b/app/scodoc/sco_preferences.py @@ -2019,7 +2019,7 @@ class BasePreferences(object): H = [ html_sco_header.sco_header(page_title="Préférences"), "
modification des logos du département (pour documents pdf)
""" # if current_user.is_administrator() # else "", diff --git a/app/static/js/configuration.js b/app/static/js/config_logos.js similarity index 54% rename from app/static/js/configuration.js rename to app/static/js/config_logos.js index b537d572f9..56b7cd27d5 100644 --- a/app/static/js/configuration.js +++ b/app/static/js/config_logos.js @@ -1,5 +1,5 @@ function submit_form() { - $("#configuration_form").submit(); + $("#config_logos_form").submit(); } $(function () { diff --git a/app/templates/config_logos.html b/app/templates/config_logos.html new file mode 100644 index 0000000000..f4bd543cb5 --- /dev/null +++ b/app/templates/config_logos.html @@ -0,0 +1,125 @@ +{# -*- mode: jinja-html -*- #} +{% extends 'base.html' %} +{% import 'bootstrap/wtf.html' as wtf %} + +{% macro render_field(field, with_label=True) %} +Modifier l'image
+ {{ render_field(logo_form.upload, False, onchange="submit_form()") }} + {% if logo_form.can_delete %} +Supprimer l'image
+ {{ render_field(logo_form.do_delete, False, onSubmit="submit_form()") }} + {% endif %} +Modifier l'image
- {{ render_field(logo_form.upload, False, onchange="submit_form()") }} - {% if logo_form.can_delete %} -Supprimer l'image
- {{ render_field(logo_form.do_delete, False, onSubmit="submit_form()") }} - {% endif %} -