2021-05-29 18:22:51 +02:00
|
|
|
# -*- coding: UTF-8 -*
|
2024-07-12 16:40:46 +02:00
|
|
|
"""ScoDoc Flask views"""
|
|
|
|
|
2021-10-03 18:19:51 +02:00
|
|
|
import datetime
|
2024-04-06 12:16:53 +02:00
|
|
|
from functools import cached_property
|
2021-10-03 18:19:51 +02:00
|
|
|
|
2021-05-29 18:22:51 +02:00
|
|
|
from flask import Blueprint
|
2021-12-04 21:06:32 +01:00
|
|
|
from flask import g, current_app, request
|
2021-10-03 18:19:51 +02:00
|
|
|
from flask_login import current_user
|
|
|
|
|
|
|
|
from app import db
|
2021-12-04 21:06:32 +01:00
|
|
|
from app.models import Identite
|
|
|
|
from app.models.formsemestre import FormSemestre
|
2021-07-20 17:32:04 +02:00
|
|
|
from app.scodoc import notesdb as ndb
|
2023-06-30 15:34:50 +02:00
|
|
|
from app.scodoc import sco_assiduites
|
2021-12-04 21:06:32 +01:00
|
|
|
from app.scodoc import sco_formsemestre_status
|
|
|
|
from app.scodoc import sco_preferences
|
2024-01-21 18:07:56 +01:00
|
|
|
from app.scodoc.html_sidebar import retreive_formsemestre_from_request
|
2021-12-04 21:06:32 +01:00
|
|
|
from app.scodoc.sco_permissions import Permission
|
|
|
|
from app.scodoc import sco_utils as scu
|
2022-02-17 22:40:11 +01:00
|
|
|
import sco_version
|
2021-05-29 18:22:51 +02:00
|
|
|
|
2021-07-04 12:32:13 +02:00
|
|
|
scodoc_bp = Blueprint("scodoc", __name__)
|
2021-05-31 00:14:15 +02:00
|
|
|
scolar_bp = Blueprint("scolar", __name__)
|
2021-05-29 18:22:51 +02:00
|
|
|
notes_bp = Blueprint("notes", __name__)
|
2021-06-26 21:57:54 +02:00
|
|
|
users_bp = Blueprint("users", __name__)
|
2021-05-31 00:14:15 +02:00
|
|
|
absences_bp = Blueprint("absences", __name__)
|
2023-04-17 15:44:55 +02:00
|
|
|
assiduites_bp = Blueprint("assiduites", __name__)
|
2021-05-29 18:22:51 +02:00
|
|
|
|
2021-06-16 16:59:31 +02:00
|
|
|
|
2021-08-13 00:34:58 +02:00
|
|
|
# Cette fonction est bien appelée avant toutes les requêtes
|
|
|
|
# de tous les blueprints
|
|
|
|
# mais apparemment elle n'a pas acces aux arguments
|
2021-07-20 17:32:04 +02:00
|
|
|
@scodoc_bp.before_app_request
|
2021-08-13 00:34:58 +02:00
|
|
|
def start_scodoc_request():
|
|
|
|
"""Affecte toutes les requêtes, de tous les blueprints"""
|
2021-10-04 00:22:44 +02:00
|
|
|
# current_app.logger.info(f"start_scodoc_request")
|
2021-08-13 00:34:58 +02:00
|
|
|
ndb.open_db_connection()
|
2021-10-16 19:20:36 +02:00
|
|
|
if current_user and current_user.is_authenticated:
|
2021-10-03 18:19:51 +02:00
|
|
|
current_user.last_seen = datetime.datetime.utcnow()
|
|
|
|
db.session.commit()
|
2021-10-04 22:05:05 +02:00
|
|
|
# caches locaux (durée de vie=la requête en cours)
|
|
|
|
g.stored_get_formsemestre = {}
|
|
|
|
# g.stored_etud_info = {} optim en cours, voir si utile
|
2021-07-20 17:32:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
@scodoc_bp.teardown_app_request
|
|
|
|
def close_dept_db_connection(arg):
|
2021-08-13 00:34:58 +02:00
|
|
|
# current_app.logger.info("close_db_connection")
|
|
|
|
ndb.close_db_connection()
|
2021-12-04 21:06:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ScoData:
|
|
|
|
"""Classe utilisée pour passer des valeurs aux vues (templates)"""
|
|
|
|
|
2023-07-16 19:59:45 +02:00
|
|
|
def __init__(self, etud: Identite = None, formsemestre: FormSemestre = None):
|
2021-12-04 21:06:32 +01:00
|
|
|
# Champs utilisés par toutes les pages ScoDoc (sidebar, en-tête)
|
|
|
|
self.Permission = Permission
|
|
|
|
self.scu = scu
|
2022-02-17 22:40:11 +01:00
|
|
|
self.SCOVERSION = sco_version.SCOVERSION
|
2024-04-06 12:16:53 +02:00
|
|
|
self._init_etud = etud
|
|
|
|
self._init_formsemestre = formsemestre
|
|
|
|
# les comptes d'absences sont initialisés lors de l'accès à etud_cur_sem
|
|
|
|
self.nb_abs_nj = 0
|
|
|
|
self.nb_abs_just = 0
|
|
|
|
self.nb_abs = 0
|
|
|
|
# .etud, .formsemestre, etc. sont des cached_property
|
|
|
|
# car ScoData() est créé par @context_processor
|
|
|
|
# AVANT le décorateur scodoc qui initialise g.scodoc_xxx
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def etud(self) -> Identite | None:
|
|
|
|
"Informations étudiant courant, si sélectionné"
|
|
|
|
if self._init_etud is None:
|
2022-03-07 21:49:11 +01:00
|
|
|
etudid = g.get("etudid", None)
|
|
|
|
if etudid is None:
|
|
|
|
if request.method == "GET":
|
|
|
|
etudid = request.args.get("etudid", None)
|
|
|
|
elif request.method == "POST":
|
|
|
|
etudid = request.form.get("etudid", None)
|
|
|
|
if etudid is not None:
|
2024-04-06 12:16:53 +02:00
|
|
|
return Identite.get_etud(etudid)
|
|
|
|
return self._init_etud
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def etud_cur_sem(self) -> FormSemestre | None:
|
|
|
|
"le semestre courant de l'étudiant courant"
|
|
|
|
etud = self.etud
|
|
|
|
if etud is None:
|
|
|
|
return None
|
|
|
|
ins = self.etud.inscription_courante()
|
|
|
|
cur_sem = ins.formsemestre
|
|
|
|
if ins:
|
|
|
|
(
|
|
|
|
self.nb_abs_nj,
|
|
|
|
self.nb_abs_just,
|
|
|
|
self.nb_abs,
|
|
|
|
) = sco_assiduites.get_assiduites_count_in_interval(
|
|
|
|
etud.id,
|
|
|
|
cur_sem.date_debut.isoformat(),
|
|
|
|
cur_sem.date_fin.isoformat(),
|
|
|
|
scu.translate_assiduites_metric(
|
|
|
|
sco_preferences.get_preference("assi_metrique")
|
|
|
|
),
|
|
|
|
)
|
|
|
|
return cur_sem
|
|
|
|
return None
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def formsemestre(self) -> FormSemestre | None:
|
|
|
|
"Le formsemestre courant, si sélectionné"
|
|
|
|
if self._init_formsemestre is None:
|
2024-01-21 18:07:56 +01:00
|
|
|
formsemestre_id = retreive_formsemestre_from_request()
|
2024-04-06 12:16:53 +02:00
|
|
|
return (
|
|
|
|
FormSemestre.get_formsemestre(formsemestre_id)
|
|
|
|
if formsemestre_id is not None
|
|
|
|
else None
|
2021-12-04 21:06:32 +01:00
|
|
|
)
|
2024-04-06 12:16:53 +02:00
|
|
|
return self._init_formsemestre
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def sem_menu_bar(self) -> str | None:
|
|
|
|
"Le html de la bare de menu formsemestre s'il y en a un."
|
|
|
|
return (
|
|
|
|
sco_formsemestre_status.formsemestre_status_menubar(self.formsemestre)
|
|
|
|
if self.formsemestre
|
|
|
|
else None
|
|
|
|
)
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def prefs(self):
|
|
|
|
"Préférences"
|
|
|
|
# prefs fallback to global pref if no current formsemestre:
|
|
|
|
return sco_preferences.SemPreferences(
|
|
|
|
self.formsemestre.id if self.formsemestre else None
|
|
|
|
)
|
2021-12-04 21:06:32 +01:00
|
|
|
|
2024-04-07 19:52:22 +02:00
|
|
|
def formsemestre_status_menu_bar(self) -> str:
|
|
|
|
"Le HTML de la barre de menu semestre"
|
|
|
|
return sco_formsemestre_status.formsemestre_status_menubar(self.formsemestre)
|
|
|
|
|
2021-12-04 21:06:32 +01:00
|
|
|
|
2024-07-09 13:37:22 +02:00
|
|
|
# Ajout des routes
|
|
|
|
from app.but import bulletin_but_court # ne pas enlever: ajoute des routes !
|
|
|
|
from app.but import jury_dut120 # ne pas enlever: ajoute des routes !
|
|
|
|
from app.pe import pe_view # ne pas enlever, ajoute des routes !
|
2023-03-21 21:14:38 +01:00
|
|
|
from app.views import (
|
|
|
|
absences,
|
2023-04-17 15:44:55 +02:00
|
|
|
assiduites,
|
2023-04-07 17:10:17 +02:00
|
|
|
but_formation,
|
2024-07-12 16:40:46 +02:00
|
|
|
groups,
|
2024-07-09 13:37:22 +02:00
|
|
|
jury_validations,
|
2023-03-21 21:14:38 +01:00
|
|
|
notes_formsemestre,
|
|
|
|
notes,
|
|
|
|
pn_modules,
|
|
|
|
refcomp,
|
|
|
|
scodoc,
|
|
|
|
scolar,
|
|
|
|
users,
|
2023-12-29 13:58:18 +01:00
|
|
|
user_board,
|
2023-03-21 21:14:38 +01:00
|
|
|
)
|