forked from ScoDoc/ScoDoc
136 lines
5.5 KiB
Python
136 lines
5.5 KiB
Python
# -*- 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 BooleanField, SelectField, SubmitField
|
|
from wtforms import SelectField, SubmitField, StringField, BooleanField, IntegerField
|
|
|
|
import app
|
|
from app.models import ScoDocSiteConfig
|
|
import app.scodoc.sco_utils as scu
|
|
from app.models.config import SiteConfig
|
|
|
|
|
|
class BonusConfigurationForm(FlaskForm):
|
|
"Panneau de configuration des logos"
|
|
bonus_sport_func_name = SelectField(
|
|
label="Fonction de calcul des bonus sport&culture",
|
|
choices=[
|
|
(name, displayed_name if name else "Aucune")
|
|
for (name, displayed_name) in ScoDocSiteConfig.get_bonus_sport_class_list()
|
|
],
|
|
)
|
|
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})
|
|
default_pdf_footer_template = StringField(label="Pied de page par défaut des documents PDF")
|
|
|
|
custom_html_header = StringField(label="Fichier d'entete html")
|
|
custom_html_footer = StringField(label="fichier pied de page html")
|
|
custom_html_header_cnx = StringField(label="Fichier d'entete html (connexion)")
|
|
custom_html_footer_cnx = StringField(label="fichier pied de page html (connexion)")
|
|
|
|
capitalize_all_ues = BooleanField(label="Capitalise toutes les UE des semestres validés (règles DUT)")
|
|
allow_null_prenom = BooleanField(label="Autorise les étudiants sans prénom (UCAC)")
|
|
publish_portal_photo_url = BooleanField(label="Si pas de photo et portail, publie l'url (était vrai jusqu'en oct 2016)")
|
|
|
|
logo_header_height = IntegerField(label="hauteur en mm du logo d'entête")
|
|
logo_footer_height = IntegerField(label="hauteur en mm du logo de pied de page")
|
|
alwways_require_ine = BooleanField(label="Rendre l'INE obligatoire")
|
|
etud_max_filesize = IntegerField(label="Taille maximale des fichiers archives étudiants en octets")
|
|
|
|
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_bonus = BonusConfigurationForm(
|
|
data={
|
|
"bonus_sport_func_name": ScoDocSiteConfig.get_bonus_sport_class_name(),
|
|
}
|
|
)
|
|
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
|
|
form = ScoDocConfigurationForm(data=SiteConfig.get_editable_data())
|
|
if request.method == "POST" and form.cancel.data: # cancel button
|
|
return redirect(url_for("scodoc.index"))
|
|
if form_bonus.submit_bonus.data and form_bonus.validate():
|
|
if (
|
|
form_bonus.data["bonus_sport_func_name"]
|
|
!= ScoDocSiteConfig.get_bonus_sport_class_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.")
|
|
if form.validate_on_submit():
|
|
modified = set()
|
|
for c in SiteConfig:
|
|
if c.editable():
|
|
if form.data[c.db_name()] != c.get_value():
|
|
c.set_value(form.data[c.db_name()])
|
|
app.clear_scodoc_cache()
|
|
modified.add(c)
|
|
|
|
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_bonus=form_bonus,
|
|
form_scodoc=form_scodoc,
|
|
scu=scu,
|
|
title="Configuration",
|
|
)
|