ScoDoc/app/views/user_board.py

56 lines
1.6 KiB
Python
Raw Permalink 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 flask_login import login_required
from app import db
2023-12-29 13:58:18 +01:00
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
from app.views import scodoc_bp as bp
2023-12-29 13:58:18 +01:00
from app.views import ScoData
@bp.route("/ScoDoc/user_board/<string:user_name>")
2023-12-29 13:58:18 +01:00
@scodoc
@login_required
2023-12-29 13:58:18 +01:00
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)
depts = {
dept_id: db.session.get(Departement, dept_id)
for dept_id in formsemestres_by_dept
}
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",
depts=depts,
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,
)