forked from ScoDoc/ScoDoc
126 lines
4.0 KiB
Python
126 lines
4.0 KiB
Python
# -*- mode: python -*-
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
#
|
|
# ScoDoc
|
|
#
|
|
# Copyright (c) 1999 - 2021 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
|
|
#
|
|
##############################################################################
|
|
|
|
"""
|
|
Module main: page d'accueil, avec liste des départements
|
|
|
|
Emmanuel Viennet, 2021
|
|
"""
|
|
import flask
|
|
from flask import flash, url_for, redirect, render_template
|
|
from flask import request
|
|
from flask.app import Flask
|
|
from flask_login.utils import login_required
|
|
from flask_wtf import FlaskForm
|
|
from wtforms import SelectField, SubmitField
|
|
|
|
# from wtforms.validators import DataRequired
|
|
|
|
from app.models import Departement, ScoDocSiteConfig
|
|
import sco_version
|
|
from app.scodoc import sco_find_etud
|
|
from app.decorators import admin_required
|
|
from app.scodoc.sco_permissions import Permission
|
|
from app.views import scodoc_bp as bp
|
|
|
|
|
|
@bp.route("/")
|
|
@bp.route("/ScoDoc")
|
|
@bp.route("/ScoDoc/index")
|
|
def index():
|
|
"Page d'accueil: liste des départements"
|
|
depts = (
|
|
Departement.query.filter_by(visible=True).order_by(Departement.acronym).all()
|
|
)
|
|
return render_template(
|
|
"scodoc.html",
|
|
title=sco_version.SCONAME,
|
|
current_app=flask.current_app,
|
|
depts=depts,
|
|
Permission=Permission,
|
|
)
|
|
|
|
|
|
@bp.route("/ScoDoc/table_etud_in_accessible_depts", methods=["POST"])
|
|
@login_required
|
|
def table_etud_in_accessible_depts():
|
|
"""recherche étudiants sur plusieurs départements"""
|
|
return sco_find_etud.table_etud_in_accessible_depts(expnom=request.form["expnom"])
|
|
|
|
|
|
# ---- CONFIGURATION
|
|
|
|
|
|
class ScoDocConfigurationForm(FlaskForm):
|
|
"Panneau de configuration général"
|
|
# très préliminaire ;-)
|
|
# On veut y mettre la fonction bonus et ensuite les 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_func_names()
|
|
],
|
|
)
|
|
submit = SubmitField("Enregistrer")
|
|
|
|
|
|
@bp.route("/ScoDoc/configuration", methods=["GET", "POST"])
|
|
@admin_required
|
|
def configuration():
|
|
"Panneau de configuration général"
|
|
form = ScoDocConfigurationForm(
|
|
bonus_sport_func_name=ScoDocSiteConfig.get_bonus_sport_func_name()
|
|
)
|
|
if form.validate_on_submit():
|
|
ScoDocSiteConfig.set_bonus_sport_func(form.bonus_sport_func_name.data)
|
|
flash(f"Configuration enregistrée")
|
|
return redirect(url_for("scodoc.index"))
|
|
return render_template(
|
|
"configuration.html",
|
|
title="Configuration ScoDoc",
|
|
form=form,
|
|
# bonus_sport_func_name=ScoDocSiteConfig.get_bonus_sport_func(),
|
|
)
|
|
|
|
|
|
# essais
|
|
# @bp.route("/testlog")
|
|
# def testlog():
|
|
# import time
|
|
# from flask import current_app
|
|
# from app import log
|
|
|
|
# log(f"testlog called: handlers={current_app.logger.handlers}")
|
|
# current_app.logger.debug(f"testlog message DEBUG")
|
|
# current_app.logger.info(f"testlog message INFO")
|
|
# current_app.logger.warning(f"testlog message WARNING")
|
|
# current_app.logger.error(f"testlog message ERROR")
|
|
# current_app.logger.critical(f"testlog message CRITICAL")
|
|
# raise SyntaxError("une erreur de syntaxe")
|
|
# return "testlog completed at " + str(time.time())
|