Config: activation du module entreprises

This commit is contained in:
Emmanuel Viennet 2022-03-22 22:14:45 +01:00
parent cdb945e7b5
commit ba78322757
7 changed files with 111 additions and 32 deletions

View File

@ -13,7 +13,6 @@ Les classes de Bonus fournissent deux méthodes:
"""
import datetime
import math
import numpy as np
import pandas as pd

View File

@ -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 <em>entreprises</em>")
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",
)

View File

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

View File

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

View File

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

View File

@ -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 }}</a></li>
{% 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() %}
<li><a href="{{ url_for('entreprises.index') }}">Entreprises</a></li>
{% endif %}
</ul>

View File

@ -21,33 +21,53 @@
{% block app_content %}
<form id="configuration_form" class="sco-form" action="" method="post" enctype="multipart/form-data" novalidate>
{{ form.hidden_tag() }}
<h1>Configuration générale</h1>
<div class="sco_help">Les paramètres donnés ici s'appliquent à tout ScoDoc (tous les départements):</div>
<div class="sco_help greenboldtext">Les paramètres donnés ici s'appliquent à tout ScoDoc (tous les départements).</div>
<section>
<h2>Calcul des "bonus" définis par l'établissement</h2>
<form id="configuration_form" class="sco-form" action="" method="post" enctype="multipart/form-data" novalidate>
{{ form_bonus.hidden_tag() }}
<div class="row">
<div class="col-md-4">
{{ wtf.quick_form(form) }}
{{ wtf.quick_form(form_bonus) }}
</div>
</div>
<div id="bonus_description"></div>
<h1>Gestion des images: logos, signatures, ...</h1>
<div class="sco_help">Ces images peuvent être intégrées dans les documents
générés par ScoDoc: bulletins, PV, etc.</div>
<p><a class="stdlink" href="{{url_for('scodoc.configure_logos')}}">configuration des images et logos</a>
</p>
<h1>Exports Apogée</h1>
<p><a class="stdlink" href="{{url_for('scodoc.config_codes_decisions')}}">configuration des codes de décision</a></p>
<h1>Utilisateurs</h1>
<p><a class="stdlink" href="{{url_for('auth.reset_standard_roles_permissions')}}">remettre les permissions des
rôles standards à leurs valeurs par défaut</a> (efface les modifications apportées)</p>
</div>
</form>
</section>
<section>
<h2>Gestion des images: logos, signatures, ...</h2>
<div class="sco_help">Ces images peuvent être intégrées dans les documents
générés par ScoDoc: bulletins, PV, etc.
</div>
<p><a class="stdlink" href="{{url_for('scodoc.configure_logos')}}">configuration des images et logos</a>
</p>
</section>
<section>
<h2>Exports Apogée</h2>
<p><a class="stdlink" href="{{url_for('scodoc.config_codes_decisions')}}">configuration des codes de décision</a></p>
</section>
<h2>Utilisateurs</h2>
<section>
<p><a class="stdlink" href="{{url_for('auth.reset_standard_roles_permissions')}}">remettre
les permissions des rôles standards à leurs valeurs par défaut</a> (efface les modifications apportées)
</p>
</section>
<h2>ScoDoc</h2>
<form id="configuration_form_scodoc" class="sco-form" action="" method="post" enctype="multipart/form-data" novalidate>
{{ form_scodoc.hidden_tag() }}
<div class="row">
<div class="col-md-4">
{{ wtf.quick_form(form_scodoc) }}
</div>
</div>
</form>
{% endblock %}
{% block scripts %}