2021-05-29 18:22:51 +02:00
|
|
|
# -*- coding: UTF-8 -*
|
|
|
|
"""ScoDoc Flask views
|
|
|
|
"""
|
2021-10-03 18:19:51 +02:00
|
|
|
import datetime
|
|
|
|
|
2021-05-29 18:22:51 +02:00
|
|
|
from flask import Blueprint
|
2021-08-13 00:34:58 +02:00
|
|
|
from flask import g, current_app
|
2021-10-03 18:19:51 +02:00
|
|
|
from flask_login import current_user
|
|
|
|
|
|
|
|
from app import db
|
2021-07-20 17:32:04 +02:00
|
|
|
from app.scodoc import notesdb as ndb
|
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__)
|
2021-05-29 18:22:51 +02:00
|
|
|
|
2021-08-17 22:11:35 +02:00
|
|
|
from app.views import scodoc, notes, scolar, absences, users
|
|
|
|
|
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-03 18:19:51 +02:00
|
|
|
current_app.logger.info(f"start_scodoc_request")
|
2021-08-13 00:34:58 +02:00
|
|
|
ndb.open_db_connection()
|
2021-10-03 18:19:51 +02:00
|
|
|
if current_user.is_authenticated:
|
|
|
|
current_user.last_seen = datetime.datetime.utcnow()
|
|
|
|
db.session.commit()
|
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()
|