ScoDoc/app/views/user_board.py

51 lines
1.5 KiB
Python
Raw Normal View History

2023-12-29 13:58:18 +01:00
"""
Tableau de bord utilisateur
Emmanuel Viennet, 2023
"""
from flask import flash, redirect, render_template, url_for
from flask import g, request
from app.auth.models import User
from app.decorators import (
scodoc,
permission_required,
)
from app.models import Departement, FormSemestre
2023-12-29 13:58:18 +01:00
from app.scodoc.sco_permissions import Permission
from app.scodoc import sco_preferences
2023-12-29 13:58:18 +01:00
from app.scodoc import sco_utils as scu
from app.views import scolar_bp as bp
from app.views import ScoData
@bp.route("/user_board/<string:user_name>")
@scodoc
@permission_required(Permission.ScoView)
def user_board(user_name: str):
"""Tableau de bord utilisateur: liens vers ses objets"""
user = User.query.filter_by(user_name=user_name).first_or_404()
(
formsemestres_by_dept,
modimpls_by_formsemestre,
) = FormSemestre.get_user_formsemestres_annee_by_dept(user)
dept_names = {
dept_id: sco_preferences.get_preference("DeptName", dept_id=dept_id)
for dept_id in formsemestres_by_dept
}
dept_names_sorted = {
dept_id: dept_name
for (dept_id, dept_name) in sorted(dept_names.items(), key=lambda x: x[1])
}
2023-12-29 13:58:18 +01:00
# TODO: le calendrier avec ses enseignements
return render_template(
"user_board/user_board.j2",
dept_names=dept_names_sorted,
formsemestres_by_dept=formsemestres_by_dept,
2023-12-29 13:58:18 +01:00
modimpls_by_formsemestre=modimpls_by_formsemestre,
sco=ScoData(),
title=f"{user.get_prenomnom()}: tableau de bord",
user=user,
)