2022-01-25 23:48:39 +01:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# ScoDoc
|
|
|
|
#
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2022-01-25 23:48:39 +01:00
|
|
|
#
|
|
|
|
# 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)
|
|
|
|
"""
|
2023-10-22 21:54:23 +02:00
|
|
|
import time
|
2022-01-25 23:48:39 +01:00
|
|
|
|
|
|
|
from flask import flash, url_for, redirect, request, render_template
|
|
|
|
from flask_wtf import FlaskForm
|
2023-02-28 19:43:48 +01:00
|
|
|
from wtforms import BooleanField, SelectField, StringField, SubmitField
|
|
|
|
from wtforms.validators import Email, Optional
|
2022-01-25 23:48:39 +01:00
|
|
|
import app
|
|
|
|
from app.models import ScoDocSiteConfig
|
2022-03-22 22:14:45 +01:00
|
|
|
import app.scodoc.sco_utils as scu
|
2022-01-25 23:48:39 +01:00
|
|
|
|
|
|
|
|
2022-03-22 22:14:45 +01:00
|
|
|
class BonusConfigurationForm(FlaskForm):
|
2022-01-25 23:48:39 +01:00
|
|
|
"Panneau de configuration des logos"
|
|
|
|
bonus_sport_func_name = SelectField(
|
|
|
|
label="Fonction de calcul des bonus sport&culture",
|
|
|
|
choices=[
|
2022-01-27 18:12:40 +01:00
|
|
|
(name, displayed_name if name else "Aucune")
|
|
|
|
for (name, displayed_name) in ScoDocSiteConfig.get_bonus_sport_class_list()
|
2022-01-25 23:48:39 +01:00
|
|
|
],
|
|
|
|
)
|
2024-03-27 16:27:45 +01:00
|
|
|
submit_bonus = SubmitField("Enregistrer ce bonus")
|
2022-03-22 22:14:45 +01:00
|
|
|
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>")
|
2024-03-27 16:27:45 +01:00
|
|
|
disable_passerelle = BooleanField( # disable car par défaut activée
|
|
|
|
"""cacher les fonctions liées à une passerelle de publication des résultats vers les étudiants ("œil"). N'affecte pas l'API, juste la présentation."""
|
|
|
|
)
|
2022-11-13 14:55:18 +01:00
|
|
|
month_debut_annee_scolaire = SelectField(
|
|
|
|
label="Mois de début des années scolaires",
|
|
|
|
description="""Date pivot. En France métropolitaine, août.
|
|
|
|
S'applique à tous les départements.""",
|
|
|
|
choices=[
|
|
|
|
(i, name.capitalize()) for (i, name) in enumerate(scu.MONTH_NAMES, start=1)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
month_debut_periode2 = SelectField(
|
|
|
|
label="Mois de début deuxième période de l'année",
|
|
|
|
description="""Date pivot. En France métropolitaine, décembre.
|
|
|
|
S'applique à tous les départements.""",
|
|
|
|
choices=[
|
|
|
|
(i, name.capitalize()) for (i, name) in enumerate(scu.MONTH_NAMES, start=1)
|
|
|
|
],
|
|
|
|
)
|
2023-02-28 19:43:48 +01:00
|
|
|
email_from_addr = StringField(
|
|
|
|
label="Adresse source des mails",
|
|
|
|
description="""adresse email source (from) des mails émis par ScoDoc.
|
|
|
|
Attention: si ce champ peut aussi être défini dans chaque département.""",
|
|
|
|
validators=[Optional(), Email()],
|
|
|
|
)
|
2024-01-09 19:56:05 +01:00
|
|
|
user_require_email_institutionnel = BooleanField(
|
|
|
|
"imposer la saisie du mail institutionnel dans le formulaire de création utilisateur"
|
|
|
|
)
|
2023-12-12 15:32:47 +01:00
|
|
|
disable_bul_pdf = BooleanField(
|
|
|
|
"interdire les exports des bulletins en PDF (déconseillé)"
|
|
|
|
)
|
2024-03-27 16:27:45 +01:00
|
|
|
submit_scodoc = SubmitField("Enregistrer ces paramètres")
|
2022-03-22 22:14:45 +01:00
|
|
|
cancel_scodoc = SubmitField("Annuler", render_kw={"formnovalidate": True})
|
2022-01-25 23:48:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
def configuration():
|
|
|
|
"Page de configuration principale"
|
|
|
|
# nb: le contrôle d'accès (SuperAdmin) doit être fait dans la vue
|
2022-03-22 22:14:45 +01:00
|
|
|
form_bonus = BonusConfigurationForm(
|
2022-01-25 23:48:39 +01:00
|
|
|
data={
|
|
|
|
"bonus_sport_func_name": ScoDocSiteConfig.get_bonus_sport_class_name(),
|
|
|
|
}
|
|
|
|
)
|
2022-03-22 22:14:45 +01:00
|
|
|
form_scodoc = ScoDocConfigurationForm(
|
2022-11-13 14:55:18 +01:00
|
|
|
data={
|
|
|
|
"enable_entreprises": ScoDocSiteConfig.is_entreprises_enabled(),
|
2024-03-27 16:27:45 +01:00
|
|
|
"disable_passerelle": ScoDocSiteConfig.is_passerelle_disabled(),
|
2022-11-13 14:55:18 +01:00
|
|
|
"month_debut_annee_scolaire": ScoDocSiteConfig.get_month_debut_annee_scolaire(),
|
|
|
|
"month_debut_periode2": ScoDocSiteConfig.get_month_debut_periode2(),
|
2023-02-28 19:43:48 +01:00
|
|
|
"email_from_addr": ScoDocSiteConfig.get("email_from_addr"),
|
2023-09-10 21:16:31 +02:00
|
|
|
"disable_bul_pdf": ScoDocSiteConfig.is_bul_pdf_disabled(),
|
2024-01-09 19:56:05 +01:00
|
|
|
"user_require_email_institutionnel": ScoDocSiteConfig.is_user_require_email_institutionnel_enabled(),
|
2022-11-13 14:55:18 +01:00
|
|
|
}
|
2022-03-22 22:14:45 +01:00
|
|
|
)
|
|
|
|
if request.method == "POST" and (
|
|
|
|
form_bonus.cancel_bonus.data or form_scodoc.cancel_scodoc.data
|
|
|
|
): # cancel button
|
2022-01-25 23:48:39 +01:00
|
|
|
return redirect(url_for("scodoc.index"))
|
2022-03-22 22:14:45 +01:00
|
|
|
if form_bonus.submit_bonus.data and form_bonus.validate():
|
2022-01-25 23:48:39 +01:00
|
|
|
if (
|
2022-03-22 22:14:45 +01:00
|
|
|
form_bonus.data["bonus_sport_func_name"]
|
2022-01-25 23:48:39 +01:00
|
|
|
!= ScoDocSiteConfig.get_bonus_sport_class_name()
|
|
|
|
):
|
2022-03-22 22:14:45 +01:00
|
|
|
ScoDocSiteConfig.set_bonus_sport_class(
|
|
|
|
form_bonus.data["bonus_sport_func_name"]
|
|
|
|
)
|
2022-01-25 23:48:39 +01:00
|
|
|
app.clear_scodoc_cache()
|
2022-05-18 20:41:55 +02:00
|
|
|
flash("""Fonction bonus sport&culture configurée.""")
|
|
|
|
else:
|
|
|
|
flash("Fonction bonus inchangée.")
|
2022-01-25 23:48:39 +01:00
|
|
|
return redirect(url_for("scodoc.index"))
|
2022-03-22 22:14:45 +01:00
|
|
|
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é")
|
|
|
|
)
|
2024-03-27 16:27:45 +01:00
|
|
|
if ScoDocSiteConfig.disable_passerelle(
|
|
|
|
disabled=form_scodoc.data["disable_passerelle"]
|
|
|
|
):
|
|
|
|
flash(
|
|
|
|
"Fonction passerelle "
|
|
|
|
+ ("cachées" if form_scodoc.data["disable_passerelle"] else "montrées")
|
|
|
|
)
|
2022-11-13 14:55:18 +01:00
|
|
|
if ScoDocSiteConfig.set_month_debut_annee_scolaire(
|
|
|
|
int(form_scodoc.data["month_debut_annee_scolaire"])
|
|
|
|
):
|
|
|
|
flash(
|
|
|
|
f"""Début des années scolaires fixé au mois de {
|
|
|
|
scu.MONTH_NAMES[ScoDocSiteConfig.get_month_debut_annee_scolaire()-1]
|
|
|
|
}"""
|
|
|
|
)
|
|
|
|
if ScoDocSiteConfig.set_month_debut_periode2(
|
|
|
|
int(form_scodoc.data["month_debut_periode2"])
|
|
|
|
):
|
|
|
|
flash(
|
|
|
|
f"""Début des années scolaires fixé au mois de {
|
|
|
|
scu.MONTH_NAMES[ScoDocSiteConfig.get_month_debut_periode2()-1]
|
|
|
|
}"""
|
|
|
|
)
|
2023-02-28 19:43:48 +01:00
|
|
|
if ScoDocSiteConfig.set("email_from_addr", form_scodoc.data["email_from_addr"]):
|
|
|
|
flash("Adresse email origine enregistrée")
|
2023-09-10 21:16:31 +02:00
|
|
|
if ScoDocSiteConfig.disable_bul_pdf(
|
|
|
|
enabled=form_scodoc.data["disable_bul_pdf"]
|
|
|
|
):
|
|
|
|
flash(
|
|
|
|
"Exports PDF "
|
|
|
|
+ ("désactivés" if form_scodoc.data["disable_bul_pdf"] else "réactivés")
|
|
|
|
)
|
2024-01-09 19:56:05 +01:00
|
|
|
if ScoDocSiteConfig.set(
|
|
|
|
"user_require_email_institutionnel",
|
|
|
|
"on" if form_scodoc.data["user_require_email_institutionnel"] else "",
|
|
|
|
):
|
|
|
|
flash(
|
|
|
|
(
|
|
|
|
"impose"
|
|
|
|
if form_scodoc.data["user_require_email_institutionnel"]
|
|
|
|
else "n'impose pas"
|
|
|
|
)
|
|
|
|
+ " la saisie du mail institutionnel des utilisateurs"
|
|
|
|
)
|
2022-03-22 22:14:45 +01:00
|
|
|
return redirect(url_for("scodoc.index"))
|
2022-01-25 23:48:39 +01:00
|
|
|
|
|
|
|
return render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"configuration.j2",
|
2022-03-22 22:14:45 +01:00
|
|
|
form_bonus=form_bonus,
|
|
|
|
form_scodoc=form_scodoc,
|
|
|
|
scu=scu,
|
2023-10-22 21:54:23 +02:00
|
|
|
time=time,
|
2022-03-22 22:14:45 +01:00
|
|
|
title="Configuration",
|
2022-01-25 23:48:39 +01:00
|
|
|
)
|