From ba783227575d78e7e84feaa0c72d8098afedeb49 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 22 Mar 2022 22:14:45 +0100 Subject: [PATCH] Config: activation du module entreprises --- app/comp/bonus_spo.py | 1 - app/forms/main/config_main.py | 47 +++++++++++++++++++++------ app/models/config.py | 25 +++++++++++++++ app/scodoc/sco_utils.py | 7 +++++ app/static/css/scodoc.css | 5 +-- app/templates/base.html | 4 +-- app/templates/configuration.html | 54 ++++++++++++++++++++++---------- 7 files changed, 111 insertions(+), 32 deletions(-) diff --git a/app/comp/bonus_spo.py b/app/comp/bonus_spo.py index ece1d3611..5846e46f4 100644 --- a/app/comp/bonus_spo.py +++ b/app/comp/bonus_spo.py @@ -13,7 +13,6 @@ Les classes de Bonus fournissent deux méthodes: """ import datetime -import math import numpy as np import pandas as pd diff --git a/app/forms/main/config_main.py b/app/forms/main/config_main.py index d6536a8de..2c2aa3d5e 100644 --- a/app/forms/main/config_main.py +++ b/app/forms/main/config_main.py @@ -31,13 +31,14 @@ 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 +from wtforms import BooleanField, SelectField, SubmitField import app from app.models import ScoDocSiteConfig +import app.scodoc.sco_utils as scu -class ScoDocConfigurationForm(FlaskForm): +class BonusConfigurationForm(FlaskForm): "Panneau de configuration des logos" bonus_sport_func_name = SelectField( label="Fonction de calcul des bonus sport&culture", @@ -46,31 +47,57 @@ class ScoDocConfigurationForm(FlaskForm): for (name, displayed_name) in ScoDocSiteConfig.get_bonus_sport_class_list() ], ) - submit = SubmitField("Valider") - cancel = SubmitField("Annuler", render_kw={"formnovalidate": True}) + submit_bonus = SubmitField("Valider") + cancel_bonus = SubmitField("Annuler", render_kw={"formnovalidate": True}) + + +class ScoDocConfigurationForm(FlaskForm): + "Panneau de configuration avancée" + enable_entreprises = BooleanField("activer le module entreprises") + submit_scodoc = SubmitField("Valider") + cancel_scodoc = 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( + form_bonus = BonusConfigurationForm( data={ "bonus_sport_func_name": ScoDocSiteConfig.get_bonus_sport_class_name(), } ) - if request.method == "POST" and form.cancel.data: # cancel button + form_scodoc = ScoDocConfigurationForm( + data={"enable_entreprises": ScoDocSiteConfig.is_entreprises_enabled()} + ) + if request.method == "POST" and ( + form_bonus.cancel_bonus.data or form_scodoc.cancel_scodoc.data + ): # cancel button return redirect(url_for("scodoc.index")) - if form.validate_on_submit(): + if form_bonus.submit_bonus.data and form_bonus.validate(): if ( - form.data["bonus_sport_func_name"] + form_bonus.data["bonus_sport_func_name"] != ScoDocSiteConfig.get_bonus_sport_class_name() ): - ScoDocSiteConfig.set_bonus_sport_class(form.data["bonus_sport_func_name"]) + ScoDocSiteConfig.set_bonus_sport_class( + form_bonus.data["bonus_sport_func_name"] + ) app.clear_scodoc_cache() flash(f"Fonction bonus sport&culture configurée.") return redirect(url_for("scodoc.index")) + elif form_scodoc.submit_scodoc.data and form_scodoc.validate(): + if ScoDocSiteConfig.enable_entreprises( + enabled=form_scodoc.data["enable_entreprises"] + ): + flash( + "Module entreprise " + + ("activé" if form_scodoc.data["enable_entreprises"] else "désactivé") + ) + return redirect(url_for("scodoc.index")) return render_template( "configuration.html", - form=form, + form_bonus=form_bonus, + form_scodoc=form_scodoc, + scu=scu, + title="Configuration", ) diff --git a/app/models/config.py b/app/models/config.py index 8a56d3879..1271beeb9 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -69,6 +69,7 @@ class ScoDocSiteConfig(db.Model): "INSTITUTION_ADDRESS": str, "INSTITUTION_CITY": str, "DEFAULT_PDF_FOOTER_TEMPLATE": str, + "enable_entreprises": bool, } def __init__(self, name, value): @@ -207,3 +208,27 @@ class ScoDocSiteConfig(db.Model): cfg.value = code_apo db.session.add(cfg) db.session.commit() + + @classmethod + def is_entreprises_enabled(cls) -> bool: + """True si on doit activer le module entreprise""" + cfg = ScoDocSiteConfig.query.filter_by(name="enable_entreprises").first() + if (cfg is None) or not cfg.value: + return False + return True + + @classmethod + def enable_entreprises(cls, enabled=True) -> bool: + """Active (ou déactive) le module entreprises. True si changement.""" + if enabled != ScoDocSiteConfig.is_entreprises_enabled(): + cfg = ScoDocSiteConfig.query.filter_by(name="enable_entreprises").first() + if cfg is None: + cfg = ScoDocSiteConfig( + name="enable_entreprises", value="on" if enabled else "" + ) + else: + cfg.value = "on" if enabled else "" + db.session.add(cfg) + db.session.commit() + return True + return False diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index 6df7ed6eb..a0bb78c61 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -1038,3 +1038,10 @@ def objects_renumber(db, obj_list) -> None: obj.numero = i db.session.add(obj) db.session.commit() + + +# Pour accès depuis les templates jinja +def is_entreprises_enabled(): + from app.models import ScoDocSiteConfig + + return ScoDocSiteConfig.is_entreprises_enabled() diff --git a/app/static/css/scodoc.css b/app/static/css/scodoc.css index 6c0b06b8f..086a130e4 100644 --- a/app/static/css/scodoc.css +++ b/app/static/css/scodoc.css @@ -872,9 +872,10 @@ a.discretelink:hover { div.sco_help { margin-top: 12px; - margin-bottom: 3px; + margin-bottom: 4px; + padding: 8px; + border-radius: 4px; font-style: italic; - color: navy; background-color: rgb(200,200,220); } diff --git a/app/templates/base.html b/app/templates/base.html index 658f41eb2..29f4455b0 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -8,7 +8,7 @@ {% endblock %} {% block title %} -{% if title %}{{ title }} - ScoDoc{% else %}Welcome to ScoDoc{% endif %} +{% if title %}{{ title }} - ScoDoc{% else %}ScoDoc{% endif %} {% endblock %} {% block navbar %} @@ -36,7 +36,7 @@ url_for('scolar.index_html', scodoc_dept=g.scodoc_dept) }}">Dept. {{ g.scodoc_dept }} {% endif %} - {% if not current_user.is_anonymous and current_user.has_permission(current_user.Permission.RelationsEntreprisesView, None) %} + {% if not current_user.is_anonymous and current_user.has_permission(current_user.Permission.RelationsEntreprisesView, None) and scu.is_entreprises_enabled() %}
  • Entreprises
  • {% endif %} diff --git a/app/templates/configuration.html b/app/templates/configuration.html index 33912fbf9..e6694e1d0 100644 --- a/app/templates/configuration.html +++ b/app/templates/configuration.html @@ -21,33 +21,53 @@ {% block app_content %} -
    - {{ form.hidden_tag() }} +

    Configuration générale

    +
    Les paramètres donnés ici s'appliquent à tout ScoDoc (tous les départements).
    -

    Configuration générale

    -
    Les paramètres donnés ici s'appliquent à tout ScoDoc (tous les départements):
    +
    +

    Calcul des "bonus" définis par l'établissement

    + + {{ form_bonus.hidden_tag() }}
    - {{ wtf.quick_form(form) }} + {{ wtf.quick_form(form_bonus) }}
    + -

    Gestion des images: logos, signatures, ...

    -
    Ces images peuvent être intégrées dans les documents - générés par ScoDoc: bulletins, PV, etc.
    -

    configuration des images et logos -

    +
    -

    Exports Apogée

    -

    configuration des codes de décision

    - -

    Utilisateurs

    -

    remettre les permissions des - rôles standards à leurs valeurs par défaut (efface les modifications apportées)

    +
    +

    Gestion des images: logos, signatures, ...

    +
    Ces images peuvent être intégrées dans les documents + générés par ScoDoc: bulletins, PV, etc.
    - +

    configuration des images et logos +

    +
    +
    +

    Exports Apogée

    +

    configuration des codes de décision

    +
    + +

    Utilisateurs

    +
    +

    remettre + les permissions des rôles standards à leurs valeurs par défaut (efface les modifications apportées) +

    +
    + +

    ScoDoc

    +
    + {{ form_scodoc.hidden_tag() }} +
    +
    + {{ wtf.quick_form(form_scodoc) }} +
    +
    +
    {% endblock %} {% block scripts %}