2023-09-20 22:38:01 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2023-09-20 22:38:01 +02:00
|
|
|
#
|
|
|
|
# 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 codé par Matthias Hartmann, 2023
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2023-04-17 15:44:55 +02:00
|
|
|
import datetime
|
2024-02-27 08:58:09 +01:00
|
|
|
import json
|
2023-11-15 14:11:47 +01:00
|
|
|
import re
|
2023-04-17 15:44:55 +02:00
|
|
|
|
2024-02-27 17:03:15 +01:00
|
|
|
from collections import OrderedDict
|
|
|
|
|
2023-09-06 11:21:53 +02:00
|
|
|
from flask import g, request, render_template, flash
|
2024-07-04 16:46:07 +02:00
|
|
|
from flask import abort, url_for, redirect, Response, session
|
2023-08-29 19:30:56 +02:00
|
|
|
from flask_login import current_user
|
2024-01-21 18:07:56 +01:00
|
|
|
from flask_sqlalchemy.query import Query
|
2023-04-17 15:44:55 +02:00
|
|
|
|
2024-02-28 10:23:47 +01:00
|
|
|
from markupsafe import Markup
|
2024-06-03 15:50:35 +02:00
|
|
|
from werkzeug.exceptions import HTTPException
|
2024-02-28 10:23:47 +01:00
|
|
|
|
2023-12-12 03:05:31 +01:00
|
|
|
from app import db, log
|
2024-07-04 16:46:07 +02:00
|
|
|
from app.api import tools
|
2023-04-17 15:44:55 +02:00
|
|
|
from app.comp import res_sem
|
|
|
|
from app.comp.res_compat import NotesTableCompat
|
|
|
|
from app.decorators import (
|
|
|
|
scodoc,
|
|
|
|
permission_required,
|
|
|
|
)
|
2023-12-12 03:05:31 +01:00
|
|
|
from app.forms.assiduite.ajout_assiduite_etud import (
|
|
|
|
AjoutAssiOrJustForm,
|
|
|
|
AjoutAssiduiteEtudForm,
|
|
|
|
AjoutJustificatifEtudForm,
|
|
|
|
)
|
2024-06-03 15:50:35 +02:00
|
|
|
from app.forms.assiduite.edit_assiduite_etud import EditAssiForm
|
2023-07-25 19:59:47 +02:00
|
|
|
from app.models import (
|
|
|
|
Assiduite,
|
|
|
|
Departement,
|
2023-09-06 11:21:53 +02:00
|
|
|
Evaluation,
|
2023-12-06 02:04:10 +01:00
|
|
|
FormSemestre,
|
2023-12-09 15:53:45 +01:00
|
|
|
GroupDescr,
|
2023-12-06 02:04:10 +01:00
|
|
|
Identite,
|
|
|
|
Justificatif,
|
2024-07-04 16:46:07 +02:00
|
|
|
Module,
|
2023-12-06 02:04:10 +01:00
|
|
|
ModuleImpl,
|
|
|
|
ScoDocSiteConfig,
|
2024-02-28 11:33:23 +01:00
|
|
|
Scolog,
|
2023-07-25 19:59:47 +02:00
|
|
|
)
|
2023-12-05 21:04:38 +01:00
|
|
|
from app.scodoc.codes_cursus import UE_STANDARD
|
2024-05-07 15:16:40 +02:00
|
|
|
|
2023-11-24 13:58:03 +01:00
|
|
|
from app.auth.models import User
|
2024-06-04 16:01:05 +02:00
|
|
|
from app.models.assiduites import get_assiduites_justif, is_period_conflicting
|
2023-12-09 15:53:45 +01:00
|
|
|
from app.tables.list_etuds import RowEtud, TableEtud
|
2023-11-24 13:58:03 +01:00
|
|
|
import app.tables.liste_assiduites as liste_assi
|
|
|
|
|
2023-04-17 15:44:55 +02:00
|
|
|
from app.views import assiduites_bp as bp
|
|
|
|
from app.views import ScoData
|
|
|
|
|
|
|
|
# ---------------
|
|
|
|
from app.scodoc.sco_permissions import Permission
|
|
|
|
from app.scodoc import html_sco_header
|
|
|
|
from app.scodoc import sco_moduleimpl
|
|
|
|
from app.scodoc import sco_preferences
|
2024-06-06 10:44:07 +02:00
|
|
|
from app.scodoc import sco_groups_view, sco_groups
|
2023-04-17 15:44:55 +02:00
|
|
|
from app.scodoc import sco_etud
|
2024-06-06 10:44:07 +02:00
|
|
|
from app.scodoc import sco_excel
|
2023-04-17 15:44:55 +02:00
|
|
|
from app.scodoc import sco_find_etud
|
2023-05-30 17:16:07 +02:00
|
|
|
from app.scodoc import sco_assiduites as scass
|
2023-08-29 19:30:56 +02:00
|
|
|
from app.scodoc import sco_utils as scu
|
|
|
|
from app.scodoc.sco_exceptions import ScoValueError
|
2024-05-07 15:16:40 +02:00
|
|
|
from app.scodoc import sco_gen_cal
|
2023-08-29 19:30:56 +02:00
|
|
|
|
2023-04-17 15:44:55 +02:00
|
|
|
|
2023-07-10 17:38:50 +02:00
|
|
|
from app.tables.visu_assiduites import TableAssi, etuds_sorted_from_ids
|
2023-11-24 13:58:03 +01:00
|
|
|
from app.scodoc.sco_archives_justificatifs import JustificatifArchiver
|
2023-07-10 17:38:50 +02:00
|
|
|
|
2023-04-17 15:44:55 +02:00
|
|
|
|
|
|
|
CSSSTYLES = html_sco_header.BOOTSTRAP_MULTISELECT_CSS
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
#
|
2023-09-21 08:46:21 +02:00
|
|
|
# Assiduité (/ScoDoc/<dept>/Scolarite/Assiduites/...)
|
2023-04-17 15:44:55 +02:00
|
|
|
#
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/")
|
2024-01-12 11:42:17 +01:00
|
|
|
@bp.route("/bilan_dept")
|
2023-04-17 15:44:55 +02:00
|
|
|
@scodoc
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.AbsChange)
|
2023-09-13 15:19:21 +02:00
|
|
|
def bilan_dept():
|
2023-04-17 15:44:55 +02:00
|
|
|
"""Gestionnaire assiduités, page principale"""
|
2023-10-27 16:05:40 +02:00
|
|
|
|
|
|
|
# Gestion des billets d'absences
|
2023-09-11 11:11:00 +02:00
|
|
|
if current_user.has_permission(
|
2023-09-29 21:17:31 +02:00
|
|
|
Permission.AbsChange
|
2023-09-11 11:11:00 +02:00
|
|
|
) and sco_preferences.get_preference("handle_billets_abs"):
|
2024-01-19 17:06:01 +01:00
|
|
|
billets = f"""
|
2023-09-11 11:11:00 +02:00
|
|
|
<h2 style="margin-top: 30px;">Billets d'absence</h2>
|
|
|
|
<ul><li><a href="{url_for("absences.list_billets", scodoc_dept=g.scodoc_dept)
|
|
|
|
}">Traitement des billets d'absence en attente</a>
|
|
|
|
</li></ul>
|
|
|
|
"""
|
2024-01-19 17:06:01 +01:00
|
|
|
else:
|
|
|
|
billets = ""
|
|
|
|
# Récupération du département
|
2023-09-12 09:41:50 +02:00
|
|
|
dept: Departement = Departement.query.filter_by(id=g.scodoc_dept_id).first()
|
2023-06-28 17:15:24 +02:00
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Récupération d'un formsemestre
|
2024-01-19 17:06:01 +01:00
|
|
|
# (pour n'afficher que les justificatifs liés au formsemestre)
|
2023-09-13 15:19:21 +02:00
|
|
|
formsemestre_id = request.args.get("formsemestre_id", "")
|
2024-01-19 17:06:01 +01:00
|
|
|
formsemestre = None
|
2023-09-13 15:19:21 +02:00
|
|
|
if formsemestre_id:
|
|
|
|
try:
|
|
|
|
formsemestre: FormSemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
|
|
|
except AttributeError:
|
|
|
|
formsemestre_id = ""
|
|
|
|
|
2024-01-19 17:06:01 +01:00
|
|
|
# <=> Génération du tableau <=>
|
|
|
|
|
|
|
|
# Récupération des étudiants du département / groupe
|
|
|
|
etudids: list[int] = [etud.id for etud in dept.etudiants] # cas département
|
|
|
|
group_ids = request.args.get("group_ids", "")
|
|
|
|
if group_ids and formsemestre:
|
|
|
|
groups_infos = sco_groups_view.DisplayedGroupsInfos(
|
|
|
|
group_ids.split(","),
|
|
|
|
formsemestre_id=formsemestre.id,
|
|
|
|
select_all_when_unspecified=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
if groups_infos.members:
|
|
|
|
etudids = [m["etudid"] for m in groups_infos.members]
|
|
|
|
|
|
|
|
# justificatifs (en attente ou modifiés avec les semestres associés)
|
|
|
|
justificatifs_query: Query = Justificatif.query.filter(
|
|
|
|
Justificatif.etat.in_(
|
|
|
|
[scu.EtatJustificatif.ATTENTE, scu.EtatJustificatif.MODIFIE]
|
2023-06-28 17:15:24 +02:00
|
|
|
),
|
2024-01-19 17:06:01 +01:00
|
|
|
Justificatif.etudid.in_(etudids),
|
|
|
|
)
|
|
|
|
# Filtrage par semestre si formsemestre_id != ""
|
|
|
|
if formsemestre:
|
|
|
|
justificatifs_query = justificatifs_query.filter(
|
|
|
|
Justificatif.date_debut >= formsemestre.date_debut,
|
|
|
|
Justificatif.date_debut <= formsemestre.date_fin,
|
|
|
|
)
|
|
|
|
|
|
|
|
data = liste_assi.AssiJustifData(
|
|
|
|
assiduites_query=None,
|
|
|
|
justificatifs_query=justificatifs_query,
|
|
|
|
)
|
|
|
|
|
|
|
|
fname: str = "Bilan Département"
|
|
|
|
cache_key: str = "tableau-dept"
|
|
|
|
titre: str = "Justificatifs en attente ou modifiés"
|
|
|
|
|
|
|
|
if formsemestre:
|
|
|
|
fname += f" {formsemestre.titre_annee()}"
|
|
|
|
cache_key += f"-{formsemestre.id}"
|
|
|
|
titre += f" {formsemestre.titre_annee()}"
|
|
|
|
|
|
|
|
if group_ids:
|
|
|
|
cache_key += f" {group_ids}"
|
|
|
|
|
|
|
|
table = _prepare_tableau(
|
|
|
|
data,
|
|
|
|
afficher_etu=True,
|
|
|
|
filename=fname,
|
|
|
|
titre=titre,
|
|
|
|
cache_key=cache_key,
|
|
|
|
)
|
|
|
|
|
|
|
|
if not table[0]:
|
|
|
|
return table[1]
|
|
|
|
|
2024-03-19 15:32:39 +01:00
|
|
|
# Récupération des formsemestres (pour le menu déroulant)
|
|
|
|
formsemestres: Query = FormSemestre.get_dept_formsemestres_courants(dept)
|
|
|
|
formsemestres_choices: dict[int, str] = {
|
|
|
|
fs.id: fs.titre_annee() for fs in formsemestres
|
|
|
|
}
|
|
|
|
|
2024-01-19 17:06:01 +01:00
|
|
|
# Peuplement du template jinja
|
|
|
|
return render_template(
|
|
|
|
"assiduites/pages/bilan_dept.j2",
|
|
|
|
tableau=table[1],
|
|
|
|
search_etud=sco_find_etud.form_search_etud(dest_url="assiduites.bilan_etud"),
|
|
|
|
billets=billets,
|
|
|
|
sco=ScoData(formsemestre=formsemestre),
|
2024-03-19 15:32:39 +01:00
|
|
|
formsemestres=formsemestres_choices,
|
|
|
|
formsemestre_id=None if not formsemestre else formsemestre.id,
|
2023-06-28 17:15:24 +02:00
|
|
|
)
|
2023-04-17 15:44:55 +02:00
|
|
|
|
|
|
|
|
2023-12-07 12:38:47 +01:00
|
|
|
@bp.route("/ajout_assiduite_etud", methods=["GET", "POST"])
|
2023-04-17 15:44:55 +02:00
|
|
|
@scodoc
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.AbsChange)
|
2023-12-14 20:50:27 +01:00
|
|
|
def ajout_assiduite_etud() -> str | Response:
|
2023-04-17 15:44:55 +02:00
|
|
|
"""
|
2023-12-05 21:04:38 +01:00
|
|
|
ajout_assiduite_etud Saisie d'une assiduité d'un étudiant
|
2023-04-17 15:44:55 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
etudid (int): l'identifiant de l'étudiant
|
2023-12-01 13:46:33 +01:00
|
|
|
date_deb, date_fin: heures début et fin (ISO sans timezone)
|
|
|
|
moduleimpl_id
|
2023-12-05 21:04:38 +01:00
|
|
|
evaluation_id : si présent, mode "évaluation"
|
|
|
|
fmt: si xls, renvoie le tableau des assiduités enregistrées
|
2023-04-17 15:44:55 +02:00
|
|
|
Returns:
|
|
|
|
str: l'html généré
|
|
|
|
"""
|
2023-12-14 20:50:27 +01:00
|
|
|
etudid: int = request.args.get("etudid", -1)
|
2023-12-01 13:46:33 +01:00
|
|
|
etud = Identite.get_etud(etudid)
|
2023-09-06 11:21:53 +02:00
|
|
|
|
2024-05-31 11:10:04 +02:00
|
|
|
formsemestre_id = request.args.get("formsemestre_id", None)
|
|
|
|
|
|
|
|
# Gestion du semestre
|
|
|
|
formsemestre: FormSemestre | None = None
|
|
|
|
sems_etud: list[FormSemestre] = etud.get_formsemestres()
|
|
|
|
if formsemestre_id:
|
|
|
|
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
|
|
|
formsemestre = formsemestre if formsemestre in sems_etud else None
|
2024-06-05 10:47:36 +02:00
|
|
|
if formsemestre is None:
|
|
|
|
raise ScoValueError("Etudiant non inscrit dans ce semestre")
|
2024-05-31 11:10:04 +02:00
|
|
|
else:
|
2024-06-05 10:47:36 +02:00
|
|
|
formsemestre = list(
|
|
|
|
sorted(sems_etud, key=lambda x: x.est_courant(), reverse=True)
|
|
|
|
) # Mets le semestre courant en premier et les autres dans l'ordre
|
2024-05-31 11:10:04 +02:00
|
|
|
formsemestre = formsemestre[0] if formsemestre else None
|
2024-06-05 10:47:36 +02:00
|
|
|
if formsemestre is None:
|
2024-06-05 11:21:53 +02:00
|
|
|
raise ScoValueError(
|
|
|
|
"L'étudiant n'est actuellement pas inscrit: on ne peut pas saisir son assiduité"
|
|
|
|
)
|
2024-05-31 11:10:04 +02:00
|
|
|
|
2023-12-01 13:46:33 +01:00
|
|
|
# Gestion évaluations (appel à la page depuis les évaluations)
|
2023-12-14 20:50:27 +01:00
|
|
|
evaluation_id: int | None = request.args.get("evaluation_id")
|
2023-12-05 21:04:38 +01:00
|
|
|
saisie_eval = evaluation_id is not None
|
2023-12-14 20:50:27 +01:00
|
|
|
moduleimpl_id: int | None = request.args.get("moduleimpl_id", "")
|
2023-12-05 21:04:38 +01:00
|
|
|
|
2023-09-06 11:21:53 +02:00
|
|
|
redirect_url: str = (
|
|
|
|
"#"
|
|
|
|
if not saisie_eval
|
|
|
|
else url_for(
|
|
|
|
"notes.evaluation_check_absences_html",
|
|
|
|
evaluation_id=evaluation_id,
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-12-05 21:04:38 +01:00
|
|
|
form = AjoutAssiduiteEtudForm(request.form)
|
|
|
|
# On dresse la liste des modules de l'année scolaire en cours
|
|
|
|
# auxquels est inscrit l'étudiant pour peupler le menu "module"
|
2024-02-27 17:03:15 +01:00
|
|
|
choices: OrderedDict = OrderedDict()
|
|
|
|
choices[""] = [("", "Non spécifié"), ("autre", "Autre module (pas dans la liste)")]
|
|
|
|
|
2024-06-06 18:48:18 +02:00
|
|
|
# Récupération des modulesimpl du semestre si existant.
|
|
|
|
if formsemestre:
|
|
|
|
# indique le nom du semestre dans le menu (optgroup)
|
|
|
|
modimpls_from_formsemestre = etud.get_modimpls_from_formsemestre(formsemestre)
|
|
|
|
group_name: str = formsemestre.titre_annee()
|
|
|
|
choices[group_name] = [
|
|
|
|
(m.id, f"{m.module.code} {m.module.abbrev or m.module.titre or ''}")
|
|
|
|
for m in modimpls_from_formsemestre
|
|
|
|
if m.module.ue.type == UE_STANDARD
|
|
|
|
]
|
2024-05-31 11:10:04 +02:00
|
|
|
|
2024-02-27 17:03:15 +01:00
|
|
|
choices.move_to_end("", last=False)
|
2023-12-05 21:04:38 +01:00
|
|
|
form.modimpl.choices = choices
|
2024-02-28 10:23:47 +01:00
|
|
|
force_options: dict = None
|
2023-12-05 21:04:38 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
if form.cancel.data: # cancel button
|
|
|
|
return redirect(redirect_url)
|
2024-05-31 11:10:04 +02:00
|
|
|
ok = _record_assiduite_etud(etud, form, formsemestre=formsemestre)
|
2023-12-05 21:04:38 +01:00
|
|
|
if ok:
|
|
|
|
flash("enregistré")
|
|
|
|
return redirect(redirect_url)
|
2023-04-17 15:44:55 +02:00
|
|
|
|
2024-02-28 10:23:47 +01:00
|
|
|
force_options = {"show_pres": True, "show_reta": True}
|
|
|
|
|
2023-12-05 21:04:38 +01:00
|
|
|
# Le tableau des assiduités+justificatifs déjà en base:
|
2023-12-01 13:46:33 +01:00
|
|
|
is_html, tableau = _prepare_tableau(
|
|
|
|
liste_assi.AssiJustifData.from_etudiants(
|
2023-11-24 18:07:30 +01:00
|
|
|
etud,
|
|
|
|
),
|
2023-12-12 03:05:31 +01:00
|
|
|
filename=f"assiduite-{etud.nom or ''}",
|
2023-11-24 13:58:03 +01:00
|
|
|
afficher_etu=False,
|
2023-12-01 13:46:33 +01:00
|
|
|
filtre=liste_assi.AssiFiltre(type_obj=1),
|
|
|
|
options=liste_assi.AssiDisplayOptions(show_module=True),
|
2024-01-11 17:24:01 +01:00
|
|
|
cache_key=f"tableau-etud-{etud.id}",
|
2024-02-28 10:23:47 +01:00
|
|
|
force_options=force_options,
|
2023-11-24 13:58:03 +01:00
|
|
|
)
|
2023-12-01 13:46:33 +01:00
|
|
|
if not is_html:
|
|
|
|
return tableau
|
2023-12-05 21:04:38 +01:00
|
|
|
|
|
|
|
return render_template(
|
|
|
|
"assiduites/pages/ajout_assiduite_etud.j2",
|
|
|
|
etud=etud,
|
|
|
|
form=form,
|
|
|
|
moduleimpl_id=moduleimpl_id,
|
|
|
|
redirect_url=redirect_url,
|
2024-05-31 11:10:04 +02:00
|
|
|
sco=ScoData(etud, formsemestre=formsemestre),
|
2023-12-05 21:04:38 +01:00
|
|
|
tableau=tableau,
|
|
|
|
scu=scu,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-12-12 03:05:31 +01:00
|
|
|
def _get_dates_from_assi_form(
|
|
|
|
form: AjoutAssiOrJustForm,
|
2024-05-31 10:13:22 +02:00
|
|
|
etud: Identite,
|
2024-03-25 16:15:01 +01:00
|
|
|
from_justif: bool = False,
|
2024-05-31 11:10:04 +02:00
|
|
|
formsemestre: FormSemestre | None = None,
|
2023-12-14 20:50:27 +01:00
|
|
|
) -> tuple[
|
|
|
|
bool, datetime.datetime | None, datetime.datetime | None, datetime.datetime | None
|
|
|
|
]:
|
2023-12-12 03:05:31 +01:00
|
|
|
"""Prend les dates et heures du form, les vérifie
|
|
|
|
puis converti en deux datetime, en timezone du serveur.
|
|
|
|
Ramène ok=True si ok.
|
|
|
|
Met des messages d'erreur dans le form.
|
2023-12-05 21:04:38 +01:00
|
|
|
"""
|
2024-01-05 10:06:16 +01:00
|
|
|
debut_jour = ScoDocSiteConfig.get("assi_morning_time", "08:00")
|
|
|
|
fin_jour = ScoDocSiteConfig.get("assi_afternoon_time", "17:00")
|
2023-12-07 12:38:47 +01:00
|
|
|
date_fin = None
|
2023-12-05 21:04:38 +01:00
|
|
|
# On commence par convertir individuellement tous les champs
|
|
|
|
try:
|
2024-04-02 23:37:23 +02:00
|
|
|
date_debut = datetime.datetime.strptime(form.date_debut.data, scu.DATE_FMT)
|
2023-12-05 21:04:38 +01:00
|
|
|
except ValueError:
|
2023-12-12 23:26:41 +01:00
|
|
|
date_debut = None
|
2023-12-14 20:50:27 +01:00
|
|
|
form.set_error("date début invalide", form.date_debut)
|
2023-12-05 21:04:38 +01:00
|
|
|
try:
|
|
|
|
date_fin = (
|
2024-04-02 23:37:23 +02:00
|
|
|
datetime.datetime.strptime(form.date_fin.data, scu.DATE_FMT)
|
2023-12-05 21:04:38 +01:00
|
|
|
if form.date_fin.data
|
|
|
|
else None
|
|
|
|
)
|
|
|
|
except ValueError:
|
2023-12-12 23:26:41 +01:00
|
|
|
date_fin = None
|
2023-12-14 20:50:27 +01:00
|
|
|
form.set_error("date fin invalide", form.date_fin)
|
2023-12-05 21:04:38 +01:00
|
|
|
|
2024-03-25 16:15:01 +01:00
|
|
|
if not from_justif and date_fin:
|
|
|
|
# Ne prends pas en compte les heures pour les assiduités sur plusieurs jours
|
|
|
|
heure_debut = datetime.time.fromisoformat(debut_jour)
|
|
|
|
heure_fin = datetime.time.fromisoformat(fin_jour)
|
2023-12-05 21:04:38 +01:00
|
|
|
else:
|
|
|
|
try:
|
2024-03-25 16:15:01 +01:00
|
|
|
heure_debut = datetime.time.fromisoformat(
|
|
|
|
form.heure_debut.data or debut_jour
|
|
|
|
)
|
2023-12-05 21:04:38 +01:00
|
|
|
except ValueError:
|
2023-12-14 20:50:27 +01:00
|
|
|
form.set_error("heure début invalide", form.heure_debut)
|
|
|
|
if bool(form.heure_debut.data) != bool(form.heure_fin.data):
|
|
|
|
form.set_error(
|
|
|
|
"Les deux heures début et fin doivent être spécifiées, ou aucune"
|
|
|
|
)
|
2023-12-05 21:04:38 +01:00
|
|
|
try:
|
2024-03-25 16:15:01 +01:00
|
|
|
heure_fin = datetime.time.fromisoformat(form.heure_fin.data or fin_jour)
|
2023-12-05 21:04:38 +01:00
|
|
|
except ValueError:
|
2023-12-14 20:50:27 +01:00
|
|
|
form.set_error("heure fin invalide", form.heure_fin)
|
|
|
|
|
|
|
|
if not form.ok:
|
|
|
|
return False, None, None, None
|
|
|
|
|
2023-12-12 03:05:31 +01:00
|
|
|
# Vérifie cohérence des dates/heures
|
2023-12-14 20:50:27 +01:00
|
|
|
dt_debut = datetime.datetime.combine(date_debut, heure_debut)
|
|
|
|
dt_fin = datetime.datetime.combine(date_fin or date_debut, heure_fin)
|
|
|
|
if dt_fin <= dt_debut:
|
|
|
|
form.set_error("dates début/fin incohérentes")
|
2024-01-30 11:47:57 +01:00
|
|
|
# La date de dépôt (si vide, la date actuelle)
|
2023-12-14 20:50:27 +01:00
|
|
|
try:
|
|
|
|
dt_entry_date = (
|
2024-04-02 23:37:23 +02:00
|
|
|
datetime.datetime.strptime(form.entry_date.data, scu.DATE_FMT)
|
2023-12-14 20:50:27 +01:00
|
|
|
if form.entry_date.data
|
2023-12-22 15:31:30 +01:00
|
|
|
else datetime.datetime.now() # local tz
|
2023-12-14 20:50:27 +01:00
|
|
|
)
|
|
|
|
except ValueError:
|
|
|
|
dt_entry_date = None
|
|
|
|
form.set_error("format de date de dépôt invalide", form.entry_date)
|
2024-01-30 11:47:57 +01:00
|
|
|
# L'heure de dépôt
|
|
|
|
try:
|
|
|
|
entry_time = datetime.time.fromisoformat(
|
|
|
|
form.entry_time.data or datetime.datetime.now().time().isoformat("seconds")
|
|
|
|
)
|
|
|
|
except ValueError:
|
|
|
|
dt_entry_date = None
|
|
|
|
form.set_error("format d'heure de dépôt invalide", form.entry_date)
|
|
|
|
if dt_entry_date:
|
|
|
|
dt_entry_date = datetime.datetime.combine(dt_entry_date, entry_time)
|
2023-12-12 03:05:31 +01:00
|
|
|
# Ajoute time zone serveur
|
2023-12-14 20:50:27 +01:00
|
|
|
dt_debut_tz_server = scu.TIME_ZONE.localize(dt_debut)
|
|
|
|
dt_fin_tz_server = scu.TIME_ZONE.localize(dt_fin)
|
2024-03-25 16:15:01 +01:00
|
|
|
|
|
|
|
if from_justif:
|
|
|
|
cas: list[bool] = [
|
|
|
|
# cas 1 (date de fin vide et pas d'heure de début)
|
|
|
|
not form.date_fin.data and not form.heure_debut.data,
|
|
|
|
# cas 2 (date de fin et pas d'heures)
|
|
|
|
form.date_fin.data != "" and not form.heure_debut.data,
|
|
|
|
]
|
|
|
|
|
|
|
|
if any(cas):
|
|
|
|
dt_debut_tz_server = dt_debut_tz_server.replace(hour=0, minute=0)
|
|
|
|
dt_fin_tz_server = dt_fin_tz_server.replace(hour=23, minute=59)
|
|
|
|
|
2024-05-31 10:13:22 +02:00
|
|
|
# Vérification dates contenu dans un semestre de l'étudiant
|
2024-05-31 11:10:04 +02:00
|
|
|
dates_semestres: list[tuple[datetime.date, datetime.date]] = (
|
|
|
|
[(sem.date_debut, sem.date_fin) for sem in etud.get_formsemestres()]
|
|
|
|
if formsemestre is None
|
|
|
|
else [(formsemestre.date_debut, formsemestre.date_fin)]
|
|
|
|
)
|
2024-05-31 10:13:22 +02:00
|
|
|
|
|
|
|
# Vérification date début
|
|
|
|
if not any(
|
|
|
|
[
|
|
|
|
dt_debut_tz_server.date() >= deb and dt_debut_tz_server.date() <= fin
|
|
|
|
for deb, fin in dates_semestres
|
|
|
|
]
|
|
|
|
):
|
|
|
|
form.set_error(
|
2024-06-27 21:22:19 +02:00
|
|
|
(
|
|
|
|
"La date de début n'appartient à aucun semestre de l'étudiant"
|
|
|
|
if formsemestre is None
|
|
|
|
else "La date de début n'appartient pas au semestre"
|
|
|
|
),
|
2024-05-31 10:13:22 +02:00
|
|
|
form.date_debut,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Vérification date fin
|
|
|
|
if form.date_fin.data and not any(
|
|
|
|
[
|
|
|
|
dt_fin_tz_server.date() >= deb and dt_fin_tz_server.date() <= fin
|
|
|
|
for deb, fin in dates_semestres
|
|
|
|
]
|
|
|
|
):
|
|
|
|
form.set_error(
|
2024-06-27 21:22:19 +02:00
|
|
|
(
|
|
|
|
"La date de fin n'appartient à aucun semestre de l'étudiant"
|
|
|
|
if not formsemestre
|
|
|
|
else "La date de fin n'appartient pas au semestre"
|
|
|
|
),
|
2024-05-31 11:10:04 +02:00
|
|
|
form.date_fin,
|
2024-05-31 10:13:22 +02:00
|
|
|
)
|
|
|
|
|
2023-12-12 03:05:31 +01:00
|
|
|
dt_entry_date_tz_server = (
|
|
|
|
scu.TIME_ZONE.localize(dt_entry_date) if dt_entry_date else None
|
|
|
|
)
|
2023-12-14 20:50:27 +01:00
|
|
|
return form.ok, dt_debut_tz_server, dt_fin_tz_server, dt_entry_date_tz_server
|
2023-12-12 03:05:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
def _record_assiduite_etud(
|
|
|
|
etud: Identite,
|
|
|
|
form: AjoutAssiduiteEtudForm,
|
2024-05-31 11:10:04 +02:00
|
|
|
formsemestre: FormSemestre | None = None,
|
2023-12-12 03:05:31 +01:00
|
|
|
) -> bool:
|
|
|
|
"""Enregistre les données du formulaire de saisie assiduité.
|
|
|
|
Returns ok if successfully recorded, else put error info in the form.
|
|
|
|
Format attendu des données du formulaire:
|
|
|
|
form.assi_etat.data : 'absent'
|
|
|
|
form.date_debut.data : '05/12/2023'
|
|
|
|
form.heure_debut.data : '09:06' (heure locale du serveur)
|
|
|
|
"""
|
|
|
|
(
|
|
|
|
ok,
|
|
|
|
dt_debut_tz_server,
|
|
|
|
dt_fin_tz_server,
|
|
|
|
dt_entry_date_tz_server,
|
2024-05-31 11:10:04 +02:00
|
|
|
) = _get_dates_from_assi_form(form, etud, formsemestre=formsemestre)
|
2023-12-05 21:04:38 +01:00
|
|
|
# Le module (avec "autre")
|
|
|
|
mod_data = form.modimpl.data
|
|
|
|
if mod_data:
|
|
|
|
if mod_data == "autre":
|
|
|
|
moduleimpl_id = "autre"
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
moduleimpl_id = int(mod_data)
|
|
|
|
except ValueError:
|
|
|
|
form.modimpl.error("choix de module invalide")
|
|
|
|
ok = False
|
|
|
|
else:
|
|
|
|
moduleimpl_id = None
|
2023-12-12 03:05:31 +01:00
|
|
|
|
2023-12-05 21:04:38 +01:00
|
|
|
if not ok:
|
|
|
|
return False
|
2023-12-12 03:05:31 +01:00
|
|
|
|
2023-12-06 02:04:10 +01:00
|
|
|
external_data = None
|
|
|
|
moduleimpl: ModuleImpl | None = None
|
|
|
|
match moduleimpl_id:
|
|
|
|
case "autre":
|
|
|
|
external_data = {"module": "Autre"}
|
|
|
|
case None:
|
|
|
|
moduleimpl = None
|
|
|
|
case _:
|
|
|
|
moduleimpl = ModuleImpl.query.get(moduleimpl_id)
|
|
|
|
try:
|
2024-01-16 16:15:48 +01:00
|
|
|
assi_etat: scu.EtatAssiduite = scu.EtatAssiduite.get(form.assi_etat.data)
|
|
|
|
|
2023-12-06 02:04:10 +01:00
|
|
|
ass = Assiduite.create_assiduite(
|
|
|
|
etud,
|
|
|
|
dt_debut_tz_server,
|
|
|
|
dt_fin_tz_server,
|
2024-01-16 16:15:48 +01:00
|
|
|
assi_etat,
|
2023-12-22 15:59:24 +01:00
|
|
|
description=form.description.data,
|
2023-12-06 02:04:10 +01:00
|
|
|
entry_date=dt_entry_date_tz_server,
|
|
|
|
external_data=external_data,
|
|
|
|
moduleimpl=moduleimpl,
|
|
|
|
notify_mail=True,
|
|
|
|
user_id=current_user.id,
|
|
|
|
)
|
|
|
|
db.session.add(ass)
|
|
|
|
db.session.commit()
|
2024-01-08 19:01:54 +01:00
|
|
|
|
2024-01-16 16:15:48 +01:00
|
|
|
if assi_etat != scu.EtatAssiduite.PRESENT and form.est_just.data:
|
|
|
|
# si la case "justifiée est cochée alors on créé un justificatif de même période"
|
2024-06-26 10:32:15 +02:00
|
|
|
|
|
|
|
# L'état est Valide si l'user à la permission JustifValidate
|
|
|
|
etat: scu.EtatJustificatif = scu.EtatJustificatif.ATTENTE
|
|
|
|
if current_user.has_permission(Permission.JustifValidate):
|
|
|
|
etat = scu.EtatJustificatif.VALIDE
|
|
|
|
else:
|
|
|
|
flash(
|
|
|
|
"Vous ne pouvez pas créer de justificatif valide,"
|
|
|
|
+ " il est automatiquement passé 'EN ATTENTE'",
|
|
|
|
)
|
|
|
|
|
2024-01-16 16:15:48 +01:00
|
|
|
justi: Justificatif = Justificatif.create_justificatif(
|
|
|
|
etudiant=etud,
|
|
|
|
date_debut=dt_debut_tz_server,
|
|
|
|
date_fin=dt_fin_tz_server,
|
2024-06-26 10:32:15 +02:00
|
|
|
etat=etat,
|
2024-01-16 16:15:48 +01:00
|
|
|
user_id=current_user.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
# On met à jour les assiduités en fonction du nouveau justificatif
|
2024-02-29 14:20:39 +01:00
|
|
|
justi.justifier_assiduites()
|
2024-01-16 16:15:48 +01:00
|
|
|
|
2024-01-08 19:01:54 +01:00
|
|
|
# Invalider cache
|
|
|
|
scass.simple_invalidate_cache(ass.to_dict(), etud.id)
|
|
|
|
|
2023-12-05 21:04:38 +01:00
|
|
|
return True
|
2023-12-06 02:04:10 +01:00
|
|
|
except ScoValueError as exc:
|
2024-02-28 10:23:47 +01:00
|
|
|
err: str = f"Erreur: {exc.args[0]}"
|
|
|
|
|
|
|
|
if (
|
|
|
|
exc.args[0]
|
|
|
|
== "Duplication: la période rentre en conflit avec une plage enregistrée"
|
|
|
|
):
|
|
|
|
# Récupération de la première assiduité conflictuelle
|
|
|
|
conflits: Query = etud.assiduites.filter(
|
|
|
|
Assiduite.date_debut < dt_fin_tz_server,
|
|
|
|
Assiduite.date_fin > dt_debut_tz_server,
|
|
|
|
)
|
|
|
|
assi: Assiduite = conflits.first()
|
|
|
|
|
|
|
|
lien: str = url_for(
|
2024-06-03 15:50:35 +02:00
|
|
|
"assiduites.edit_assiduite_etud",
|
2024-06-05 10:47:36 +02:00
|
|
|
assiduite_id=assi.assiduite_id,
|
2024-02-28 10:23:47 +01:00
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
)
|
|
|
|
|
|
|
|
form.set_error(
|
|
|
|
Markup(
|
|
|
|
err
|
|
|
|
+ f' <a href="{lien}" target="_blank" title="Voir le détail de'
|
|
|
|
+ " l'assiduité conflictuelle\">(conflit)</a>"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
form.set_error(err)
|
2023-12-06 02:04:10 +01:00
|
|
|
return False
|
2023-12-05 21:04:38 +01:00
|
|
|
|
2023-04-17 15:44:55 +02:00
|
|
|
|
2023-12-07 22:10:51 +01:00
|
|
|
@bp.route("/bilan_etud")
|
2023-06-28 17:15:24 +02:00
|
|
|
@scodoc
|
2023-06-30 17:24:16 +02:00
|
|
|
@permission_required(Permission.ScoView)
|
2023-06-28 17:15:24 +02:00
|
|
|
def bilan_etud():
|
|
|
|
"""
|
|
|
|
bilan_etud Affichage de toutes les assiduites et justificatifs d'un etudiant
|
|
|
|
Args:
|
|
|
|
etudid (int): l'identifiant de l'étudiant
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: l'html généré
|
|
|
|
"""
|
2024-06-27 19:13:39 +02:00
|
|
|
# Initialisation des options du tableau
|
|
|
|
options: liste_assi.AssiDisplayOptions = liste_assi.AssiDisplayOptions(
|
|
|
|
show_module=True
|
|
|
|
)
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Récupération de l'étudiant
|
2023-06-28 17:15:24 +02:00
|
|
|
etudid = request.args.get("etudid", -1)
|
|
|
|
etud: Identite = Identite.query.get_or_404(etudid)
|
|
|
|
if etud.dept_id != g.scodoc_dept_id:
|
|
|
|
abort(404, "étudiant inexistant dans ce département")
|
|
|
|
|
2024-06-27 19:13:39 +02:00
|
|
|
# Gestion du filtre de module
|
|
|
|
moduleimpl_id = request.args.get("moduleimpl_id", None)
|
|
|
|
if moduleimpl_id is not None:
|
|
|
|
try:
|
|
|
|
moduleimpl_id = int(moduleimpl_id)
|
|
|
|
except ValueError:
|
|
|
|
moduleimpl_id = None
|
|
|
|
options.moduleimpl_id = moduleimpl_id
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Gestion des dates du bilan (par défaut l'année scolaire)
|
2024-04-02 23:37:23 +02:00
|
|
|
date_debut = scu.date_debut_annee_scolaire().strftime(scu.DATE_FMT)
|
|
|
|
date_fin: str = scu.date_fin_annee_scolaire().strftime(scu.DATE_FMT)
|
2023-06-28 17:15:24 +02:00
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Récupération de la métrique d'assiduité
|
2023-08-22 15:43:10 +02:00
|
|
|
assi_metric = scu.translate_assiduites_metric(
|
|
|
|
sco_preferences.get_preference("assi_metrique", dept_id=g.scodoc_dept_id),
|
2023-08-14 01:08:04 +02:00
|
|
|
)
|
2023-06-28 17:15:24 +02:00
|
|
|
|
2024-06-27 19:13:39 +02:00
|
|
|
# préparation du selecteur de moduleimpl
|
2024-06-27 21:22:19 +02:00
|
|
|
annee_sco = _get_anne_sco_from_request()
|
2024-06-27 19:13:39 +02:00
|
|
|
moduleimpl_select: str = _module_selector_multiple(
|
2024-06-27 21:22:19 +02:00
|
|
|
etud, moduleimpl_id, no_default=True, annee_sco=annee_sco
|
2024-06-27 19:13:39 +02:00
|
|
|
)
|
|
|
|
|
2024-05-24 10:26:47 +02:00
|
|
|
# Préparation de la page
|
|
|
|
tableau = _prepare_tableau(
|
2024-06-27 19:13:39 +02:00
|
|
|
liste_assi.AssiJustifData.from_etudiants(etud),
|
2024-05-24 10:26:47 +02:00
|
|
|
filename=f"assiduites-justificatifs-{etud.id}",
|
2024-01-19 17:06:01 +01:00
|
|
|
afficher_etu=False,
|
2024-05-24 10:26:47 +02:00
|
|
|
filtre=liste_assi.AssiFiltre(type_obj=0),
|
2024-06-27 19:13:39 +02:00
|
|
|
options=options,
|
2024-05-24 10:26:47 +02:00
|
|
|
cache_key=f"tableau-etud-{etud.id}",
|
2024-06-27 19:13:39 +02:00
|
|
|
moduleimpl_select=moduleimpl_select,
|
2024-01-19 17:06:01 +01:00
|
|
|
)
|
2024-05-24 10:26:47 +02:00
|
|
|
if not tableau[0]:
|
|
|
|
return tableau[1]
|
2024-01-19 17:06:01 +01:00
|
|
|
|
2024-01-21 22:21:10 +01:00
|
|
|
# Génération de la page HTML
|
|
|
|
return render_template(
|
|
|
|
"assiduites/pages/bilan_etud.j2",
|
|
|
|
assi_metric=assi_metric,
|
|
|
|
assi_seuil=_get_seuil(),
|
|
|
|
date_debut=date_debut,
|
|
|
|
date_fin=date_fin,
|
|
|
|
sco=ScoData(etud),
|
2024-05-24 10:26:47 +02:00
|
|
|
tableau=tableau[1],
|
2024-01-21 22:21:10 +01:00
|
|
|
)
|
2023-06-28 17:15:24 +02:00
|
|
|
|
|
|
|
|
2023-12-22 15:31:30 +01:00
|
|
|
@bp.route("/edit_justificatif_etud/<int:justif_id>", methods=["GET", "POST"])
|
|
|
|
@scodoc
|
2024-06-03 15:50:35 +02:00
|
|
|
@permission_required(Permission.ScoView)
|
2023-12-22 15:31:30 +01:00
|
|
|
def edit_justificatif_etud(justif_id: int):
|
|
|
|
"""
|
2024-01-21 18:07:56 +01:00
|
|
|
Edition d'un justificatif.
|
|
|
|
Il faut de plus la permission pour voir/modifier la raison.
|
|
|
|
|
2023-12-22 15:31:30 +01:00
|
|
|
Args:
|
|
|
|
justif_id (int): l'identifiant du justificatif
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: l'html généré
|
|
|
|
"""
|
2024-06-03 15:50:35 +02:00
|
|
|
try:
|
|
|
|
justif = Justificatif.get_justificatif(justif_id)
|
|
|
|
except HTTPException:
|
|
|
|
flash("Justificatif invalide")
|
|
|
|
return redirect(url_for("assiduites.bilan_dept", scodoc_dept=g.scodoc_dept))
|
|
|
|
|
|
|
|
readonly = not current_user.has_permission(Permission.AbsChange)
|
|
|
|
|
2023-12-22 15:31:30 +01:00
|
|
|
form = AjoutJustificatifEtudForm(obj=justif)
|
2024-06-26 10:32:15 +02:00
|
|
|
# Limite les choix d'état si l'utilisateur n'a pas la permission de valider
|
|
|
|
choix_etat: list = [
|
|
|
|
(scu.EtatJustificatif.ATTENTE.value, "En attente de validation")
|
|
|
|
]
|
|
|
|
|
|
|
|
if current_user.has_permission(Permission.JustifValidate):
|
|
|
|
choix_etat = [
|
|
|
|
("", "Choisir..."),
|
|
|
|
(scu.EtatJustificatif.ATTENTE.value, "En attente de validation"),
|
|
|
|
(scu.EtatJustificatif.NON_VALIDE.value, "Non valide"),
|
|
|
|
(scu.EtatJustificatif.MODIFIE.value, "Modifié"),
|
|
|
|
(scu.EtatJustificatif.VALIDE.value, "Valide"),
|
|
|
|
]
|
|
|
|
|
|
|
|
form.etat.choices = choix_etat
|
2024-06-03 15:50:35 +02:00
|
|
|
|
|
|
|
if readonly:
|
|
|
|
form.disable_all()
|
|
|
|
|
2023-12-22 15:31:30 +01:00
|
|
|
# Set the default value for the etat field
|
|
|
|
if request.method == "GET":
|
2024-04-02 23:37:23 +02:00
|
|
|
form.date_debut.data = justif.date_debut.strftime(scu.DATE_FMT)
|
|
|
|
form.date_fin.data = justif.date_fin.strftime(scu.DATE_FMT)
|
2023-12-22 15:31:30 +01:00
|
|
|
if form.date_fin.data == form.date_debut.data:
|
|
|
|
# un seul jour: pas de date de fin, indique les heures
|
|
|
|
form.date_fin.data = ""
|
2024-04-02 23:37:23 +02:00
|
|
|
form.heure_debut.data = justif.date_debut.strftime(scu.TIME_FMT)
|
|
|
|
form.heure_fin.data = justif.date_fin.strftime(scu.TIME_FMT)
|
2023-12-22 15:31:30 +01:00
|
|
|
form.entry_date.data = (
|
2024-04-02 23:37:23 +02:00
|
|
|
justif.entry_date.strftime(scu.DATE_FMT) if justif.entry_date else ""
|
2023-12-22 15:31:30 +01:00
|
|
|
)
|
2024-01-30 11:47:57 +01:00
|
|
|
form.entry_time.data = (
|
2024-04-02 23:37:23 +02:00
|
|
|
justif.entry_date.strftime(scu.TIME_FMT) if justif.entry_date else ""
|
2024-01-30 11:47:57 +01:00
|
|
|
)
|
2023-12-22 15:31:30 +01:00
|
|
|
form.etat.data = str(justif.etat)
|
|
|
|
|
2024-03-22 08:46:05 +01:00
|
|
|
back_url = request.args.get("back_url", None)
|
|
|
|
|
|
|
|
redirect_url = back_url or url_for(
|
2024-05-24 10:26:47 +02:00
|
|
|
"assiduites.bilan_etud",
|
2023-12-22 15:31:30 +01:00
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
etudid=justif.etudiant.id,
|
|
|
|
)
|
2024-03-22 08:46:05 +01:00
|
|
|
|
2023-12-22 15:31:30 +01:00
|
|
|
if form.validate_on_submit():
|
2024-06-03 15:50:35 +02:00
|
|
|
if form.cancel.data or not current_user.has_permission(
|
|
|
|
Permission.AbsChange
|
|
|
|
): # cancel button
|
2024-03-01 16:35:39 +01:00
|
|
|
return redirect(redirect_url)
|
2023-12-22 15:31:30 +01:00
|
|
|
if _record_justificatif_etud(justif.etudiant, form, justif):
|
|
|
|
return redirect(redirect_url)
|
|
|
|
|
|
|
|
# Fichiers
|
|
|
|
filenames, nb_files = justif.get_fichiers()
|
|
|
|
|
|
|
|
return render_template(
|
|
|
|
"assiduites/pages/ajout_justificatif_etud.j2",
|
2024-01-21 18:07:56 +01:00
|
|
|
can_view_justif_detail=current_user.has_permission(Permission.AbsJustifView)
|
|
|
|
or current_user.id == justif.user_id,
|
2023-12-22 15:31:30 +01:00
|
|
|
etud=justif.etudiant,
|
|
|
|
filenames=filenames,
|
|
|
|
form=form,
|
2024-06-03 15:50:35 +02:00
|
|
|
justif=_preparer_objet("justificatif", justif),
|
2023-12-22 15:31:30 +01:00
|
|
|
nb_files=nb_files,
|
2024-01-21 18:07:56 +01:00
|
|
|
title=f"Modification justificatif absence de {justif.etudiant.html_link_fiche()}",
|
2023-12-22 15:31:30 +01:00
|
|
|
redirect_url=redirect_url,
|
|
|
|
sco=ScoData(justif.etudiant),
|
|
|
|
scu=scu,
|
2024-06-03 15:50:35 +02:00
|
|
|
readonly=not current_user.has_permission(Permission.AbsChange),
|
2023-12-22 15:31:30 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-01-21 18:07:56 +01:00
|
|
|
@bp.route("/ajout_justificatif_etud", methods=["GET", "POST"])
|
2023-06-20 15:50:56 +02:00
|
|
|
@scodoc
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.AbsChange)
|
2023-06-20 15:50:56 +02:00
|
|
|
def ajout_justificatif_etud():
|
|
|
|
"""
|
2023-12-22 15:31:30 +01:00
|
|
|
ajout_justificatif_etud : Affichage et création des justificatifs de l'étudiant
|
2023-06-20 15:50:56 +02:00
|
|
|
Args:
|
|
|
|
etudid (int): l'identifiant de l'étudiant
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: l'html généré
|
|
|
|
"""
|
2023-12-12 03:05:31 +01:00
|
|
|
etud = Identite.get_etud(request.args.get("etudid"))
|
|
|
|
redirect_url = url_for(
|
|
|
|
"assiduites.calendrier_assi_etud", scodoc_dept=g.scodoc_dept, etudid=etud.id
|
2023-06-20 15:50:56 +02:00
|
|
|
)
|
|
|
|
|
2023-12-12 03:05:31 +01:00
|
|
|
form = AjoutJustificatifEtudForm()
|
2024-06-26 10:32:15 +02:00
|
|
|
# Limite les choix d'état si l'utilisateur n'a pas la permission de valider
|
|
|
|
choix_etat: list = [
|
|
|
|
(scu.EtatJustificatif.ATTENTE.value, "En attente de validation")
|
|
|
|
]
|
|
|
|
|
|
|
|
if current_user.has_permission(Permission.JustifValidate):
|
|
|
|
choix_etat = [
|
|
|
|
("", "Choisir..."),
|
|
|
|
(scu.EtatJustificatif.ATTENTE.value, "En attente de validation"),
|
|
|
|
(scu.EtatJustificatif.NON_VALIDE.value, "Non valide"),
|
|
|
|
(scu.EtatJustificatif.MODIFIE.value, "Modifié"),
|
|
|
|
(scu.EtatJustificatif.VALIDE.value, "Valide"),
|
|
|
|
]
|
|
|
|
|
|
|
|
form.etat.choices = choix_etat
|
2023-12-12 03:05:31 +01:00
|
|
|
if form.validate_on_submit():
|
|
|
|
if form.cancel.data: # cancel button
|
|
|
|
return redirect(redirect_url)
|
|
|
|
ok = _record_justificatif_etud(etud, form)
|
|
|
|
if ok:
|
|
|
|
return redirect(redirect_url)
|
|
|
|
|
|
|
|
is_html, tableau = _prepare_tableau(
|
2023-12-01 13:46:33 +01:00
|
|
|
liste_assi.AssiJustifData.from_etudiants(
|
2023-11-24 18:07:30 +01:00
|
|
|
etud,
|
|
|
|
),
|
2023-12-12 03:05:31 +01:00
|
|
|
filename=f"justificatifs-{etud.nom or ''}",
|
2023-11-24 18:07:30 +01:00
|
|
|
afficher_etu=False,
|
2023-12-01 13:46:33 +01:00
|
|
|
filtre=liste_assi.AssiFiltre(type_obj=2),
|
|
|
|
options=liste_assi.AssiDisplayOptions(show_module=False, show_desc=True),
|
2023-11-24 18:07:30 +01:00
|
|
|
afficher_options=False,
|
2023-12-12 03:05:31 +01:00
|
|
|
titre="Justificatifs enregistrés pour cet étudiant",
|
2024-01-11 17:24:01 +01:00
|
|
|
cache_key=f"tableau-etud-{etud.id}",
|
2023-11-24 18:07:30 +01:00
|
|
|
)
|
2023-12-12 03:05:31 +01:00
|
|
|
if not is_html:
|
|
|
|
return tableau
|
2023-11-24 18:07:30 +01:00
|
|
|
|
2023-12-12 03:05:31 +01:00
|
|
|
return render_template(
|
|
|
|
"assiduites/pages/ajout_justificatif_etud.j2",
|
|
|
|
etud=etud,
|
|
|
|
form=form,
|
2024-01-21 18:07:56 +01:00
|
|
|
title=f"Ajout justificatif absence pour {etud.html_link_fiche()}",
|
2023-12-12 03:05:31 +01:00
|
|
|
redirect_url=redirect_url,
|
|
|
|
sco=ScoData(etud),
|
|
|
|
scu=scu,
|
|
|
|
tableau=tableau,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def _record_justificatif_etud(
|
2023-12-22 15:31:30 +01:00
|
|
|
etud: Identite, form: AjoutJustificatifEtudForm, justif: Justificatif | None = None
|
2023-12-12 03:05:31 +01:00
|
|
|
) -> bool:
|
|
|
|
"""Enregistre les données du formulaire de saisie justificatif (et ses fichiers).
|
|
|
|
Returns ok if successfully recorded, else put error info in the form.
|
|
|
|
Format attendu des données du formulaire:
|
|
|
|
form.assi_etat.data : 'absent'
|
|
|
|
form.date_debut.data : '05/12/2023'
|
|
|
|
form.heure_debut.data : '09:06' (heure locale du serveur)
|
2023-12-22 15:31:30 +01:00
|
|
|
Si justif, modifie le justif existant, sinon en crée un nouveau
|
2023-12-12 03:05:31 +01:00
|
|
|
"""
|
|
|
|
(
|
|
|
|
ok,
|
|
|
|
dt_debut_tz_server,
|
|
|
|
dt_fin_tz_server,
|
|
|
|
dt_entry_date_tz_server,
|
2024-05-31 10:13:22 +02:00
|
|
|
) = _get_dates_from_assi_form(form, etud, from_justif=True)
|
2023-12-12 03:05:31 +01:00
|
|
|
if not ok:
|
2023-12-22 15:31:30 +01:00
|
|
|
log("_record_justificatif_etud: dates invalides")
|
|
|
|
form.set_error("Erreur: dates invalides")
|
|
|
|
return False
|
|
|
|
if not form.etat.data:
|
|
|
|
log("_record_justificatif_etud: etat invalide")
|
|
|
|
form.set_error("Erreur: état invalide")
|
|
|
|
return False
|
|
|
|
etat = int(form.etat.data)
|
|
|
|
if not scu.EtatJustificatif.is_valid_etat(etat):
|
|
|
|
log(f"_record_justificatif_etud: etat invalide ({etat})")
|
|
|
|
form.set_error("Erreur: état invalide")
|
2023-12-12 03:05:31 +01:00
|
|
|
return False
|
2023-12-22 15:31:30 +01:00
|
|
|
|
2024-06-26 10:32:15 +02:00
|
|
|
if (
|
|
|
|
not current_user.has_permission(Permission.JustifValidate)
|
|
|
|
and etat != scu.EtatJustificatif.ATTENTE
|
|
|
|
):
|
|
|
|
log("_record_justificatif_etud: pas la permission")
|
|
|
|
form.set_error(
|
|
|
|
"Erreur: vous n'avez pas la permission de définir la validité d'un justificatif"
|
|
|
|
)
|
|
|
|
return False
|
|
|
|
|
2023-12-12 03:05:31 +01:00
|
|
|
try:
|
2023-12-22 15:31:30 +01:00
|
|
|
message = ""
|
|
|
|
if justif:
|
|
|
|
form.date_debut.data = dt_debut_tz_server
|
|
|
|
form.date_fin.data = dt_fin_tz_server
|
|
|
|
form.entry_date.data = dt_entry_date_tz_server
|
2024-02-29 14:20:39 +01:00
|
|
|
justif.dejustifier_assiduites()
|
2023-12-22 15:31:30 +01:00
|
|
|
if justif.edit_from_form(form):
|
|
|
|
message = "Justificatif modifié"
|
2024-02-28 11:33:23 +01:00
|
|
|
|
|
|
|
# On met à jour la db pour avoir les bonnes donnés pour le journal etud
|
|
|
|
db.session.add(justif)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
Scolog.logdb(
|
|
|
|
method="edit_justificatif",
|
|
|
|
etudid=etud.id,
|
|
|
|
msg=f"justificatif modif: {justif}",
|
|
|
|
)
|
2023-12-22 15:31:30 +01:00
|
|
|
else:
|
|
|
|
message = "Pas de modification"
|
2024-03-01 16:35:39 +01:00
|
|
|
fichier_suppr: list[str] = request.form.getlist("suppr_fichier_just")
|
|
|
|
|
|
|
|
if len(fichier_suppr) > 0 and justif.fichier is not None:
|
|
|
|
archiver: JustificatifArchiver = JustificatifArchiver()
|
|
|
|
for fichier in fichier_suppr:
|
|
|
|
archiver.delete_justificatif(etud, justif.fichier, fichier)
|
|
|
|
flash(f"Fichier {fichier} supprimé")
|
|
|
|
|
2023-12-22 15:31:30 +01:00
|
|
|
else:
|
|
|
|
justif = Justificatif.create_justificatif(
|
|
|
|
etud,
|
|
|
|
dt_debut_tz_server,
|
|
|
|
dt_fin_tz_server,
|
|
|
|
etat=etat,
|
|
|
|
raison=form.raison.data,
|
|
|
|
entry_date=dt_entry_date_tz_server,
|
|
|
|
user_id=current_user.id,
|
|
|
|
)
|
|
|
|
message = "Justificatif créé"
|
|
|
|
db.session.add(justif)
|
|
|
|
if not _upload_justificatif_files(justif, form):
|
2023-12-12 20:19:18 +01:00
|
|
|
flash("Erreur enregistrement fichiers")
|
|
|
|
log("problem in _upload_justificatif_files, rolling back")
|
2023-12-12 03:05:31 +01:00
|
|
|
db.session.rollback()
|
|
|
|
return False
|
|
|
|
db.session.commit()
|
2024-02-29 14:20:39 +01:00
|
|
|
justif.justifier_assiduites()
|
2023-12-22 15:31:30 +01:00
|
|
|
scass.simple_invalidate_cache(justif.to_dict(), etud.id)
|
|
|
|
flash(message)
|
2023-12-12 03:05:31 +01:00
|
|
|
return True
|
|
|
|
except ScoValueError as exc:
|
2023-12-22 15:31:30 +01:00
|
|
|
log(f"_record_justificatif_etud: erreur {exc.args[0]}")
|
2023-12-12 03:05:31 +01:00
|
|
|
db.session.rollback()
|
2023-12-14 20:50:27 +01:00
|
|
|
form.set_error(f"Erreur: {exc.args[0]}")
|
2023-12-12 03:05:31 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def _upload_justificatif_files(
|
|
|
|
just: Justificatif, form: AjoutJustificatifEtudForm
|
|
|
|
) -> bool:
|
|
|
|
"""Enregistre les fichiers du formulaire de création de justificatif"""
|
|
|
|
# Utilisation de l'archiver de justificatifs
|
|
|
|
archiver: JustificatifArchiver = JustificatifArchiver()
|
|
|
|
archive_name: str = just.fichier
|
|
|
|
try:
|
|
|
|
# On essaye de sauvegarder les fichiers
|
|
|
|
for file in form.fichiers.data or []:
|
|
|
|
archive_name, _ = archiver.save_justificatif(
|
|
|
|
just.etudiant,
|
|
|
|
filename=file.filename,
|
|
|
|
data=file.stream.read(),
|
|
|
|
archive_name=archive_name,
|
|
|
|
user_id=current_user.id,
|
|
|
|
)
|
|
|
|
flash(f"Fichier {file.filename} enregistré")
|
|
|
|
if form.fichiers.data:
|
|
|
|
# On actualise l'archive du justificatif
|
|
|
|
just.fichier = archive_name
|
|
|
|
db.session.add(just)
|
2023-12-12 20:19:18 +01:00
|
|
|
db.session.commit()
|
2023-12-12 03:05:31 +01:00
|
|
|
return True
|
|
|
|
except ScoValueError as exc:
|
2023-12-12 13:58:07 +01:00
|
|
|
log(
|
|
|
|
f"_upload_justificatif_files: error on {file.filename} for etud {just.etudid}"
|
|
|
|
)
|
2023-12-14 20:50:27 +01:00
|
|
|
form.set_error(f"Erreur sur fichier justificatif: {exc.args[0]}")
|
2023-12-12 03:05:31 +01:00
|
|
|
return False
|
2023-06-20 15:50:56 +02:00
|
|
|
|
|
|
|
|
2023-12-12 03:05:31 +01:00
|
|
|
@bp.route("/calendrier_assi_etud")
|
2023-06-22 16:25:13 +02:00
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
2023-12-12 03:05:31 +01:00
|
|
|
def calendrier_assi_etud():
|
2023-06-22 16:25:13 +02:00
|
|
|
"""
|
2023-12-12 03:05:31 +01:00
|
|
|
Affichage d'un calendrier de l'assiduité de l'étudiant
|
2023-06-22 16:25:13 +02:00
|
|
|
Args:
|
|
|
|
etudid (int): l'identifiant de l'étudiant
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: l'html généré
|
|
|
|
"""
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Récupération de l'étudiant
|
2023-06-22 16:25:13 +02:00
|
|
|
etudid = request.args.get("etudid", -1)
|
|
|
|
etud: Identite = Identite.query.get_or_404(etudid)
|
|
|
|
if etud.dept_id != g.scodoc_dept_id:
|
|
|
|
abort(404, "étudiant inexistant dans ce département")
|
|
|
|
|
2024-01-11 17:19:56 +01:00
|
|
|
# Options
|
|
|
|
mode_demi: bool = scu.to_bool(request.args.get("mode_demi", "t"))
|
|
|
|
show_pres: bool = scu.to_bool(request.args.get("show_pres", "f"))
|
|
|
|
show_reta: bool = scu.to_bool(request.args.get("show_reta", "f"))
|
|
|
|
annee: int = int(request.args.get("annee", scu.annee_scolaire()))
|
2023-06-22 16:25:13 +02:00
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Récupération des années d'étude de l'étudiant
|
2023-11-15 17:34:13 +01:00
|
|
|
annees: list[int] = []
|
|
|
|
for ins in etud.formsemestre_inscriptions:
|
2024-02-27 08:58:09 +01:00
|
|
|
date_deb = ins.formsemestre.date_debut
|
|
|
|
date_fin = ins.formsemestre.date_fin
|
2023-11-15 17:34:13 +01:00
|
|
|
annees.extend(
|
2024-02-27 08:58:09 +01:00
|
|
|
[
|
|
|
|
scu.annee_scolaire_repr(date_deb.year, date_deb.month),
|
|
|
|
scu.annee_scolaire_repr(date_fin.year, date_fin.month),
|
|
|
|
]
|
2023-11-15 17:34:13 +01:00
|
|
|
)
|
|
|
|
annees = sorted(annees, reverse=True)
|
2023-08-22 16:06:56 +02:00
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Transformation en une liste "json"
|
|
|
|
# (sera utilisé pour générer le selecteur d'année)
|
2024-02-27 08:58:09 +01:00
|
|
|
annees_str: str = json.dumps(annees)
|
2023-08-22 16:06:56 +02:00
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
cal = CalendrierAssi(
|
|
|
|
annee,
|
|
|
|
etud,
|
|
|
|
mode_demi=mode_demi,
|
|
|
|
show_pres=show_pres,
|
|
|
|
show_reta=show_reta,
|
|
|
|
)
|
|
|
|
calendrier: str = cal.get_html()
|
2024-01-11 17:19:56 +01:00
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Peuplement du template jinja
|
2024-01-16 16:15:48 +01:00
|
|
|
return render_template(
|
|
|
|
"assiduites/pages/calendrier_assi_etud.j2",
|
|
|
|
sco=ScoData(etud),
|
|
|
|
annee=annee,
|
|
|
|
nonworkdays=_non_work_days(),
|
|
|
|
annees=annees_str,
|
|
|
|
calendrier=calendrier,
|
|
|
|
mode_demi=mode_demi,
|
|
|
|
show_pres=show_pres,
|
|
|
|
show_reta=show_reta,
|
|
|
|
)
|
2023-06-22 16:25:13 +02:00
|
|
|
|
|
|
|
|
2023-12-31 22:18:13 +01:00
|
|
|
@bp.route("/signal_assiduites_group")
|
2023-04-17 15:44:55 +02:00
|
|
|
@scodoc
|
2023-09-29 21:17:31 +02:00
|
|
|
@permission_required(Permission.AbsChange)
|
2023-04-17 15:44:55 +02:00
|
|
|
def signal_assiduites_group():
|
|
|
|
"""
|
2024-01-17 21:58:45 +01:00
|
|
|
signal_assiduites_group Saisie des assiduités des groupes pour le jour donné
|
2023-04-17 15:44:55 +02:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: l'html généré
|
|
|
|
"""
|
2023-10-27 16:05:40 +02:00
|
|
|
# Récupération des paramètres de l'url
|
2024-01-17 21:58:45 +01:00
|
|
|
# formsemestre_id est optionnel si modimpl est indiqué
|
2023-04-17 15:44:55 +02:00
|
|
|
formsemestre_id: int = request.args.get("formsemestre_id", -1)
|
|
|
|
moduleimpl_id: int = request.args.get("moduleimpl_id")
|
2024-05-30 10:51:24 +02:00
|
|
|
date: str = request.args.get("day", datetime.date.today().isoformat())
|
2023-11-13 08:35:19 +01:00
|
|
|
heures: list[str] = [
|
|
|
|
request.args.get("heure_deb", ""),
|
|
|
|
request.args.get("heure_fin", ""),
|
|
|
|
]
|
2023-04-17 15:44:55 +02:00
|
|
|
group_ids: list[int] = request.args.get("group_ids", None)
|
2023-07-26 16:43:49 +02:00
|
|
|
if group_ids is None:
|
|
|
|
group_ids = []
|
|
|
|
else:
|
|
|
|
group_ids = group_ids.split(",")
|
|
|
|
map(str, group_ids)
|
|
|
|
|
|
|
|
# Vérification du moduleimpl_id
|
|
|
|
try:
|
|
|
|
moduleimpl_id = int(moduleimpl_id)
|
|
|
|
except (TypeError, ValueError):
|
|
|
|
moduleimpl_id = None
|
2024-01-17 23:51:45 +01:00
|
|
|
if moduleimpl_id is not None and moduleimpl_id >= 0:
|
2024-01-17 21:58:45 +01:00
|
|
|
modimpl = ModuleImpl.get_modimpl(moduleimpl_id)
|
|
|
|
else:
|
|
|
|
modimpl = None
|
2023-07-26 16:43:49 +02:00
|
|
|
# Vérification du formsemestre_id
|
|
|
|
try:
|
|
|
|
formsemestre_id = int(formsemestre_id)
|
|
|
|
except (TypeError, ValueError):
|
|
|
|
formsemestre_id = None
|
|
|
|
|
2024-01-17 21:58:45 +01:00
|
|
|
if (formsemestre_id < 0 or formsemestre_id is None) and modimpl:
|
|
|
|
# si le module est spécifié mais pas le semestre:
|
|
|
|
formsemestre_id = modimpl.formsemestre_id
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Gestion des groupes
|
2023-07-26 16:43:49 +02:00
|
|
|
groups_infos = sco_groups_view.DisplayedGroupsInfos(
|
2023-12-31 22:18:13 +01:00
|
|
|
group_ids,
|
|
|
|
moduleimpl_id=moduleimpl_id,
|
|
|
|
formsemestre_id=formsemestre_id,
|
|
|
|
select_all_when_unspecified=True,
|
2023-07-26 16:43:49 +02:00
|
|
|
)
|
|
|
|
if not groups_infos.members:
|
|
|
|
return (
|
2024-05-23 08:59:10 +02:00
|
|
|
html_sco_header.sco_header(page_title="Saisie de l'assiduité")
|
2023-07-26 16:43:49 +02:00
|
|
|
+ "<h3>Aucun étudiant ! </h3>"
|
|
|
|
+ html_sco_header.sco_footer()
|
|
|
|
)
|
|
|
|
|
|
|
|
# --- Filtrage par formsemestre ---
|
|
|
|
formsemestre_id = groups_infos.formsemestre_id
|
|
|
|
|
|
|
|
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
|
|
|
if formsemestre.dept_id != g.scodoc_dept_id:
|
|
|
|
abort(404, "groupes inexistants dans ce département")
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Récupération des étudiants des groupes
|
2023-07-26 16:43:49 +02:00
|
|
|
etuds = [
|
|
|
|
sco_etud.get_etud_info(etudid=m["etudid"], filled=True)[0]
|
|
|
|
for m in groups_infos.members
|
|
|
|
]
|
|
|
|
|
|
|
|
# --- Vérification de la date ---
|
|
|
|
real_date = scu.is_iso_formated(date, True).date()
|
|
|
|
|
2023-09-13 08:59:54 +02:00
|
|
|
if real_date < formsemestre.date_debut or real_date > formsemestre.date_fin:
|
2024-01-12 10:52:40 +01:00
|
|
|
# Si le jour est hors semestre, renvoyer vers choix date
|
2024-05-30 10:51:24 +02:00
|
|
|
flash(
|
|
|
|
"La date sélectionnée n'est pas dans le semestre. Choisissez une autre date."
|
|
|
|
)
|
|
|
|
|
|
|
|
return sco_gen_cal.calendrier_choix_date(
|
|
|
|
formsemestre.date_debut,
|
|
|
|
formsemestre.date_fin,
|
|
|
|
url=url_for(
|
|
|
|
"assiduites.signal_assiduites_group",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
2024-01-12 10:52:40 +01:00
|
|
|
formsemestre_id=formsemestre_id,
|
2024-05-30 10:51:24 +02:00
|
|
|
group_ids=",".join(group_ids),
|
2024-01-12 10:52:40 +01:00
|
|
|
moduleimpl_id=moduleimpl_id,
|
2024-05-30 10:51:24 +02:00
|
|
|
day="placeholder",
|
|
|
|
),
|
|
|
|
mode="jour",
|
|
|
|
titre="Choix de la date",
|
2023-09-13 08:59:54 +02:00
|
|
|
)
|
2023-07-26 16:43:49 +02:00
|
|
|
|
|
|
|
# --- Restriction en fonction du moduleimpl_id ---
|
|
|
|
if moduleimpl_id:
|
|
|
|
mod_inscrits = {
|
|
|
|
x["etudid"]
|
|
|
|
for x in sco_moduleimpl.do_moduleimpl_inscription_list(
|
|
|
|
moduleimpl_id=moduleimpl_id
|
|
|
|
)
|
|
|
|
}
|
|
|
|
etuds_inscrits_module = [e for e in etuds if e["etudid"] in mod_inscrits]
|
|
|
|
if etuds_inscrits_module:
|
|
|
|
etuds = etuds_inscrits_module
|
|
|
|
else:
|
|
|
|
# Si aucun etudiant n'est inscrit au module choisi...
|
|
|
|
moduleimpl_id = None
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Récupération du nom des/du groupe(s)
|
2023-07-26 16:43:49 +02:00
|
|
|
|
|
|
|
if groups_infos.tous_les_etuds_du_sem:
|
|
|
|
gr_tit = "en"
|
|
|
|
else:
|
|
|
|
if len(groups_infos.group_ids) > 1:
|
|
|
|
grp = "des groupes"
|
|
|
|
else:
|
|
|
|
grp = "du groupe"
|
|
|
|
gr_tit = (
|
|
|
|
grp + ' <span class="fontred">' + groups_infos.groups_titles + "</span>"
|
|
|
|
)
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Récupération du semestre en dictionnaire
|
|
|
|
sem = formsemestre.to_dict()
|
|
|
|
|
2024-01-21 22:21:10 +01:00
|
|
|
# Page HTML
|
|
|
|
return render_template(
|
|
|
|
"assiduites/pages/signal_assiduites_group.j2",
|
|
|
|
date=_dateiso_to_datefr(date),
|
|
|
|
defdem=_get_etuds_dem_def(formsemestre),
|
|
|
|
forcer_module=sco_preferences.get_preference(
|
|
|
|
"forcer_module",
|
2023-07-26 16:43:49 +02:00
|
|
|
formsemestre_id=formsemestre_id,
|
2024-01-21 22:21:10 +01:00
|
|
|
dept_id=g.scodoc_dept_id,
|
2023-07-26 16:43:49 +02:00
|
|
|
),
|
2024-04-22 15:05:31 +02:00
|
|
|
non_present=sco_preferences.get_preference(
|
|
|
|
"non_present",
|
|
|
|
formsemestre_id=formsemestre_id,
|
|
|
|
dept_id=g.scodoc_dept_id,
|
|
|
|
),
|
2024-01-21 22:21:10 +01:00
|
|
|
formsemestre_date_debut=str(formsemestre.date_debut),
|
|
|
|
formsemestre_date_fin=str(formsemestre.date_fin),
|
|
|
|
formsemestre_id=formsemestre_id,
|
|
|
|
gr_tit=gr_tit,
|
|
|
|
grp=sco_groups_view.menu_groups_choice(groups_infos),
|
|
|
|
minitimeline=_mini_timeline(),
|
|
|
|
moduleimpl_select=_module_selector(formsemestre, moduleimpl_id),
|
|
|
|
nonworkdays=_non_work_days(),
|
|
|
|
readonly="false",
|
|
|
|
sco=ScoData(formsemestre=formsemestre),
|
|
|
|
sem=sem["titre_num"],
|
|
|
|
timeline=_timeline(heures=",".join([f"'{s}'" for s in heures])),
|
2024-05-23 08:59:10 +02:00
|
|
|
title="Saisie de l'assiduité",
|
2024-01-21 22:21:10 +01:00
|
|
|
)
|
2023-07-26 16:43:49 +02:00
|
|
|
|
|
|
|
|
2023-12-09 15:53:45 +01:00
|
|
|
class RowEtudWithAssi(RowEtud):
|
|
|
|
"""Ligne de la table d'étudiants avec colonne Assiduité"""
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
table: TableEtud,
|
|
|
|
etud: Identite,
|
|
|
|
etat_assiduite: str,
|
2024-01-18 09:36:38 +01:00
|
|
|
est_just: bool,
|
2023-12-09 15:53:45 +01:00
|
|
|
*args,
|
|
|
|
**kwargs,
|
|
|
|
):
|
|
|
|
super().__init__(table, etud, *args, **kwargs)
|
|
|
|
self.etat_assiduite = etat_assiduite
|
2024-01-18 09:36:38 +01:00
|
|
|
self.est_just = est_just
|
2023-12-09 15:53:45 +01:00
|
|
|
# remplace lien vers fiche par lien vers calendrier
|
|
|
|
self.target_url = url_for(
|
2023-12-12 03:05:31 +01:00
|
|
|
"assiduites.calendrier_assi_etud", scodoc_dept=g.scodoc_dept, etudid=etud.id
|
2023-12-09 15:53:45 +01:00
|
|
|
)
|
|
|
|
self.target_title = f"Calendrier de {etud.nomprenom}"
|
|
|
|
|
|
|
|
def add_etud_cols(self):
|
|
|
|
"""Ajoute colonnes pour cet étudiant"""
|
|
|
|
super().add_etud_cols()
|
|
|
|
self.add_cell(
|
|
|
|
"assi-type",
|
|
|
|
"Présence",
|
|
|
|
self.etat_assiduite,
|
|
|
|
"assi-type",
|
|
|
|
)
|
|
|
|
self.classes += ["row-assiduite", self.etat_assiduite.lower()]
|
|
|
|
|
2024-01-18 09:36:38 +01:00
|
|
|
if self.est_just:
|
|
|
|
self.classes += ["justifiee"]
|
|
|
|
|
2023-12-09 15:53:45 +01:00
|
|
|
|
2023-08-30 08:53:36 +02:00
|
|
|
@bp.route("/etat_abs_date")
|
2023-05-30 17:16:07 +02:00
|
|
|
@scodoc
|
2023-06-01 17:32:50 +02:00
|
|
|
@permission_required(Permission.ScoView)
|
2023-08-30 08:53:36 +02:00
|
|
|
def etat_abs_date():
|
2023-12-09 15:53:45 +01:00
|
|
|
"""Tableau de l'état d'assiduité d'un ou plusieurs groupes
|
|
|
|
sur la plage de dates date_debut, date_fin.
|
2023-12-09 16:03:17 +01:00
|
|
|
group_ids : ids de(s) groupe(s)
|
2023-12-09 15:53:45 +01:00
|
|
|
date_debut, date_fin: format ISO
|
|
|
|
evaluation_id: optionnel, évaluation concernée, pour titre et liens.
|
|
|
|
date_debut, date_fin en ISO
|
2023-12-09 16:03:17 +01:00
|
|
|
fmt : format export (xls, défaut html)
|
2023-12-09 15:53:45 +01:00
|
|
|
"""
|
2023-10-27 16:05:40 +02:00
|
|
|
|
2023-12-09 15:53:45 +01:00
|
|
|
# Récupération des paramètres de la requête
|
2023-08-29 19:30:56 +02:00
|
|
|
date_debut_str = request.args.get("date_debut")
|
|
|
|
date_fin_str = request.args.get("date_fin")
|
2023-12-09 16:03:17 +01:00
|
|
|
fmt = request.args.get("fmt", "html")
|
2023-12-09 15:53:45 +01:00
|
|
|
group_ids = request.args.getlist("group_ids", int)
|
|
|
|
evaluation_id = request.args.get("evaluation_id")
|
|
|
|
evaluation: Evaluation = (
|
|
|
|
Evaluation.query.get_or_404(evaluation_id)
|
|
|
|
if evaluation_id is not None
|
|
|
|
else None
|
|
|
|
)
|
2023-10-27 16:05:40 +02:00
|
|
|
# Vérification des dates
|
2023-08-29 19:30:56 +02:00
|
|
|
try:
|
|
|
|
date_debut = datetime.datetime.fromisoformat(date_debut_str)
|
|
|
|
except ValueError as exc:
|
|
|
|
raise ScoValueError("date_debut invalide") from exc
|
|
|
|
try:
|
|
|
|
date_fin = datetime.datetime.fromisoformat(date_fin_str)
|
|
|
|
except ValueError as exc:
|
|
|
|
raise ScoValueError("date_fin invalide") from exc
|
2023-10-27 16:05:40 +02:00
|
|
|
|
2023-12-09 15:53:45 +01:00
|
|
|
# Les groupes:
|
|
|
|
groups = [GroupDescr.query.get_or_404(group_id) for group_id in group_ids]
|
|
|
|
# Les étudiants de tous les groupes sélectionnés, flat list
|
2023-05-30 17:16:07 +02:00
|
|
|
etuds = [
|
2023-12-09 15:53:45 +01:00
|
|
|
etud for gr_etuds in [group.etuds for group in groups] for etud in gr_etuds
|
2023-05-30 17:16:07 +02:00
|
|
|
]
|
2023-12-09 15:53:45 +01:00
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Récupération des assiduites des étudiants
|
2023-05-30 17:16:07 +02:00
|
|
|
assiduites: Assiduite = Assiduite.query.filter(
|
2023-12-09 15:53:45 +01:00
|
|
|
Assiduite.etudid.in_([etud.id for etud in etuds])
|
2023-05-30 17:16:07 +02:00
|
|
|
)
|
2023-10-27 16:05:40 +02:00
|
|
|
# Filtrage des assiduités en fonction des dates données
|
2024-01-18 09:36:38 +01:00
|
|
|
assiduites = scass.filter_by_date(assiduites, Assiduite, date_debut, date_fin)
|
2023-05-30 17:16:07 +02:00
|
|
|
|
2023-12-09 15:53:45 +01:00
|
|
|
# Génération table
|
|
|
|
table = TableEtud(row_class=RowEtudWithAssi)
|
|
|
|
for etud in sorted(etuds, key=lambda e: e.sort_key):
|
2023-10-27 16:05:40 +02:00
|
|
|
# On récupère l'état de la première assiduité sur la période
|
2023-12-09 15:53:45 +01:00
|
|
|
assi = assiduites.filter_by(etudid=etud.id).first()
|
2023-05-30 17:16:07 +02:00
|
|
|
etat = ""
|
2024-01-22 17:01:01 +01:00
|
|
|
if assi is not None:
|
|
|
|
if assi.etat != scu.EtatAssiduite.PRESENT:
|
|
|
|
etat = scu.EtatAssiduite.inverse().get(assi.etat).name
|
|
|
|
row = table.row_class(table, etud, etat, assi.est_just)
|
|
|
|
row.add_etud_cols()
|
|
|
|
table.add_row(row)
|
2023-05-30 17:16:07 +02:00
|
|
|
|
2023-12-09 16:03:17 +01:00
|
|
|
if fmt.startswith("xls"):
|
|
|
|
return scu.send_file(
|
|
|
|
table.excel(),
|
|
|
|
filename=f"assiduite-eval-{date_debut.isoformat()}",
|
|
|
|
mime=scu.XLSX_MIMETYPE,
|
|
|
|
suffix=scu.XLSX_SUFFIX,
|
|
|
|
)
|
2023-12-09 15:53:45 +01:00
|
|
|
return render_template(
|
|
|
|
"assiduites/pages/etat_abs_date.j2",
|
|
|
|
date_debut=date_debut,
|
|
|
|
date_fin=date_fin,
|
|
|
|
evaluation=evaluation,
|
|
|
|
etuds=etuds,
|
|
|
|
group_title=", ".join(gr.get_nom_with_part("tous") for gr in groups),
|
|
|
|
sco=ScoData(),
|
|
|
|
table=table,
|
2023-05-30 17:16:07 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-12-15 01:31:15 +01:00
|
|
|
@bp.route("/visu_assi_group")
|
2023-07-10 17:38:50 +02:00
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
|
|
|
def visu_assi_group():
|
2024-02-08 11:05:57 +01:00
|
|
|
"""Visualisation de l'assiduité d'un groupe entre deux dates.
|
|
|
|
Paramètres:
|
|
|
|
- date_debut, date_fin (format ISO)
|
|
|
|
- fmt : format d'export, html (défaut) ou xls
|
|
|
|
- group_ids : liste des groupes
|
2024-02-08 15:56:58 +01:00
|
|
|
- formsemestre_modimpls_id: id d'un formasemestre, si fournit restreint les
|
|
|
|
comptages aux assiduités liées à des modules de ce formsemestre.
|
2024-02-08 11:05:57 +01:00
|
|
|
"""
|
2023-10-27 16:05:40 +02:00
|
|
|
|
|
|
|
# Récupération des paramètres de la requête
|
2023-07-10 17:38:50 +02:00
|
|
|
dates = {
|
|
|
|
"debut": request.args.get("date_debut"),
|
|
|
|
"fin": request.args.get("date_fin"),
|
|
|
|
}
|
2024-02-08 15:56:58 +01:00
|
|
|
formsemestre_modimpls_id = request.args.get("formsemestre_modimpls_id")
|
|
|
|
formsemestre_modimpls = (
|
|
|
|
None
|
|
|
|
if formsemestre_modimpls_id is None
|
|
|
|
else FormSemestre.get_formsemestre(formsemestre_modimpls_id)
|
|
|
|
)
|
2023-09-21 10:20:19 +02:00
|
|
|
fmt = request.args.get("fmt", "html")
|
2023-07-10 17:38:50 +02:00
|
|
|
|
|
|
|
group_ids: list[int] = request.args.get("group_ids", None)
|
|
|
|
if group_ids is None:
|
|
|
|
group_ids = []
|
|
|
|
else:
|
|
|
|
group_ids = group_ids.split(",")
|
|
|
|
map(str, group_ids)
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Récupération des groupes, du semestre et des étudiants
|
2023-07-10 17:38:50 +02:00
|
|
|
groups_infos = sco_groups_view.DisplayedGroupsInfos(group_ids)
|
2023-07-26 13:27:57 +02:00
|
|
|
formsemestre = db.session.get(FormSemestre, groups_infos.formsemestre_id)
|
2023-07-10 17:38:50 +02:00
|
|
|
etuds = etuds_sorted_from_ids([m["etudid"] for m in groups_infos.members])
|
2023-10-27 16:05:40 +02:00
|
|
|
|
|
|
|
# Génération du tableau des assiduités
|
2023-07-26 13:27:57 +02:00
|
|
|
table: TableAssi = TableAssi(
|
2024-02-08 11:05:57 +01:00
|
|
|
etuds=etuds,
|
|
|
|
dates=list(dates.values()),
|
|
|
|
formsemestre=formsemestre,
|
2024-02-08 15:56:58 +01:00
|
|
|
formsemestre_modimpls=formsemestre_modimpls,
|
|
|
|
convert_values=(fmt == "html"),
|
2023-07-26 13:27:57 +02:00
|
|
|
)
|
2023-10-27 16:05:40 +02:00
|
|
|
# Export en XLS
|
2023-07-20 15:53:59 +02:00
|
|
|
if fmt.startswith("xls"):
|
|
|
|
return scu.send_file(
|
|
|
|
table.excel(),
|
|
|
|
filename=f"assiduite-{groups_infos.groups_filename}",
|
|
|
|
mime=scu.XLSX_MIMETYPE,
|
|
|
|
suffix=scu.XLSX_SUFFIX,
|
|
|
|
)
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# récupération du/des noms du/des groupes
|
2023-07-10 17:38:50 +02:00
|
|
|
if groups_infos.tous_les_etuds_du_sem:
|
2023-07-25 14:03:09 +02:00
|
|
|
gr_tit = ""
|
|
|
|
grp = ""
|
2023-07-10 17:38:50 +02:00
|
|
|
else:
|
|
|
|
if len(groups_infos.group_ids) > 1:
|
|
|
|
grp = "des groupes"
|
|
|
|
else:
|
|
|
|
grp = "du groupe"
|
|
|
|
gr_tit = (
|
|
|
|
grp + ' <span class="fontred">' + groups_infos.groups_titles + "</span>"
|
|
|
|
)
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Génération de la page
|
2023-07-20 15:53:59 +02:00
|
|
|
return render_template(
|
2023-12-15 01:31:15 +01:00
|
|
|
"assiduites/pages/visu_assi_group.j2",
|
2023-08-22 15:43:10 +02:00
|
|
|
assi_metric=scu.translate_assiduites_metric(
|
|
|
|
scu.translate_assiduites_metric(
|
|
|
|
sco_preferences.get_preference(
|
|
|
|
"assi_metrique", dept_id=g.scodoc_dept_id
|
|
|
|
),
|
|
|
|
),
|
|
|
|
inverse=False,
|
|
|
|
short=False,
|
2023-08-13 22:40:16 +02:00
|
|
|
),
|
2023-11-15 14:11:47 +01:00
|
|
|
date_debut=_dateiso_to_datefr(dates["debut"]),
|
2023-11-17 11:36:15 +01:00
|
|
|
date_fin=_dateiso_to_datefr(dates["fin"]),
|
2023-08-13 22:40:16 +02:00
|
|
|
gr_tit=gr_tit,
|
2023-07-20 15:53:59 +02:00
|
|
|
group_ids=request.args.get("group_ids", None),
|
|
|
|
sco=ScoData(formsemestre=groups_infos.get_formsemestre()),
|
2023-08-13 22:40:16 +02:00
|
|
|
tableau=table.html(),
|
2023-07-20 15:53:59 +02:00
|
|
|
title=f"Assiduité {grp} {groups_infos.groups_titles}",
|
|
|
|
)
|
2023-07-10 17:38:50 +02:00
|
|
|
|
|
|
|
|
2024-06-27 21:22:19 +02:00
|
|
|
def _get_anne_sco_from_request() -> int | None:
|
|
|
|
"""La valeur du paramètreannee_sco de la requête GET,
|
|
|
|
ou None si absent"""
|
|
|
|
annee_sco: str | None = request.args.get("annee_sco", None)
|
|
|
|
# Vérification de l'année scolaire
|
|
|
|
if annee_sco is not None:
|
|
|
|
try:
|
|
|
|
return int(annee_sco)
|
|
|
|
except (ValueError, TypeError):
|
|
|
|
pass
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2023-12-01 13:46:33 +01:00
|
|
|
def _prepare_tableau(
|
|
|
|
data: liste_assi.AssiJustifData,
|
2023-11-24 13:58:03 +01:00
|
|
|
filename: str = "tableau-assiduites",
|
|
|
|
afficher_etu: bool = True,
|
2023-12-01 13:46:33 +01:00
|
|
|
filtre: liste_assi.AssiFiltre = None,
|
|
|
|
options: liste_assi.AssiDisplayOptions = None,
|
2023-11-24 18:07:30 +01:00
|
|
|
afficher_options: bool = True,
|
2024-06-27 19:13:39 +02:00
|
|
|
moduleimpl_select: str = None,
|
2023-12-12 03:05:31 +01:00
|
|
|
titre="Évènements enregistrés pour cet étudiant",
|
2024-01-11 17:24:01 +01:00
|
|
|
cache_key: str = "",
|
2024-02-28 10:23:47 +01:00
|
|
|
force_options: dict[str, object] = None,
|
2024-06-27 21:22:19 +02:00
|
|
|
annee_sco: int | None = None,
|
2023-12-01 13:46:33 +01:00
|
|
|
) -> tuple[bool, Response | str]:
|
2023-11-24 13:58:03 +01:00
|
|
|
"""
|
2023-12-01 13:46:33 +01:00
|
|
|
Prépare un tableau d'assiduités / justificatifs
|
2023-11-22 16:49:13 +01:00
|
|
|
|
2023-12-01 13:46:33 +01:00
|
|
|
Cette fonction récupère dans la requête les arguments :
|
2023-11-24 13:58:03 +01:00
|
|
|
|
2024-06-27 21:22:19 +02:00
|
|
|
annee_sco : int -> XXX
|
|
|
|
n_page : int -> XXX
|
|
|
|
page_number : int -> XXX
|
2023-11-24 13:58:03 +01:00
|
|
|
show_pres : bool -> Affiche les présences, par défaut False
|
|
|
|
show_reta : bool -> Affiche les retard, par défaut False
|
|
|
|
show_desc : bool -> Affiche les descriptions, par défaut False
|
|
|
|
|
|
|
|
Returns:
|
2023-12-01 13:46:33 +01:00
|
|
|
tuple[bool | Reponse|str ]:
|
2023-11-24 13:58:03 +01:00
|
|
|
- bool : Vrai si la réponse est du Text/HTML
|
|
|
|
- Reponse : du Text/HTML ou Une Reponse (téléchargement fichier)
|
|
|
|
"""
|
2023-11-22 16:49:13 +01:00
|
|
|
|
|
|
|
show_pres: bool | str = request.args.get("show_pres", False)
|
|
|
|
show_reta: bool | str = request.args.get("show_reta", False)
|
2023-11-24 13:58:03 +01:00
|
|
|
show_desc: bool | str = request.args.get("show_desc", False)
|
2024-06-27 21:22:19 +02:00
|
|
|
annee_sco = _get_anne_sco_from_request() if annee_sco is None else annee_sco
|
2023-11-22 16:49:13 +01:00
|
|
|
nb_ligne_page: int = request.args.get("nb_ligne_page")
|
|
|
|
# Vérification de nb_ligne_page
|
|
|
|
try:
|
|
|
|
nb_ligne_page: int = int(nb_ligne_page)
|
|
|
|
except (ValueError, TypeError):
|
2023-11-24 13:58:03 +01:00
|
|
|
nb_ligne_page = liste_assi.ListeAssiJusti.NB_PAR_PAGE
|
2023-11-22 16:49:13 +01:00
|
|
|
|
|
|
|
page_number: int = request.args.get("n_page", 1)
|
|
|
|
# Vérification de page_number
|
|
|
|
try:
|
|
|
|
page_number: int = int(page_number)
|
|
|
|
except (ValueError, TypeError):
|
|
|
|
page_number = 1
|
2023-11-03 14:57:22 +01:00
|
|
|
|
2023-11-24 13:58:03 +01:00
|
|
|
fmt = request.args.get("fmt", "html")
|
|
|
|
|
2024-01-11 17:24:01 +01:00
|
|
|
# Ordre
|
|
|
|
ordre: tuple[str, str | bool] = None
|
|
|
|
ordre_col: str = request.args.get("order_col", None)
|
|
|
|
ordre_tri: str = request.args.get("order", None)
|
|
|
|
if ordre_col is not None and ordre_tri is not None:
|
|
|
|
ordre = (ordre_col, ordre_tri == "ascending")
|
|
|
|
|
2023-11-24 13:58:03 +01:00
|
|
|
if options is None:
|
2023-12-01 13:46:33 +01:00
|
|
|
options: liste_assi.AssiDisplayOptions = liste_assi.AssiDisplayOptions()
|
2023-11-24 13:58:03 +01:00
|
|
|
|
|
|
|
options.remplacer(
|
|
|
|
page=page_number,
|
|
|
|
nb_ligne_page=nb_ligne_page,
|
|
|
|
show_pres=show_pres,
|
|
|
|
show_reta=show_reta,
|
|
|
|
show_desc=show_desc,
|
|
|
|
show_etu=afficher_etu,
|
2024-01-11 17:24:01 +01:00
|
|
|
order=ordre,
|
2024-03-27 11:51:50 +01:00
|
|
|
annee_sco=annee_sco,
|
2023-11-24 13:58:03 +01:00
|
|
|
)
|
2023-10-26 13:12:22 +02:00
|
|
|
|
2024-02-28 10:23:47 +01:00
|
|
|
if force_options is not None:
|
|
|
|
options.remplacer(**force_options)
|
|
|
|
|
2023-11-24 13:58:03 +01:00
|
|
|
table: liste_assi.ListeAssiJusti = liste_assi.ListeAssiJusti(
|
2023-11-24 18:07:30 +01:00
|
|
|
table_data=data,
|
2023-11-24 13:58:03 +01:00
|
|
|
options=options,
|
|
|
|
filtre=filtre,
|
2024-01-11 17:24:01 +01:00
|
|
|
no_pagination=fmt.startswith("xls"),
|
|
|
|
titre=cache_key,
|
2023-11-22 16:49:13 +01:00
|
|
|
)
|
2023-10-26 13:12:22 +02:00
|
|
|
|
|
|
|
if fmt.startswith("xls"):
|
2023-11-24 13:58:03 +01:00
|
|
|
return False, scu.send_file(
|
2023-10-26 13:12:22 +02:00
|
|
|
table.excel(),
|
2023-11-24 13:58:03 +01:00
|
|
|
filename=filename,
|
2023-10-26 13:12:22 +02:00
|
|
|
mime=scu.XLSX_MIMETYPE,
|
|
|
|
suffix=scu.XLSX_SUFFIX,
|
|
|
|
)
|
|
|
|
|
2023-11-24 13:58:03 +01:00
|
|
|
return True, render_template(
|
|
|
|
"assiduites/widgets/tableau.j2",
|
2023-12-01 13:46:33 +01:00
|
|
|
table=table,
|
2023-11-22 16:49:13 +01:00
|
|
|
total_pages=table.total_pages,
|
2023-11-24 13:58:03 +01:00
|
|
|
options=options,
|
2023-11-24 18:07:30 +01:00
|
|
|
afficher_options=afficher_options,
|
2023-12-12 03:05:31 +01:00
|
|
|
titre=titre,
|
2024-06-27 19:13:39 +02:00
|
|
|
moduleimpl_select=moduleimpl_select,
|
2023-10-26 13:12:22 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-03-19 15:32:39 +01:00
|
|
|
@bp.route("/recup_assiduites_plage", methods=["POST"])
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.AbsChange)
|
|
|
|
def recup_assiduites_plage():
|
|
|
|
"""
|
|
|
|
Renvoie un fichier excel contenant toutes les assiduités d'une plage
|
|
|
|
La plage est définie par les valeurs "datedeb" et "datefin" du formulaire
|
|
|
|
Par défaut tous les étudiants du département sont concernés
|
|
|
|
Si le champs "formsemestre_id" est présent dans le formulaire et est non vide,
|
|
|
|
seuls les étudiants inscrits dans ce semestre sont concernés.
|
|
|
|
"""
|
|
|
|
|
|
|
|
date_deb: datetime.datetime = request.form.get("datedeb")
|
|
|
|
date_fin: datetime.datetime = request.form.get("datefin")
|
|
|
|
|
|
|
|
# Vérification des dates
|
|
|
|
try:
|
2024-04-02 23:37:23 +02:00
|
|
|
date_deb = datetime.datetime.strptime(date_deb, scu.DATE_FMT)
|
2024-03-19 15:32:39 +01:00
|
|
|
except ValueError as exc:
|
|
|
|
raise ScoValueError("date_debut invalide", dest_url=request.referrer) from exc
|
|
|
|
try:
|
2024-04-02 23:37:23 +02:00
|
|
|
date_fin = datetime.datetime.strptime(date_fin, scu.DATE_FMT)
|
2024-03-19 15:32:39 +01:00
|
|
|
except ValueError as exc:
|
|
|
|
raise ScoValueError("date_fin invalide", dest_url=request.referrer) from exc
|
|
|
|
|
|
|
|
# Récupération des étudiants
|
|
|
|
etuds: Query = []
|
|
|
|
formsemestre_id: str | None = request.form.get("formsemestre_id")
|
|
|
|
|
|
|
|
name: str = ""
|
|
|
|
|
|
|
|
if formsemestre_id is not None and formsemestre_id != "":
|
|
|
|
formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
|
|
|
etuds = formsemestre.etuds
|
|
|
|
name = formsemestre.session_id()
|
|
|
|
else:
|
|
|
|
dept: Departement = Departement.query.get_or_404(g.scodoc_dept_id)
|
|
|
|
etuds = dept.etudiants
|
|
|
|
name = dept.acronym
|
|
|
|
|
2024-03-27 15:01:58 +01:00
|
|
|
# Récupération des assiduités/justificatifs
|
|
|
|
etudids: list[int] = [etud.id for etud in etuds]
|
|
|
|
assiduites: Query = Assiduite.query.filter(Assiduite.etudid.in_(etudids))
|
|
|
|
justificatifs: Query = Justificatif.query.filter(Justificatif.etudid.in_(etudids))
|
2024-03-19 15:32:39 +01:00
|
|
|
|
2024-03-27 15:01:58 +01:00
|
|
|
# Filtrage des assiduités/justificatifs en fonction des dates données
|
2024-03-19 15:32:39 +01:00
|
|
|
assiduites = scass.filter_by_date(assiduites, Assiduite, date_deb, date_fin)
|
2024-03-27 15:01:58 +01:00
|
|
|
justificatifs = scass.filter_by_date(
|
|
|
|
justificatifs, Justificatif, date_deb, date_fin
|
|
|
|
)
|
2024-03-19 15:32:39 +01:00
|
|
|
|
|
|
|
table_data: liste_assi.AssiJustifData = liste_assi.AssiJustifData(
|
|
|
|
assiduites_query=assiduites,
|
2024-03-27 15:01:58 +01:00
|
|
|
justificatifs_query=justificatifs,
|
2024-03-19 15:32:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
options: liste_assi.AssiDisplayOptions = liste_assi.AssiDisplayOptions(
|
|
|
|
show_pres=True,
|
|
|
|
show_reta=True,
|
|
|
|
show_module=True,
|
2024-03-27 15:01:58 +01:00
|
|
|
show_desc=True,
|
2024-03-19 15:32:39 +01:00
|
|
|
show_etu=True,
|
2024-03-27 15:01:58 +01:00
|
|
|
annee_sco=-1,
|
2024-03-19 15:32:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
date_deb_str: str = date_deb.strftime("%d-%m-%Y")
|
|
|
|
date_fin_str: str = date_fin.strftime("%d-%m-%Y")
|
|
|
|
|
|
|
|
filename: str = f"assiduites_{name}_{date_deb_str}_{date_fin_str}"
|
|
|
|
|
|
|
|
tableau: liste_assi.ListeAssiJusti = liste_assi.ListeAssiJusti(
|
|
|
|
table_data,
|
|
|
|
options=options,
|
|
|
|
titre="tableau-dept-" + filename,
|
|
|
|
no_pagination=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
return scu.send_file(
|
|
|
|
tableau.excel(),
|
|
|
|
filename=filename,
|
|
|
|
mime=scu.XLSX_MIMETYPE,
|
|
|
|
suffix=scu.XLSX_SUFFIX,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-12-07 22:10:51 +01:00
|
|
|
@bp.route("/tableau_assiduite_actions", methods=["GET", "POST"])
|
2023-11-24 13:58:03 +01:00
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.AbsChange)
|
|
|
|
def tableau_assiduite_actions():
|
2023-12-06 14:42:10 +01:00
|
|
|
"""Edition/suppression/information sur une assiduité ou un justificatif
|
|
|
|
type = "assiduite" | "justificatif"
|
2024-01-08 19:06:44 +01:00
|
|
|
action = "supprimer" | "details" | "justifier"
|
2023-12-06 14:42:10 +01:00
|
|
|
"""
|
2023-11-24 13:58:03 +01:00
|
|
|
obj_type: str = request.args.get("type", "assiduite")
|
|
|
|
action: str = request.args.get("action", "details")
|
|
|
|
obj_id: str = int(request.args.get("obj_id", -1))
|
|
|
|
|
|
|
|
objet: Assiduite | Justificatif
|
2023-12-06 14:42:10 +01:00
|
|
|
objet_name = ""
|
2023-11-24 13:58:03 +01:00
|
|
|
if obj_type == "assiduite":
|
|
|
|
objet: Assiduite = Assiduite.query.get_or_404(obj_id)
|
2023-12-06 14:42:10 +01:00
|
|
|
objet_name = scu.EtatAssiduite(objet.etat).version_lisible()
|
2023-11-24 13:58:03 +01:00
|
|
|
else:
|
|
|
|
objet: Justificatif = Justificatif.query.get_or_404(obj_id)
|
2023-12-06 14:42:10 +01:00
|
|
|
objet_name = "Justificatif"
|
2023-11-24 13:58:03 +01:00
|
|
|
|
2023-12-06 14:42:10 +01:00
|
|
|
# Suppression : attention, POST ou GET !
|
2023-11-24 13:58:03 +01:00
|
|
|
if action == "supprimer":
|
2023-12-07 12:38:47 +01:00
|
|
|
objet.supprime()
|
2023-12-06 14:42:10 +01:00
|
|
|
flash(f"{objet_name} supprimé")
|
2023-11-24 13:58:03 +01:00
|
|
|
|
|
|
|
return redirect(request.referrer)
|
|
|
|
|
2024-01-08 19:06:44 +01:00
|
|
|
# Justification d'une assiduité depuis le tableau
|
|
|
|
if action == "justifier" and obj_type == "assiduite":
|
2024-06-26 10:32:15 +02:00
|
|
|
# L'état est Valide si l'user à la permission JustifValidate
|
|
|
|
etat: scu.EtatJustificatif = scu.EtatJustificatif.ATTENTE
|
|
|
|
if current_user.has_permission(Permission.JustifValidate):
|
|
|
|
etat = scu.EtatJustificatif.VALIDE
|
|
|
|
else:
|
|
|
|
flash(
|
|
|
|
"Vous ne pouvez pas créer de justificatif valide,"
|
|
|
|
+ " il est automatiquement passé 'EN ATTENTE'",
|
|
|
|
)
|
|
|
|
|
2024-01-08 19:06:44 +01:00
|
|
|
# Création du justificatif correspondant
|
|
|
|
justificatif_correspondant: Justificatif = Justificatif.create_justificatif(
|
|
|
|
etudiant=objet.etudiant,
|
|
|
|
date_debut=objet.date_debut,
|
|
|
|
date_fin=objet.date_fin,
|
2024-06-26 10:32:15 +02:00
|
|
|
etat=etat,
|
2024-01-08 19:06:44 +01:00
|
|
|
user_id=current_user.id,
|
|
|
|
)
|
|
|
|
|
2024-02-29 14:20:39 +01:00
|
|
|
justificatif_correspondant.justifier_assiduites()
|
2024-01-09 14:38:02 +01:00
|
|
|
scass.simple_invalidate_cache(
|
|
|
|
justificatif_correspondant.to_dict(), objet.etudiant.id
|
|
|
|
)
|
2024-06-26 10:32:15 +02:00
|
|
|
if etat == scu.EtatJustificatif.VALIDE:
|
|
|
|
flash(f"{objet_name} justifiée")
|
2024-01-08 19:06:44 +01:00
|
|
|
return redirect(request.referrer)
|
|
|
|
|
2024-06-11 14:50:30 +02:00
|
|
|
# Si on arrive ici, c'est que l'action n'est pas autorisée
|
|
|
|
# cette fonction ne sert plus qu'à supprimer ou justifier
|
|
|
|
flash("Méthode non autorisée", "error")
|
|
|
|
return redirect(request.referrer)
|
2023-11-24 13:58:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
def _preparer_objet(
|
|
|
|
obj_type: str, objet: Assiduite | Justificatif, sans_gros_objet: bool = False
|
|
|
|
) -> dict:
|
2023-12-06 14:42:10 +01:00
|
|
|
"Préparation d'un objet pour simplifier l'affichage jinja"
|
2023-11-24 13:58:03 +01:00
|
|
|
objet_prepare: dict = objet.to_dict()
|
|
|
|
if obj_type == "assiduite":
|
|
|
|
objet_prepare["etat"] = (
|
|
|
|
scu.EtatAssiduite(objet.etat).version_lisible().capitalize()
|
|
|
|
)
|
|
|
|
objet_prepare["real_etat"] = scu.EtatAssiduite(objet.etat).name.lower()
|
|
|
|
objet_prepare["description"] = (
|
|
|
|
"" if objet.description is None else objet.description
|
|
|
|
)
|
|
|
|
objet_prepare["description"] = objet_prepare["description"].strip()
|
|
|
|
|
|
|
|
# Gestion du module
|
|
|
|
objet_prepare["module"] = objet.get_module(True)
|
|
|
|
|
|
|
|
# Gestion justification
|
|
|
|
|
2024-06-03 15:50:35 +02:00
|
|
|
objet_prepare["justification"] = {
|
|
|
|
"est_just": objet.est_just,
|
|
|
|
"justificatifs": [],
|
|
|
|
}
|
2023-11-24 13:58:03 +01:00
|
|
|
|
2024-06-03 15:50:35 +02:00
|
|
|
if not sans_gros_objet:
|
|
|
|
justificatifs: list[int] = get_assiduites_justif(objet.assiduite_id, False)
|
|
|
|
for justi_id in justificatifs:
|
|
|
|
justi: Justificatif = Justificatif.query.get(justi_id)
|
|
|
|
objet_prepare["justification"]["justificatifs"].append(
|
|
|
|
_preparer_objet("justificatif", justi, sans_gros_objet=True)
|
2023-11-24 13:58:03 +01:00
|
|
|
)
|
|
|
|
|
2023-12-22 15:31:30 +01:00
|
|
|
else: # objet == "justificatif"
|
|
|
|
justif: Justificatif = objet
|
2023-11-24 13:58:03 +01:00
|
|
|
objet_prepare["etat"] = (
|
2023-12-22 15:31:30 +01:00
|
|
|
scu.EtatJustificatif(justif.etat).version_lisible().capitalize()
|
2023-11-24 13:58:03 +01:00
|
|
|
)
|
2023-12-22 15:31:30 +01:00
|
|
|
objet_prepare["real_etat"] = scu.EtatJustificatif(justif.etat).name.lower()
|
|
|
|
objet_prepare["raison"] = "" if justif.raison is None else justif.raison
|
2023-11-24 13:58:03 +01:00
|
|
|
objet_prepare["raison"] = objet_prepare["raison"].strip()
|
|
|
|
|
|
|
|
objet_prepare["justification"] = {"assiduites": [], "fichiers": {}}
|
|
|
|
if not sans_gros_objet:
|
2024-06-03 15:50:35 +02:00
|
|
|
assiduites: list[Assiduite] = justif.get_assiduites()
|
|
|
|
for assi in assiduites:
|
2023-11-24 13:58:03 +01:00
|
|
|
objet_prepare["justification"]["assiduites"].append(
|
|
|
|
_preparer_objet("assiduite", assi, sans_gros_objet=True)
|
|
|
|
)
|
|
|
|
|
2023-12-22 15:31:30 +01:00
|
|
|
# fichiers justificatifs archivés:
|
|
|
|
filenames, nb_files = justif.get_fichiers()
|
2023-11-24 13:58:03 +01:00
|
|
|
objet_prepare["justification"]["fichiers"] = {
|
2023-12-22 15:31:30 +01:00
|
|
|
"total": nb_files,
|
|
|
|
"filenames": filenames,
|
2023-11-24 13:58:03 +01:00
|
|
|
}
|
|
|
|
|
2024-04-02 23:37:23 +02:00
|
|
|
objet_prepare["date_fin"] = objet.date_fin.strftime(scu.DATEATIME_FMT)
|
2023-11-24 13:58:03 +01:00
|
|
|
objet_prepare["real_date_fin"] = objet.date_fin.isoformat()
|
2024-04-02 23:37:23 +02:00
|
|
|
objet_prepare["date_debut"] = objet.date_debut.strftime(scu.DATEATIME_FMT)
|
2023-11-24 13:58:03 +01:00
|
|
|
objet_prepare["real_date_debut"] = objet.date_debut.isoformat()
|
|
|
|
|
2024-04-02 23:37:23 +02:00
|
|
|
objet_prepare["entry_date"] = objet.entry_date.strftime(scu.DATEATIME_FMT)
|
2023-11-24 13:58:03 +01:00
|
|
|
|
|
|
|
objet_prepare["etud_nom"] = objet.etudiant.nomprenom
|
|
|
|
|
2023-12-22 15:31:30 +01:00
|
|
|
if objet.user_id is not None:
|
2023-11-24 13:58:03 +01:00
|
|
|
user: User = User.query.get(objet.user_id)
|
|
|
|
objet_prepare["saisie_par"] = user.get_nomprenom()
|
|
|
|
else:
|
|
|
|
objet_prepare["saisie_par"] = "Inconnu"
|
|
|
|
|
|
|
|
return objet_prepare
|
|
|
|
|
|
|
|
|
2023-12-10 20:59:32 +01:00
|
|
|
@bp.route("/signale_evaluation_abs/<int:evaluation_id>/<int:etudid>")
|
2023-09-06 11:21:53 +02:00
|
|
|
@scodoc
|
2023-12-10 20:59:32 +01:00
|
|
|
@permission_required(Permission.AbsChange)
|
|
|
|
def signale_evaluation_abs(etudid: int = None, evaluation_id: int = None):
|
2023-09-06 11:21:53 +02:00
|
|
|
"""
|
|
|
|
Signale l'absence d'un étudiant à une évaluation
|
2023-12-10 20:59:32 +01:00
|
|
|
Si la durée de l'évaluation est inférieure à 1 jour
|
|
|
|
l'absence sera sur la période de l'évaluation
|
|
|
|
sinon l'utilisateur sera redirigé vers la page de saisie des absences de l'étudiant
|
2023-09-06 11:21:53 +02:00
|
|
|
"""
|
2023-12-01 13:46:33 +01:00
|
|
|
etud = Identite.get_etud(etudid)
|
2023-09-06 11:21:53 +02:00
|
|
|
evaluation: Evaluation = Evaluation.query.get_or_404(evaluation_id)
|
|
|
|
|
|
|
|
delta: datetime.timedelta = evaluation.date_fin - evaluation.date_debut
|
2023-10-27 16:05:40 +02:00
|
|
|
# Si l'évaluation dure plus qu'un jour alors on redirige vers la page de saisie etudiant
|
2023-09-06 11:21:53 +02:00
|
|
|
if delta > datetime.timedelta(days=1):
|
|
|
|
# rediriger vers page saisie
|
|
|
|
return redirect(
|
|
|
|
url_for(
|
2023-12-05 21:04:38 +01:00
|
|
|
"assiduites.ajout_assiduite_etud",
|
2023-09-06 11:21:53 +02:00
|
|
|
etudid=etudid,
|
|
|
|
evaluation_id=evaluation.id,
|
2023-12-07 12:38:47 +01:00
|
|
|
date_deb=evaluation.date_debut.strftime("%Y-%m-%dT%H:%M:%S"),
|
2023-09-06 11:21:53 +02:00
|
|
|
date_fin=evaluation.date_fin.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
|
|
moduleimpl_id=evaluation.moduleimpl.id,
|
|
|
|
saisie_eval="true",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# Sinon on créé l'assiduité
|
2024-02-04 00:48:45 +01:00
|
|
|
assiduite_unique: Assiduite | None = None
|
2023-09-07 09:17:25 +02:00
|
|
|
try:
|
2024-02-04 00:48:45 +01:00
|
|
|
assiduite_unique = Assiduite.create_assiduite(
|
2023-09-07 09:17:25 +02:00
|
|
|
etud=etud,
|
|
|
|
date_debut=scu.localize_datetime(evaluation.date_debut),
|
|
|
|
date_fin=scu.localize_datetime(evaluation.date_fin),
|
|
|
|
etat=scu.EtatAssiduite.ABSENT,
|
|
|
|
moduleimpl=evaluation.moduleimpl,
|
|
|
|
)
|
2023-12-10 20:59:32 +01:00
|
|
|
except ScoValueError as exc:
|
2023-10-27 16:05:40 +02:00
|
|
|
# En cas d'erreur
|
2023-12-10 20:59:32 +01:00
|
|
|
msg: str = exc.args[0]
|
2023-09-07 09:17:25 +02:00
|
|
|
if "Duplication" in msg:
|
2023-12-01 13:46:33 +01:00
|
|
|
msg = """Une autre saisie concerne déjà cette période.
|
|
|
|
En cliquant sur continuer vous serez redirigé vers la page de
|
2023-12-05 21:04:38 +01:00
|
|
|
saisie de l'assiduité de l'étudiant."""
|
2023-09-07 09:17:25 +02:00
|
|
|
dest: str = url_for(
|
2023-12-05 21:04:38 +01:00
|
|
|
"assiduites.ajout_assiduite_etud",
|
2023-09-07 09:17:25 +02:00
|
|
|
etudid=etudid,
|
|
|
|
evaluation_id=evaluation.id,
|
2024-01-19 17:06:01 +01:00
|
|
|
date_deb=evaluation.date_debut.strftime("%Y-%m-%dT%H:%M:%S"),
|
2023-09-07 09:17:25 +02:00
|
|
|
date_fin=evaluation.date_fin.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
|
|
moduleimpl_id=evaluation.moduleimpl.id,
|
|
|
|
saisie_eval="true",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
duplication="oui",
|
|
|
|
)
|
2023-12-10 20:59:32 +01:00
|
|
|
raise ScoValueError(msg, dest) from exc
|
2024-02-04 00:48:45 +01:00
|
|
|
if assiduite_unique is not None:
|
|
|
|
db.session.add(assiduite_unique)
|
|
|
|
db.session.commit()
|
2023-09-06 11:21:53 +02:00
|
|
|
|
2023-12-10 20:59:32 +01:00
|
|
|
# on flash puis on revient sur la page de l'évaluation
|
2023-09-06 11:21:53 +02:00
|
|
|
flash("L'absence a bien été créée")
|
|
|
|
# rediriger vers la page d'évaluation
|
|
|
|
return redirect(
|
|
|
|
url_for(
|
|
|
|
"notes.evaluation_check_absences_html",
|
|
|
|
evaluation_id=evaluation.id,
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-03-22 15:41:39 +01:00
|
|
|
@bp.route("traitement_justificatifs")
|
|
|
|
@scodoc
|
2024-06-26 10:32:15 +02:00
|
|
|
@permission_required(Permission.JustifValidate)
|
2024-03-22 15:41:39 +01:00
|
|
|
@permission_required(Permission.AbsJustifView)
|
|
|
|
def traitement_justificatifs():
|
|
|
|
"""Page de traitement des justificatifs
|
|
|
|
On traite les justificatifs par formsemestre
|
|
|
|
On peut Valider, Invalider ou mettre en ATT
|
|
|
|
"""
|
|
|
|
# Récupération du formsemestre
|
|
|
|
formsemestre_id: int = request.args.get("formsemestre_id", -1)
|
|
|
|
formsemestre: FormSemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
|
|
|
|
|
|
|
lignes: list[dict] = []
|
|
|
|
|
|
|
|
# Récupération des justificatifs
|
|
|
|
justificatifs_query: Query = scass.filter_by_formsemestre(
|
|
|
|
Justificatif.query, Justificatif, formsemestre
|
|
|
|
)
|
|
|
|
justificatifs_query = justificatifs_query.filter(
|
|
|
|
Justificatif.etat.in_(
|
|
|
|
[scu.EtatJustificatif.ATTENTE, scu.EtatJustificatif.MODIFIE]
|
|
|
|
)
|
|
|
|
).order_by(Justificatif.date_debut)
|
|
|
|
|
|
|
|
justif: Justificatif
|
|
|
|
for justif in justificatifs_query:
|
|
|
|
etud: Identite = justif.etudiant
|
|
|
|
assi_stats: tuple[int, int, int] = scass.get_assiduites_count(
|
|
|
|
etud.id, formsemestre.to_dict()
|
|
|
|
)
|
|
|
|
etud_dict: dict = {
|
|
|
|
"id": etud.id,
|
|
|
|
"nom": etud.nom,
|
|
|
|
"prenom": etud.prenom,
|
|
|
|
"nomprenom": etud.nomprenom,
|
|
|
|
"stats": assi_stats,
|
|
|
|
"sort_key": etud.sort_key,
|
|
|
|
}
|
|
|
|
|
|
|
|
assiduites_justifiees: list[Assiduite] = justif.get_assiduites().all()
|
|
|
|
|
|
|
|
# fichiers justificatifs archivés:
|
|
|
|
filenames, nb_files = justif.get_fichiers()
|
|
|
|
fichiers = {
|
|
|
|
"total": nb_files,
|
|
|
|
"filenames": filenames,
|
|
|
|
}
|
|
|
|
|
|
|
|
lignes.append(
|
|
|
|
{
|
|
|
|
"etud": etud_dict,
|
|
|
|
"justif": justif,
|
|
|
|
"assiduites": assiduites_justifiees,
|
|
|
|
"fichiers": fichiers,
|
|
|
|
"etat": scu.EtatJustificatif(justif.etat).name.lower(),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
# Tri en fonction du nom des étudiants
|
|
|
|
lignes = sorted(lignes, key=lambda x: x["etud"]["sort_key"])
|
|
|
|
|
|
|
|
return render_template(
|
|
|
|
"assiduites/pages/traitement_justificatifs.j2",
|
|
|
|
formsemestre=formsemestre,
|
|
|
|
sco=ScoData(formsemestre=formsemestre),
|
|
|
|
lignes=lignes,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-05-27 17:59:34 +02:00
|
|
|
@bp.route("signal_assiduites_hebdo")
|
|
|
|
@scodoc
|
2024-05-27 22:33:01 +02:00
|
|
|
@permission_required(Permission.ScoView)
|
2024-05-27 17:59:34 +02:00
|
|
|
def signal_assiduites_hebdo():
|
|
|
|
"""
|
|
|
|
signal_assiduites_hebdo
|
|
|
|
|
|
|
|
paramètres obligatoires :
|
|
|
|
- formsemestre_id : id du formsemestre
|
|
|
|
- groups_id : id des groupes (séparés par des virgules -> 1,2,3)
|
|
|
|
|
|
|
|
paramètres optionnels :
|
2024-05-29 19:09:06 +02:00
|
|
|
- week : date semaine (iso 8601 -> 20XX-WXX), par défaut la semaine actuelle
|
2024-05-27 17:59:34 +02:00
|
|
|
- moduleimpl_id : id du moduleimpl (par défaut None)
|
2024-05-27 22:33:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
Permissions :
|
|
|
|
- ScoView -> page en lecture seule
|
|
|
|
- AbsChange -> page en lecture/écriture
|
2024-05-27 17:59:34 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
# Récupération des paramètres
|
|
|
|
moduleimpl_id: int = request.args.get("moduleimpl_id", None)
|
2024-05-27 22:33:01 +02:00
|
|
|
group_ids: str = request.args.get("group_ids", "") # ex: "1,2,3"
|
2024-05-27 17:59:34 +02:00
|
|
|
formsemestre_id: int = request.args.get("formsemestre_id", -1)
|
2024-05-29 19:09:06 +02:00
|
|
|
week: str = request.args.get("week", datetime.datetime.now().strftime("%G-W%V"))
|
2024-05-27 17:59:34 +02:00
|
|
|
# Vérification des paramètres
|
2024-05-29 19:09:06 +02:00
|
|
|
if group_ids == "" or formsemestre_id == -1:
|
2024-05-27 17:59:34 +02:00
|
|
|
raise ScoValueError("Paramètres manquants", dest_url=request.referrer)
|
|
|
|
|
|
|
|
# Récupération du moduleimpl
|
2024-05-27 22:33:01 +02:00
|
|
|
try:
|
|
|
|
moduleimpl_id: int = int(moduleimpl_id)
|
|
|
|
except (ValueError, TypeError):
|
|
|
|
moduleimpl_id: str | None = None if moduleimpl_id != "autre" else moduleimpl_id
|
2024-05-27 17:59:34 +02:00
|
|
|
|
|
|
|
# Récupération du formsemestre
|
|
|
|
formsemestre: FormSemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
|
|
|
|
2024-05-27 22:33:01 +02:00
|
|
|
# Vérification semaine dans format iso 8601 et formsemestre
|
|
|
|
regex_iso8601 = r"^\d{4}-W\d{2}$"
|
2024-06-02 10:05:15 +02:00
|
|
|
if week and not re.match(regex_iso8601, week):
|
2024-05-27 22:33:01 +02:00
|
|
|
raise ScoValueError("Semaine invalide", dest_url=request.referrer)
|
2024-05-27 17:59:34 +02:00
|
|
|
|
2024-05-27 22:33:01 +02:00
|
|
|
fs_deb_iso8601 = formsemestre.date_debut.strftime("%Y-W%W")
|
|
|
|
fs_fin_iso8601 = formsemestre.date_fin.strftime("%Y-W%W")
|
2024-05-27 17:59:34 +02:00
|
|
|
|
2024-05-27 22:33:01 +02:00
|
|
|
# Utilisation de la propriété de la norme iso 8601
|
|
|
|
# les chaines sont triables par ordre alphanumérique croissant
|
|
|
|
# et produiront le même ordre que les dates par ordre chronologique croissant
|
2024-06-02 10:05:15 +02:00
|
|
|
if (not week) or week < fs_deb_iso8601 or week > fs_fin_iso8601:
|
|
|
|
if week:
|
|
|
|
flash(
|
|
|
|
"""La semaine n'est pas dans le semestre,
|
|
|
|
choisissez la semaine sur laquelle saisir l'assiduité"""
|
|
|
|
)
|
2024-05-30 10:51:24 +02:00
|
|
|
return sco_gen_cal.calendrier_choix_date(
|
|
|
|
date_debut=formsemestre.date_debut,
|
|
|
|
date_fin=formsemestre.date_fin,
|
|
|
|
url=url_for(
|
|
|
|
"assiduites.signal_assiduites_hebdo",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
formsemestre_id=formsemestre_id,
|
|
|
|
group_ids=group_ids,
|
|
|
|
moduleimpl_id=moduleimpl_id,
|
|
|
|
week="placeholder",
|
|
|
|
),
|
|
|
|
mode="semaine",
|
|
|
|
titre="Choix de la semaine",
|
|
|
|
)
|
2024-05-27 17:59:34 +02:00
|
|
|
|
|
|
|
# Vérification des groupes
|
2024-05-27 22:33:01 +02:00
|
|
|
group_ids = group_ids.split(",") if group_ids != "" else []
|
|
|
|
|
2024-05-27 17:59:34 +02:00
|
|
|
groups_infos = sco_groups_view.DisplayedGroupsInfos(
|
|
|
|
group_ids, formsemestre_id=formsemestre.id, select_all_when_unspecified=True
|
|
|
|
)
|
|
|
|
if not groups_infos.members:
|
|
|
|
return (
|
2024-05-27 22:33:01 +02:00
|
|
|
html_sco_header.sco_header(page_title="Assiduité: saisie hebdomadaire")
|
2024-05-27 17:59:34 +02:00
|
|
|
+ "<h3>Aucun étudiant ! </h3>"
|
|
|
|
+ html_sco_header.sco_footer()
|
|
|
|
)
|
|
|
|
|
|
|
|
# Récupération des étudiants
|
2024-05-27 22:33:01 +02:00
|
|
|
etudiants: list[Identite] = [
|
|
|
|
Identite.get_etud(etudid=m["etudid"]) for m in groups_infos.members
|
|
|
|
]
|
2024-05-27 17:59:34 +02:00
|
|
|
|
|
|
|
if groups_infos.tous_les_etuds_du_sem:
|
|
|
|
gr_tit = "en"
|
|
|
|
else:
|
|
|
|
if len(groups_infos.group_ids) > 1:
|
|
|
|
grp = "des groupes"
|
|
|
|
else:
|
|
|
|
grp = "du groupe"
|
|
|
|
gr_tit = (
|
|
|
|
grp + ' <span class="fontred">' + groups_infos.groups_titles + "</span>"
|
|
|
|
)
|
|
|
|
|
2024-05-28 20:07:25 +02:00
|
|
|
# Gestion des jours
|
|
|
|
jours: dict[str, list[str]] = {
|
|
|
|
"lun": [
|
|
|
|
"Lundi",
|
|
|
|
datetime.datetime.strptime(week + "-1", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
"mar": [
|
|
|
|
"Mardi",
|
|
|
|
datetime.datetime.strptime(week + "-2", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
"mer": [
|
|
|
|
"Mercredi",
|
|
|
|
datetime.datetime.strptime(week + "-3", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
"jeu": [
|
|
|
|
"Jeudi",
|
|
|
|
datetime.datetime.strptime(week + "-4", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
"ven": [
|
|
|
|
"Vendredi",
|
|
|
|
datetime.datetime.strptime(week + "-5", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
"sam": [
|
|
|
|
"Samedi",
|
|
|
|
datetime.datetime.strptime(week + "-6", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
"dim": [
|
|
|
|
"Dimanche",
|
|
|
|
datetime.datetime.strptime(week + "-7", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
non_travail = sco_preferences.get_preference("non_travail")
|
|
|
|
non_travail = non_travail.replace(" ", "").split(",")
|
|
|
|
|
|
|
|
hebdo_jours: list[tuple[bool, str]] = []
|
|
|
|
for key, val in jours.items():
|
|
|
|
hebdo_jours.append((key in non_travail, val))
|
|
|
|
|
2024-06-02 10:05:15 +02:00
|
|
|
url_choix_semaine = url_for(
|
|
|
|
"assiduites.signal_assiduites_hebdo",
|
|
|
|
group_ids=",".join(map(str, groups_infos.group_ids)),
|
|
|
|
week="",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
formsemestre_id=groups_infos.formsemestre_id,
|
|
|
|
moduleimpl_id=moduleimpl_id,
|
|
|
|
)
|
|
|
|
|
2024-07-04 16:46:07 +02:00
|
|
|
erreurs: list = session.pop("feuille_abs_hebdo-erreurs", [])
|
|
|
|
|
2024-05-27 17:59:34 +02:00
|
|
|
return render_template(
|
|
|
|
"assiduites/pages/signal_assiduites_hebdo.j2",
|
2024-05-29 15:59:19 +02:00
|
|
|
title="Assiduité: saisie hebdomadaire",
|
2024-05-27 17:59:34 +02:00
|
|
|
gr=gr_tit,
|
|
|
|
etudiants=etudiants,
|
|
|
|
moduleimpl_select=_module_selector(
|
|
|
|
formsemestre=formsemestre, moduleimpl_id=moduleimpl_id
|
|
|
|
),
|
2024-05-28 20:07:25 +02:00
|
|
|
hebdo_jours=hebdo_jours,
|
2024-05-29 15:59:19 +02:00
|
|
|
readonly=not current_user.has_permission(Permission.AbsChange),
|
|
|
|
non_present=sco_preferences.get_preference(
|
|
|
|
"non_present",
|
|
|
|
formsemestre_id=formsemestre_id,
|
|
|
|
dept_id=g.scodoc_dept_id,
|
|
|
|
),
|
2024-06-02 10:05:15 +02:00
|
|
|
url_choix_semaine=url_choix_semaine,
|
2024-07-04 16:46:07 +02:00
|
|
|
query_string=request.query_string.decode(encoding="utf-8"),
|
|
|
|
erreurs=erreurs,
|
2024-05-27 17:59:34 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-06-03 15:50:35 +02:00
|
|
|
@bp.route("edit_assiduite_etud/<int:assiduite_id>", methods=["GET", "POST"])
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.ScoView)
|
|
|
|
def edit_assiduite_etud(assiduite_id: int):
|
|
|
|
"""
|
|
|
|
Page affichant les détails d'une assiduité
|
|
|
|
Si le current_user alors la page propose un formulaire de modification
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
assi: Assiduite = Assiduite.get_assiduite(assiduite_id=assiduite_id)
|
|
|
|
except HTTPException:
|
|
|
|
flash("Assiduité invalide")
|
|
|
|
return redirect(url_for("assiduites.bilan_dept", scodoc_dept=g.scodoc_dept))
|
|
|
|
|
|
|
|
etud: Identite = assi.etudiant
|
|
|
|
formsemestre: FormSemestre = assi.get_formsemestre()
|
|
|
|
|
|
|
|
readonly: bool = not current_user.has_permission(Permission.AbsChange)
|
|
|
|
|
|
|
|
form: EditAssiForm = EditAssiForm(request.form)
|
|
|
|
if readonly:
|
|
|
|
form.disable_all()
|
|
|
|
|
|
|
|
# peuplement moduleimpl_select
|
|
|
|
choices: OrderedDict = OrderedDict()
|
|
|
|
choices[""] = [("", "Non spécifié"), ("autre", "Autre module (pas dans la liste)")]
|
|
|
|
|
2024-06-05 13:43:44 +02:00
|
|
|
# Récupération des modulesimpl du semestre si existant.
|
|
|
|
if formsemestre:
|
|
|
|
# indique le nom du semestre dans le menu (optgroup)
|
|
|
|
modimpls_from_formsemestre = etud.get_modimpls_from_formsemestre(formsemestre)
|
|
|
|
group_name: str = formsemestre.titre_annee()
|
|
|
|
choices[group_name] = [
|
|
|
|
(m.id, f"{m.module.code} {m.module.abbrev or m.module.titre or ''}")
|
|
|
|
for m in modimpls_from_formsemestre
|
|
|
|
if m.module.ue.type == UE_STANDARD
|
|
|
|
]
|
2024-06-03 15:50:35 +02:00
|
|
|
|
|
|
|
choices.move_to_end("", last=False)
|
|
|
|
form.modimpl.choices = choices
|
|
|
|
|
|
|
|
# Vérification formulaire
|
|
|
|
if form.validate_on_submit():
|
|
|
|
if form.cancel.data: # cancel button
|
|
|
|
return redirect(request.referrer)
|
|
|
|
|
|
|
|
# vérification des valeurs
|
|
|
|
|
|
|
|
# Gestion de l'état
|
|
|
|
etat = form.assi_etat.data
|
|
|
|
try:
|
|
|
|
etat = int(etat)
|
|
|
|
etat = scu.EtatAssiduite.inverse().get(etat, None)
|
|
|
|
except ValueError:
|
|
|
|
etat = None
|
|
|
|
|
|
|
|
if etat is None:
|
|
|
|
form.error_messages.append("État invalide")
|
|
|
|
form.ok = False
|
|
|
|
|
|
|
|
description = form.description.data or ""
|
|
|
|
description = description.strip()
|
2024-06-04 16:01:05 +02:00
|
|
|
moduleimpl_id = form.modimpl.data if form.modimpl.data is not None else -1
|
|
|
|
# Vérifications des dates / horaires
|
|
|
|
|
|
|
|
ok, dt_deb, dt_fin, dt_entry = _get_dates_from_assi_form(
|
|
|
|
form, etud, from_justif=True, formsemestre=formsemestre
|
|
|
|
)
|
|
|
|
if ok:
|
|
|
|
if is_period_conflicting(
|
|
|
|
dt_deb, dt_fin, etud.assiduites, Assiduite, assi.id
|
|
|
|
):
|
|
|
|
form.set_error("La période est en conflit avec une autre assiduité")
|
2024-06-03 15:50:35 +02:00
|
|
|
form.ok = False
|
|
|
|
|
|
|
|
if form.ok:
|
|
|
|
assi.etat = etat
|
|
|
|
assi.description = description
|
|
|
|
if moduleimpl_id != -1:
|
|
|
|
assi.set_moduleimpl(moduleimpl_id)
|
|
|
|
|
2024-06-04 16:01:05 +02:00
|
|
|
assi.date_debut = dt_deb
|
|
|
|
assi.date_fin = dt_fin
|
|
|
|
assi.entry_date = dt_entry
|
|
|
|
|
2024-06-03 15:50:35 +02:00
|
|
|
db.session.add(assi)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
scass.simple_invalidate_cache(assi.to_dict(format_api=True), assi.etudid)
|
|
|
|
|
|
|
|
flash("enregistré")
|
|
|
|
return redirect(request.referrer)
|
|
|
|
|
|
|
|
# Remplissage du formulaire
|
|
|
|
form.assi_etat.data = str(assi.etat)
|
|
|
|
form.description.data = assi.description
|
|
|
|
moduleimpl_id: int | str | None = assi.get_moduleimpl_id() or ""
|
|
|
|
form.modimpl.data = str(moduleimpl_id)
|
|
|
|
|
2024-06-04 16:01:05 +02:00
|
|
|
form.date_debut.data = assi.date_debut.strftime(scu.DATE_FMT)
|
|
|
|
form.heure_debut.data = assi.date_debut.strftime(scu.TIME_FMT)
|
|
|
|
form.date_fin.data = assi.date_fin.strftime(scu.DATE_FMT)
|
|
|
|
form.heure_fin.data = assi.date_fin.strftime(scu.TIME_FMT)
|
|
|
|
form.entry_date.data = assi.entry_date.strftime(scu.DATE_FMT)
|
|
|
|
form.entry_time.data = assi.entry_date.strftime(scu.TIME_FMT)
|
|
|
|
|
2024-06-03 15:50:35 +02:00
|
|
|
return render_template(
|
|
|
|
"assiduites/pages/edit_assiduite_etud.j2",
|
|
|
|
etud=etud,
|
|
|
|
sco=ScoData(etud, formsemestre=formsemestre),
|
|
|
|
form=form,
|
2024-06-05 10:47:36 +02:00
|
|
|
readonly=readonly,
|
2024-06-03 15:50:35 +02:00
|
|
|
objet=_preparer_objet("assiduite", assi),
|
|
|
|
title=f"Assiduité {etud.nom_short}",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-09-08 11:59:10 +02:00
|
|
|
def generate_bul_list(etud: Identite, semestre: FormSemestre) -> str:
|
|
|
|
"""Génère la liste des assiduités d'un étudiant pour le bulletin mail"""
|
2023-10-27 16:05:40 +02:00
|
|
|
|
|
|
|
# On récupère la métrique d'assiduité
|
2023-09-08 11:59:10 +02:00
|
|
|
metrique: str = scu.translate_assiduites_metric(
|
|
|
|
sco_preferences.get_preference("assi_metrique", formsemestre_id=semestre.id),
|
|
|
|
)
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# On récupère le nombre maximum de ligne d'assiduité
|
2023-09-08 11:59:10 +02:00
|
|
|
max_nb: int = int(
|
|
|
|
sco_preferences.get_preference(
|
|
|
|
"bul_mail_list_abs_nb", formsemestre_id=semestre.id
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# On récupère les assiduités et les justificatifs de l'étudiant
|
2023-09-08 11:59:10 +02:00
|
|
|
assiduites = scass.filter_by_formsemestre(
|
|
|
|
etud.assiduites, Assiduite, semestre
|
|
|
|
).order_by(Assiduite.entry_date.desc())
|
|
|
|
justificatifs = scass.filter_by_formsemestre(
|
|
|
|
etud.justificatifs, Justificatif, semestre
|
|
|
|
).order_by(Justificatif.entry_date.desc())
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# On calcule les statistiques
|
2023-09-08 11:59:10 +02:00
|
|
|
stats: dict = scass.get_assiduites_stats(
|
|
|
|
assiduites, metric=metrique, filtered={"split": True}
|
|
|
|
)
|
|
|
|
|
2023-11-03 14:57:22 +01:00
|
|
|
# On sépare :
|
2023-10-27 16:05:40 +02:00
|
|
|
# - abs_j = absences justifiées
|
|
|
|
# - abs_nj = absences non justifiées
|
|
|
|
# - retards = les retards
|
|
|
|
# - justifs = les justificatifs
|
2023-11-03 14:57:22 +01:00
|
|
|
|
2023-09-08 11:59:10 +02:00
|
|
|
abs_j: list[str] = [
|
|
|
|
{"date": _get_date_str(assi.date_debut, assi.date_fin)}
|
|
|
|
for assi in assiduites
|
|
|
|
if assi.etat == scu.EtatAssiduite.ABSENT and assi.est_just is True
|
|
|
|
]
|
|
|
|
abs_nj: list[str] = [
|
|
|
|
{"date": _get_date_str(assi.date_debut, assi.date_fin)}
|
|
|
|
for assi in assiduites
|
|
|
|
if assi.etat == scu.EtatAssiduite.ABSENT and assi.est_just is False
|
|
|
|
]
|
|
|
|
retards: list[str] = [
|
|
|
|
{"date": _get_date_str(assi.date_debut, assi.date_fin)}
|
|
|
|
for assi in assiduites
|
|
|
|
if assi.etat == scu.EtatAssiduite.RETARD
|
|
|
|
]
|
|
|
|
|
|
|
|
justifs: list[dict[str, str]] = [
|
|
|
|
{
|
|
|
|
"date": _get_date_str(justi.date_debut, justi.date_fin),
|
|
|
|
"raison": "" if justi.raison is None else justi.raison,
|
|
|
|
"etat": {
|
|
|
|
scu.EtatJustificatif.VALIDE: "justificatif valide",
|
|
|
|
scu.EtatJustificatif.NON_VALIDE: "justificatif invalide",
|
|
|
|
scu.EtatJustificatif.ATTENTE: "justificatif en attente de validation",
|
|
|
|
scu.EtatJustificatif.MODIFIE: "justificatif ayant été modifié",
|
|
|
|
}.get(justi.etat),
|
|
|
|
}
|
|
|
|
for justi in justificatifs
|
|
|
|
]
|
|
|
|
|
|
|
|
return render_template(
|
|
|
|
"assiduites/widgets/liste_assiduites_mail.j2",
|
|
|
|
abs_j=abs_j[:max_nb],
|
|
|
|
abs_nj=abs_nj[:max_nb],
|
|
|
|
retards=retards[:max_nb],
|
|
|
|
justifs=justifs[:max_nb],
|
|
|
|
stats=stats,
|
|
|
|
metrique=scu.translate_assiduites_metric(metrique, short=True, inverse=False),
|
|
|
|
metric=metrique,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-06-06 10:44:07 +02:00
|
|
|
@bp.route("feuille_abs_hebdo", methods=["GET", "POST"])
|
|
|
|
@scodoc
|
|
|
|
@permission_required(Permission.AbsChange)
|
|
|
|
def feuille_abs_hebdo():
|
|
|
|
"""
|
|
|
|
GET : Renvoie un tableau excel pour permettre la saisie des absences
|
2024-07-04 16:46:07 +02:00
|
|
|
POST: Enregistre les absences saisies et renvoie sur la page de saisie hebdomadaire
|
2024-06-06 10:44:07 +02:00
|
|
|
Affiche un choix de semaine si "week" n'est pas renseigné
|
2024-07-04 16:46:07 +02:00
|
|
|
|
|
|
|
Si POST:
|
|
|
|
renvoie sur la page saisie_assiduites_hebdo
|
2024-06-06 10:44:07 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
# Récupération des groupes
|
|
|
|
group_ids: str = request.args.get("group_ids", "")
|
|
|
|
if group_ids == "":
|
|
|
|
raise ScoValueError("Paramètre 'group_ids' manquant", dest_url=request.referrer)
|
|
|
|
|
|
|
|
# Vérification du semestre
|
|
|
|
formsemestre_id: int = request.args.get("formsemestre_id", -1)
|
|
|
|
formsemestre: FormSemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
|
|
|
|
|
|
|
# Vériication de la semaine
|
|
|
|
week: str = request.args.get("week", datetime.datetime.now().strftime("%G-W%V"))
|
|
|
|
|
|
|
|
regex_iso8601 = r"^\d{4}-W\d{2}$"
|
|
|
|
if week and not re.match(regex_iso8601, week):
|
|
|
|
raise ScoValueError("Semaine invalide", dest_url=request.referrer)
|
|
|
|
|
|
|
|
fs_deb_iso8601 = formsemestre.date_debut.strftime("%Y-W%W")
|
|
|
|
fs_fin_iso8601 = formsemestre.date_fin.strftime("%Y-W%W")
|
|
|
|
|
|
|
|
# Utilisation de la propriété de la norme iso 8601
|
|
|
|
# les chaines sont triables par ordre alphanumérique croissant
|
|
|
|
# et produiront le même ordre que les dates par ordre chronologique croissant
|
|
|
|
if (not week) or week < fs_deb_iso8601 or week > fs_fin_iso8601:
|
|
|
|
if week:
|
|
|
|
flash(
|
|
|
|
"""La semaine n'est pas dans le semestre,
|
|
|
|
choisissez la semaine sur laquelle saisir l'assiduité"""
|
|
|
|
)
|
|
|
|
return sco_gen_cal.calendrier_choix_date(
|
|
|
|
date_debut=formsemestre.date_debut,
|
|
|
|
date_fin=formsemestre.date_fin,
|
|
|
|
url=url_for(
|
|
|
|
"assiduites.feuilles_abs_hebdo",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
formsemestre_id=formsemestre_id,
|
|
|
|
group_ids=group_ids,
|
|
|
|
week="placeholder",
|
|
|
|
),
|
|
|
|
mode="semaine",
|
|
|
|
titre="Choix de la semaine",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Vérification des groupes
|
|
|
|
group_ids = group_ids.split(",") if group_ids != "" else []
|
|
|
|
|
|
|
|
groups_infos = sco_groups_view.DisplayedGroupsInfos(
|
|
|
|
group_ids, formsemestre_id=formsemestre.id, select_all_when_unspecified=True
|
|
|
|
)
|
|
|
|
if not groups_infos.members:
|
|
|
|
return (
|
|
|
|
html_sco_header.sco_header(
|
|
|
|
page_title="Assiduité: feuille saisie hebdomadaire"
|
|
|
|
)
|
|
|
|
+ "<h3>Aucun étudiant ! </h3>"
|
|
|
|
+ html_sco_header.sco_footer()
|
|
|
|
)
|
|
|
|
|
|
|
|
# Gestion des jours
|
|
|
|
jours: dict[str, list[str]] = {
|
|
|
|
"lun": [
|
|
|
|
"Lundi",
|
|
|
|
datetime.datetime.strptime(week + "-1", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
"mar": [
|
|
|
|
"Mardi",
|
|
|
|
datetime.datetime.strptime(week + "-2", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
"mer": [
|
|
|
|
"Mercredi",
|
|
|
|
datetime.datetime.strptime(week + "-3", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
"jeu": [
|
|
|
|
"Jeudi",
|
|
|
|
datetime.datetime.strptime(week + "-4", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
"ven": [
|
|
|
|
"Vendredi",
|
|
|
|
datetime.datetime.strptime(week + "-5", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
"sam": [
|
|
|
|
"Samedi",
|
|
|
|
datetime.datetime.strptime(week + "-6", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
"dim": [
|
|
|
|
"Dimanche",
|
|
|
|
datetime.datetime.strptime(week + "-7", "%G-W%V-%u").strftime("%d/%m/%Y"),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
non_travail = sco_preferences.get_preference("non_travail")
|
|
|
|
non_travail = non_travail.replace(" ", "").split(",")
|
|
|
|
|
|
|
|
hebdo_jours: list[tuple[bool, str]] = []
|
|
|
|
for key, val in jours.items():
|
|
|
|
hebdo_jours.append((key in non_travail, val))
|
|
|
|
|
|
|
|
if request.method == "POST":
|
2024-07-04 16:46:07 +02:00
|
|
|
url_saisie: str = url_for(
|
|
|
|
"assiduites.signal_assiduites_hebdo",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
**request.args,
|
|
|
|
)
|
|
|
|
# Vérification du fichier
|
|
|
|
file = request.files.get("file", None)
|
|
|
|
if file is None or file.filename == "":
|
|
|
|
flash("Erreur : Pas de fichier")
|
|
|
|
return redirect(url_saisie)
|
|
|
|
# Vérification des heures
|
|
|
|
heures: list[str] = request.form.get("heures", "").split(",")
|
|
|
|
if len(heures) != 4:
|
|
|
|
flash("Erreur : Les heures sont incorrectes")
|
|
|
|
return redirect(url_saisie)
|
|
|
|
# Récupération du moduleimpl
|
|
|
|
moduleimpl_id = request.form.get("moduleimpl_id")
|
|
|
|
|
|
|
|
# Enregistrement des assiduites
|
|
|
|
erreurs = _import_feuille_abs_hebdo(
|
|
|
|
file,
|
|
|
|
heures=["08:15", "13:00", "13:00", "18:15"],
|
|
|
|
moduleimpl_id=moduleimpl_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
if erreurs:
|
|
|
|
session["feuille_abs_hebdo-erreurs"] = erreurs
|
|
|
|
|
|
|
|
return redirect(url_saisie)
|
2024-06-06 10:44:07 +02:00
|
|
|
|
|
|
|
filename = f"feuille_signal_abs_{week}"
|
|
|
|
xls = _excel_feuille_abs(
|
|
|
|
formsemestre=formsemestre, groups_infos=groups_infos, hebdo_jours=hebdo_jours
|
|
|
|
)
|
|
|
|
return scu.send_file(xls, filename, scu.XLSX_SUFFIX, mime=scu.XLSX_MIMETYPE)
|
|
|
|
|
|
|
|
|
2024-07-04 16:46:07 +02:00
|
|
|
@bp.route("feuille_abs_formsemestre", methods=["GET", "POST"])
|
|
|
|
@scodoc
|
|
|
|
def feuille_abs_formsemestre():
|
|
|
|
"""
|
|
|
|
Permet l'importation d'une liste d'assiduités depuis un fichier excel
|
|
|
|
GET:
|
|
|
|
Affiche un formulaire pour l'import et les erreurs lors de l'import
|
|
|
|
POST:
|
|
|
|
Nécessite un fichier excel contenant une liste d'assiduités (file)
|
|
|
|
|
|
|
|
"""
|
|
|
|
# Récupération du formsemestre
|
|
|
|
formsemestre_id: int = request.args.get("formsemestre_id", -1)
|
|
|
|
formsemestre: FormSemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
|
|
|
erreurs: list = []
|
|
|
|
if request.method == "POST":
|
|
|
|
# Récupération et vérification du fichier
|
|
|
|
file = request.files.get("file")
|
|
|
|
if file is None or file.filename == "":
|
|
|
|
raise ScoValueError("Pas de fichier", dest_url=request.referrer)
|
|
|
|
|
|
|
|
# Récupération du type d'identifiant
|
|
|
|
type_identifiant: str = request.form.get("type_identifiant", "etudid")
|
|
|
|
|
|
|
|
# Importation du fichier
|
|
|
|
erreurs = _import_excel_assiduites_list(
|
|
|
|
file, formsemestre=formsemestre, type_etud_identifiant=type_identifiant
|
|
|
|
)
|
|
|
|
|
|
|
|
if erreurs:
|
|
|
|
flash("Erreurs lors de l'importation, voir bas de page", "error")
|
|
|
|
else:
|
|
|
|
flash("Importation réussie")
|
|
|
|
|
|
|
|
return render_template(
|
|
|
|
"assiduites/pages/feuille_abs_formsemestre.j2",
|
|
|
|
erreurs=erreurs,
|
|
|
|
titre_form=formsemestre.titre_annee(),
|
|
|
|
sco=ScoData(formsemestre=formsemestre),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-09-06 11:21:53 +02:00
|
|
|
# --- Fonctions internes ---
|
|
|
|
|
|
|
|
|
2024-07-04 16:46:07 +02:00
|
|
|
def _import_feuille_abs_hebdo(
|
|
|
|
file, heures: list[str], moduleimpl_id: int = None
|
|
|
|
) -> list:
|
|
|
|
"""
|
|
|
|
Importe un fichier excel au format de la feuille d'absence hebdomadaire
|
|
|
|
(voir _excel_feuille_abs)
|
|
|
|
|
|
|
|
Génère les assiduités correspondantes et retourne une liste d'erreurs
|
|
|
|
|
|
|
|
Les erreurs sont sous la forme :
|
|
|
|
(message, [num_ligne, ...contenu_ligne])
|
|
|
|
|
|
|
|
Attention : num_ligne correspond au numéro de la ligne dans le fichier excel
|
|
|
|
"""
|
|
|
|
|
|
|
|
data: list = sco_excel.excel_file_to_list(file)
|
|
|
|
erreurs: list = []
|
|
|
|
|
|
|
|
# Récupération des jours (entête du tableau)
|
|
|
|
jours: list[str] = [
|
|
|
|
str_jour.split(" ")[1] for str_jour in data[1][4][4:] if str_jour
|
|
|
|
]
|
|
|
|
|
|
|
|
lettres: str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
|
|
|
|
# On récupère uniquement les lignes d'étudiants (on ignore les headers)
|
|
|
|
data: list = data[1][6:]
|
|
|
|
|
|
|
|
# Chaque ligne commence par [!etudid][nom][prenom][groupe]
|
|
|
|
for num, ligne in enumerate(data):
|
|
|
|
etudid = ligne[0].replace("!", "") # on enlève le point d'exclamation
|
|
|
|
try:
|
|
|
|
etud = Identite.get_etud(etudid)
|
|
|
|
except HTTPException as exc:
|
|
|
|
erreurs.append((exc.description, [num + 6, "A"] + ligne))
|
|
|
|
continue
|
|
|
|
|
|
|
|
for i, etat in enumerate(ligne[4:]):
|
|
|
|
try:
|
|
|
|
etat: str = etat.strip().upper()
|
|
|
|
if etat:
|
|
|
|
# Vérification de l'état
|
|
|
|
if etat not in ["ABS", "RET", "PRE"]:
|
|
|
|
raise ScoValueError(f"État invalide => {etat}")
|
|
|
|
|
|
|
|
etat: scu.EtatAssiduite = {
|
|
|
|
"ABS": scu.EtatAssiduite.ABSENT,
|
|
|
|
"RET": scu.EtatAssiduite.RETARD,
|
|
|
|
"PRE": scu.EtatAssiduite.PRESENT,
|
|
|
|
}.get(etat, scu.EtatAssiduite.ABSENT)
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Génération des dates de début et de fin de l'assiduité
|
|
|
|
heure_debut: str = heures[0] if i % 2 == 0 else heures[2]
|
|
|
|
heure_fin: str = heures[1] if i % 2 == 0 else heures[3]
|
|
|
|
|
|
|
|
try:
|
|
|
|
date_debut: datetime.datetime = datetime.datetime.strptime(
|
|
|
|
jours[i // 2] + " " + heure_debut, "%d/%m/%Y %H:%M"
|
|
|
|
)
|
|
|
|
date_fin: datetime.datetime = datetime.datetime.strptime(
|
|
|
|
jours[i // 2] + " " + heure_fin, "%d/%m/%Y %H:%M"
|
|
|
|
)
|
|
|
|
except ValueError as exc:
|
|
|
|
raise ScoValueError("Dates Invalides") from exc
|
|
|
|
|
|
|
|
# On met les dates à la timezone du serveur
|
|
|
|
date_debut = scu.TIME_ZONE.localize(date_debut)
|
|
|
|
date_fin = scu.TIME_ZONE.localize(date_fin)
|
|
|
|
|
|
|
|
# Création de l'assiduité
|
|
|
|
assiduite: Assiduite = Assiduite.create_assiduite(
|
|
|
|
etud=etud,
|
|
|
|
date_debut=date_debut,
|
|
|
|
date_fin=date_fin,
|
|
|
|
etat=etat,
|
|
|
|
user_id=current_user.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
if moduleimpl_id:
|
|
|
|
assiduite.set_moduleimpl(moduleimpl_id)
|
|
|
|
|
|
|
|
db.session.add(assiduite)
|
|
|
|
scass.simple_invalidate_cache(assiduite.to_dict())
|
|
|
|
except HTTPException as exc:
|
|
|
|
erreurs.append((exc.description, [num + 6, lettres[i + 4]] + ligne))
|
|
|
|
except ScoValueError as exc:
|
|
|
|
erreurs.append((exc.args[0], [num + 6, lettres[i + 4]] + ligne))
|
|
|
|
continue
|
|
|
|
|
|
|
|
# On commit les changements
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
return erreurs
|
|
|
|
|
|
|
|
|
|
|
|
def _import_excel_assiduites_list(
|
|
|
|
file, formsemestre: FormSemestre, type_etud_identifiant: str = "etudid"
|
|
|
|
) -> list:
|
|
|
|
"""
|
|
|
|
Importe un fichier excel contenant une liste d'assiduités
|
|
|
|
sous le format :
|
|
|
|
|
|
|
|
| etudid/nip/ine | date_debut | date_fin | etat [optionnel -> "ABS"] | Module [optionnel -> None] |
|
|
|
|
|
|
|
|
Génère les assiduités correspondantes et retourne une liste d'erreurs
|
|
|
|
|
|
|
|
Les erreurs sont sous la forme :
|
|
|
|
(message, [num_ligne, ...contenu_ligne])
|
|
|
|
|
|
|
|
Attention : num_ligne correspond au numéro de la ligne dans le fichier excel
|
|
|
|
"""
|
|
|
|
|
|
|
|
# On récupère les données du fichier
|
|
|
|
data: list = sco_excel.excel_file_to_list(file)
|
|
|
|
|
|
|
|
# On récupère le deuxième élément de la liste (les lignes du tableur)
|
|
|
|
# Le premier element de la liste correspond à la description des feuilles excel
|
|
|
|
data: list = data[1]
|
|
|
|
|
|
|
|
# On parcourt les lignes et on les traite
|
|
|
|
erreurs: list[tuple[str, list]] = []
|
|
|
|
for num, ligne in enumerate(data):
|
|
|
|
identifiant_etud = ligne[0] # etudid/nip/ine
|
|
|
|
date_debut_str = ligne[1] # iso / fra / excel
|
|
|
|
date_fin_str = ligne[2] # iso / fra / excel
|
|
|
|
etat = ligne[3].strip().upper() # etat abs par défaut, sinon RET ou PRE
|
|
|
|
etat = etat or "ABS"
|
|
|
|
module = ligne[4] or None # code du module
|
|
|
|
moduleimpl: ModuleImpl | None = None
|
|
|
|
try:
|
|
|
|
# On récupère l'étudiant
|
|
|
|
etud: Identite = _find_etud(identifiant_etud, type_etud_identifiant)
|
|
|
|
|
|
|
|
# On vérifie que l'étudiant appartient au semestre
|
|
|
|
if formsemestre not in etud.get_formsemestres():
|
|
|
|
raise ScoValueError("Étudiant non inscrit dans le semestre")
|
|
|
|
|
|
|
|
# On transforme les dates
|
|
|
|
date_debut: datetime.datetime = _try_parse_date(date_debut_str)
|
|
|
|
date_fin: datetime.datetime = _try_parse_date(date_fin_str)
|
|
|
|
|
|
|
|
# On met les dates à la timezone du serveur
|
|
|
|
date_debut = scu.TIME_ZONE.localize(date_debut)
|
|
|
|
date_fin = scu.TIME_ZONE.localize(date_fin)
|
|
|
|
|
|
|
|
# Vérification de l'état
|
|
|
|
if etat not in ["ABS", "RET", "PRE"]:
|
|
|
|
raise ScoValueError(f"État invalide => {etat}")
|
|
|
|
|
|
|
|
etat: scu.EtatAssiduite = {
|
|
|
|
"ABS": scu.EtatAssiduite.ABSENT,
|
|
|
|
"RET": scu.EtatAssiduite.RETARD,
|
|
|
|
"PRE": scu.EtatAssiduite.PRESENT,
|
|
|
|
}.get(etat, scu.EtatAssiduite.ABSENT)
|
|
|
|
|
|
|
|
# On récupère le moduleimpl à partir du code du module et du formsemestre
|
|
|
|
if module:
|
|
|
|
moduleimpl = _get_moduleimpl_from_code(module, formsemestre)
|
|
|
|
|
|
|
|
assiduite: Assiduite = Assiduite.create_assiduite(
|
|
|
|
etud=etud,
|
|
|
|
date_debut=date_debut,
|
|
|
|
date_fin=date_fin,
|
|
|
|
etat=etat,
|
|
|
|
moduleimpl=moduleimpl,
|
|
|
|
)
|
|
|
|
db.session.add(assiduite)
|
|
|
|
scass.simple_invalidate_cache(assiduite.to_dict())
|
|
|
|
|
|
|
|
except ScoValueError as exc:
|
|
|
|
erreurs.append((exc.args[0], [num + 1] + ligne))
|
|
|
|
except HTTPException as exc:
|
|
|
|
erreurs.append((exc.description, [num + 1] + ligne))
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
return erreurs
|
|
|
|
|
|
|
|
|
|
|
|
def _get_moduleimpl_from_code(
|
|
|
|
module_code: str, formsemestre: FormSemestre
|
|
|
|
) -> ModuleImpl:
|
|
|
|
query: Query = ModuleImpl.query.filter(
|
|
|
|
ModuleImpl.module.has(Module.code == module_code),
|
|
|
|
ModuleImpl.formsemestre_id == formsemestre.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
moduleimpl: ModuleImpl = query.first()
|
|
|
|
if moduleimpl is None:
|
|
|
|
raise ScoValueError("Module non trouvé")
|
|
|
|
return moduleimpl
|
|
|
|
|
|
|
|
|
|
|
|
def _try_parse_date(date: str) -> datetime.datetime:
|
|
|
|
"""
|
|
|
|
Tente de parser une date sous différents formats
|
|
|
|
renvoie la première date valide
|
|
|
|
"""
|
|
|
|
|
|
|
|
# On tente de parser la date en iso (yyyy-mm-ddThh:mm:ss)
|
|
|
|
try:
|
|
|
|
return datetime.datetime.fromisoformat(date)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# On tente de parser la date en français (dd/mm/yyyy hh:mm:ss)
|
|
|
|
try:
|
|
|
|
return datetime.datetime.strptime(date, "%d/%m/%Y %H:%M:%S")
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
raise ScoValueError("Date invalide")
|
|
|
|
|
|
|
|
|
|
|
|
def _find_etud(identifiant: str, type_identifiant: str) -> Identite:
|
|
|
|
"""
|
|
|
|
Renvoie l'étudiant correspondant à l'identifiant
|
|
|
|
"""
|
|
|
|
if type_identifiant == "etudid":
|
|
|
|
return tools.get_etud(etudid=identifiant)
|
|
|
|
elif type_identifiant == "nip":
|
|
|
|
return tools.get_etud(nip=identifiant)
|
|
|
|
elif type_identifiant == "ine":
|
|
|
|
return tools.get_etud(ine=identifiant)
|
|
|
|
else:
|
|
|
|
raise ScoValueError("Type d'identifiant invalide")
|
|
|
|
|
|
|
|
|
2024-06-06 10:44:07 +02:00
|
|
|
def _excel_feuille_abs(
|
|
|
|
formsemestre: FormSemestre,
|
|
|
|
groups_infos: sco_groups_view.DisplayedGroupsInfos,
|
|
|
|
hebdo_jours: list[tuple[bool, str]],
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Génère un fichier excel pour la saisie des absences hebdomadaires
|
|
|
|
|
|
|
|
Colonnes :
|
|
|
|
- A : [formsemestre_id][etudid...]
|
|
|
|
- B : [nom][nom...]
|
|
|
|
- C : [prenom][prenom...]
|
|
|
|
- D : [groupes][groupe...]
|
|
|
|
- 2 colonnes (matin/aprem) par jour de la semaine
|
|
|
|
"""
|
|
|
|
|
|
|
|
ws = sco_excel.ScoExcelSheet("Saisie_ABS")
|
|
|
|
|
|
|
|
# == Préparation des données ==
|
|
|
|
lines: list[tuple] = []
|
|
|
|
|
|
|
|
for membre in groups_infos.members:
|
|
|
|
etudid = membre["etudid"]
|
|
|
|
groups = sco_groups.get_etud_groups(etudid, formsemestre_id=formsemestre.id)
|
|
|
|
grc = sco_groups.listgroups_abbrev(groups)
|
|
|
|
line = [
|
|
|
|
str(etudid),
|
|
|
|
membre["nom"].upper(),
|
|
|
|
membre["prenom"].lower().capitalize(),
|
|
|
|
membre["etat"],
|
|
|
|
grc,
|
|
|
|
]
|
|
|
|
line += ["" for _ in range(len(hebdo_jours) * 2)]
|
|
|
|
lines.append(line)
|
|
|
|
|
|
|
|
# == Préparation du fichier ==
|
|
|
|
|
|
|
|
# colonnes
|
|
|
|
lettres: str = "EFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
# ajuste largeurs colonnes (unite inconnue, empirique)
|
|
|
|
ws.set_column_dimension_width("A", 11.0 / 7) # codes
|
|
|
|
# ws.set_column_dimension_hidden("A", True) # codes
|
|
|
|
ws.set_column_dimension_width("B", 164.00 / 7) # noms
|
|
|
|
ws.set_column_dimension_width("C", 109.0 / 7) # prenoms
|
|
|
|
ws.set_column_dimension_width("D", 164.0 / 7) # groupes
|
|
|
|
|
|
|
|
i: int = 0
|
|
|
|
for jour in hebdo_jours:
|
|
|
|
ws.set_column_dimension_width(lettres[i], 100.0 / 7)
|
|
|
|
ws.set_column_dimension_width(lettres[i + 1], 100.0 / 7)
|
|
|
|
if jour[0]:
|
|
|
|
ws.set_column_dimension_hidden(lettres[i], True)
|
|
|
|
ws.set_column_dimension_hidden(lettres[i + 1], True)
|
|
|
|
i += 2
|
|
|
|
|
|
|
|
# fontes
|
|
|
|
font_base = sco_excel.Font(name="Arial", size=12)
|
|
|
|
font_bold = sco_excel.Font(name="Arial", bold=True)
|
|
|
|
font_italic = sco_excel.Font(
|
|
|
|
name="Arial", size=12, italic=True, color=sco_excel.COLORS.RED.value
|
|
|
|
)
|
|
|
|
font_titre = sco_excel.Font(name="Arial", bold=True, size=14)
|
|
|
|
font_purple = sco_excel.Font(name="Arial", color=sco_excel.COLORS.PURPLE.value)
|
|
|
|
font_brown = sco_excel.Font(name="Arial", color=sco_excel.COLORS.BROWN.value)
|
|
|
|
|
|
|
|
# bordures
|
|
|
|
side_thin = sco_excel.Side(border_style="thin", color=sco_excel.COLORS.BLACK.value)
|
|
|
|
border_top = sco_excel.Border(top=side_thin)
|
|
|
|
border_right = sco_excel.Border(right=side_thin)
|
|
|
|
border_sides = sco_excel.Border(left=side_thin, right=side_thin, bottom=side_thin)
|
|
|
|
|
|
|
|
# fonds
|
|
|
|
fill_light_yellow = sco_excel.PatternFill(
|
|
|
|
patternType="solid", fgColor=sco_excel.COLORS.LIGHT_YELLOW.value
|
|
|
|
)
|
|
|
|
|
|
|
|
# styles
|
|
|
|
style_titres = {"font": font_titre}
|
|
|
|
style_expl = {"font": font_italic}
|
|
|
|
|
|
|
|
style_ro = { # cells read-only
|
|
|
|
"font": font_purple,
|
|
|
|
"border": border_right,
|
|
|
|
}
|
|
|
|
style_dem = {
|
|
|
|
"font": font_brown,
|
|
|
|
"border": border_top,
|
|
|
|
}
|
|
|
|
style_nom = { # style pour nom, prenom, groupe
|
|
|
|
"font": font_base,
|
|
|
|
"border": border_top,
|
|
|
|
}
|
|
|
|
style_abs = {
|
|
|
|
"font": font_bold,
|
|
|
|
"fill": fill_light_yellow,
|
|
|
|
"border": border_sides,
|
|
|
|
}
|
|
|
|
|
|
|
|
# filtre
|
|
|
|
filter_top = 6
|
|
|
|
filter_bottom = filter_top + len(lines)
|
|
|
|
filter_left = "A"
|
|
|
|
filter_right = lettres[len(hebdo_jours) * 2 - 1]
|
|
|
|
ws.set_auto_filter(f"${filter_left}${filter_top}:${filter_right}${filter_bottom}")
|
|
|
|
|
|
|
|
# == Ecritures statiques ==
|
|
|
|
ws.append_single_cell_row(
|
2024-07-04 16:46:07 +02:00
|
|
|
"Saisir les assiduités dans les cases jaunes (ABS, RET, PRE)", style=style_expl
|
2024-06-06 10:44:07 +02:00
|
|
|
)
|
|
|
|
ws.append_single_cell_row("Ne pas modifier les cases en mauve !", style_expl)
|
|
|
|
# Nom du semestre
|
|
|
|
ws.append_single_cell_row(
|
|
|
|
scu.unescape_html(formsemestre.titre_annee()), style_titres
|
|
|
|
)
|
|
|
|
# ligne blanche
|
|
|
|
ws.append_blank_row()
|
|
|
|
|
|
|
|
# == Ecritures dynamiques ==
|
|
|
|
# Ecriture des entêtes
|
|
|
|
row = [ws.make_cell("", style=style_titres) for _ in range(4)]
|
|
|
|
for jour in hebdo_jours:
|
|
|
|
row.append(ws.make_cell(" ".join(jour[1]), style=style_titres))
|
|
|
|
row.append(ws.make_cell("", style=style_titres))
|
|
|
|
ws.append_row(row)
|
|
|
|
|
|
|
|
row = [
|
|
|
|
ws.make_cell(f"!{formsemestre.id}", style=style_ro),
|
|
|
|
ws.make_cell("Nom", style=style_titres),
|
|
|
|
ws.make_cell("Prénom", style=style_titres),
|
|
|
|
ws.make_cell("Groupe", style=style_titres),
|
|
|
|
]
|
|
|
|
|
|
|
|
for jour in hebdo_jours:
|
|
|
|
row.append(ws.make_cell("Matin", style=style_titres))
|
|
|
|
row.append(ws.make_cell("Après-Midi", style=style_titres))
|
|
|
|
|
|
|
|
ws.append_row(row)
|
|
|
|
|
|
|
|
# Ecriture des données
|
|
|
|
for line in lines:
|
|
|
|
st = style_nom
|
|
|
|
if line[3] != "I":
|
|
|
|
st = style_dem
|
|
|
|
if line[3] == "D": # demissionnaire
|
|
|
|
s = "DEM"
|
|
|
|
else:
|
|
|
|
s = line[3] # etat autre
|
|
|
|
else:
|
|
|
|
s = line[4] # groupes TD/TP/...
|
|
|
|
ws.append_row(
|
|
|
|
[
|
|
|
|
ws.make_cell("!" + line[0], style_ro), # code
|
|
|
|
ws.make_cell(line[1], st),
|
|
|
|
ws.make_cell(line[2], st),
|
|
|
|
ws.make_cell(s, st),
|
|
|
|
]
|
|
|
|
+ [ws.make_cell(" ", style_abs) for _ in range(len(hebdo_jours) * 2)]
|
|
|
|
)
|
|
|
|
|
|
|
|
# ligne blanche
|
|
|
|
ws.append_blank_row()
|
|
|
|
|
|
|
|
return ws.generate()
|
|
|
|
|
|
|
|
|
2023-11-15 14:11:47 +01:00
|
|
|
def _dateiso_to_datefr(date_iso: str) -> str:
|
|
|
|
"""
|
|
|
|
_dateiso_to_datefr Transforme une date iso en date format français
|
|
|
|
|
|
|
|
Args:
|
|
|
|
date_iso (str): date au format iso (YYYY-MM-DD)
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
ValueError: Si l'argument `date_iso` n'est pas au bon format
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: date au format français (DD/MM/YYYY)
|
|
|
|
"""
|
|
|
|
|
|
|
|
regex_date_iso: str = r"^\d{4}-([0]\d|1[0-2])-([0-2]\d|3[01])$"
|
|
|
|
|
|
|
|
# Vérification de la date_iso
|
|
|
|
if not re.match(regex_date_iso, date_iso):
|
|
|
|
raise ValueError(
|
|
|
|
f"La dateiso passée en paramètre [{date_iso}] n'est pas valide."
|
|
|
|
)
|
|
|
|
|
|
|
|
return f"{date_iso[8:10]}/{date_iso[5:7]}/{date_iso[0:4]}"
|
|
|
|
|
|
|
|
|
2023-09-08 11:59:10 +02:00
|
|
|
def _get_date_str(deb: datetime.datetime, fin: datetime.datetime) -> str:
|
2023-10-27 16:05:40 +02:00
|
|
|
"""
|
|
|
|
_get_date_str transforme une période en chaîne lisible
|
|
|
|
|
|
|
|
Args:
|
|
|
|
deb (datetime.datetime): date de début
|
|
|
|
fin (datetime.datetime): date de fin
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str:
|
|
|
|
"le dd/mm/yyyy de hh:MM à hh:MM" si les deux date sont sur le même jour
|
|
|
|
"du dd/mm/yyyy hh:MM audd/mm/yyyy hh:MM" sinon
|
|
|
|
"""
|
2023-09-08 11:59:10 +02:00
|
|
|
if deb.date() == fin.date():
|
2024-04-02 23:37:23 +02:00
|
|
|
temps = deb.strftime("%d/%m/%Y %H:%M").split(" ") + [fin.strftime(scu.TIME_FMT)]
|
2023-09-08 11:59:10 +02:00
|
|
|
return f"le {temps[0]} de {temps[1]} à {temps[2]}"
|
|
|
|
return f'du {deb.strftime("%d/%m/%Y %H:%M")} au {fin.strftime("%d/%m/%Y %H:%M")}'
|
|
|
|
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
def _module_selector(formsemestre: FormSemestre, moduleimpl_id: int = None) -> str:
|
2023-04-17 15:44:55 +02:00
|
|
|
"""
|
|
|
|
_module_selector Génère un HTMLSelectElement à partir des moduleimpl du formsemestre
|
|
|
|
|
|
|
|
Args:
|
|
|
|
formsemestre (FormSemestre): Le formsemestre d'où les moduleimpls seront pris.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: La représentation str d'un HTMLSelectElement
|
|
|
|
"""
|
2023-10-27 16:05:40 +02:00
|
|
|
# récupération des ues du semestre
|
2023-04-17 15:44:55 +02:00
|
|
|
ntc: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
|
|
|
|
2024-02-29 08:47:03 +01:00
|
|
|
modimpls_list: list[dict] = ntc.get_modimpls_dict()
|
2023-04-17 15:44:55 +02:00
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
# prévoie la sélection par défaut d'un moduleimpl s'il a été passé en paramètre
|
2023-09-01 15:24:44 +02:00
|
|
|
selected = "" if moduleimpl_id is not None else "selected"
|
2023-04-17 15:44:55 +02:00
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
modules: list[dict[str, str | int]] = []
|
|
|
|
# Récupération de l'id et d'un nom lisible pour chaque moduleimpl
|
2023-04-17 15:44:55 +02:00
|
|
|
for modimpl in modimpls_list:
|
|
|
|
modname: str = (
|
|
|
|
(modimpl["module"]["code"] or "")
|
|
|
|
+ " "
|
|
|
|
+ (modimpl["module"]["abbrev"] or modimpl["module"]["titre"] or "")
|
|
|
|
)
|
|
|
|
modules.append({"moduleimpl_id": modimpl["moduleimpl_id"], "name": modname})
|
|
|
|
|
|
|
|
return render_template(
|
2023-09-01 15:24:44 +02:00
|
|
|
"assiduites/widgets/moduleimpl_selector.j2",
|
2024-01-23 20:09:13 +01:00
|
|
|
formsemestre_id=formsemestre.id,
|
2023-09-01 15:24:44 +02:00
|
|
|
modules=modules,
|
|
|
|
moduleimpl_id=moduleimpl_id,
|
2024-01-23 20:09:13 +01:00
|
|
|
selected=selected,
|
2023-04-17 15:44:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-01-19 17:06:01 +01:00
|
|
|
def _module_selector_multiple(
|
2024-06-27 19:13:39 +02:00
|
|
|
etud: Identite,
|
|
|
|
moduleimpl_id: int = None,
|
|
|
|
only_form: FormSemestre = None,
|
|
|
|
no_default: bool = False,
|
2024-06-27 21:22:19 +02:00
|
|
|
annee_sco: int | None = None,
|
2024-01-19 17:06:01 +01:00
|
|
|
) -> str:
|
2024-01-23 20:09:13 +01:00
|
|
|
"""menu HTML <select> pour choix moduleimpl
|
2024-06-27 21:22:19 +02:00
|
|
|
Prend les semestres de l'année indiquée, sauf si only_form est indiqué.
|
2024-01-23 20:09:13 +01:00
|
|
|
"""
|
2024-06-27 21:22:19 +02:00
|
|
|
modimpls_by_formsemestre = etud.get_modimpls_by_formsemestre(
|
|
|
|
scu.annee_scolaire() if annee_sco is None else annee_sco
|
|
|
|
)
|
2024-02-27 17:03:15 +01:00
|
|
|
choices = OrderedDict()
|
2024-01-19 17:06:01 +01:00
|
|
|
for formsemestre_id in modimpls_by_formsemestre:
|
|
|
|
formsemestre: FormSemestre = FormSemestre.query.get(formsemestre_id)
|
|
|
|
if only_form is not None and formsemestre != only_form:
|
|
|
|
continue
|
|
|
|
# indique le nom du semestre dans le menu (optgroup)
|
|
|
|
choices[formsemestre.titre_annee()] = [
|
|
|
|
{
|
|
|
|
"moduleimpl_id": m.id,
|
|
|
|
"name": f"{m.module.code} {m.module.abbrev or m.module.titre or ''}",
|
|
|
|
}
|
|
|
|
for m in modimpls_by_formsemestre[formsemestre_id]
|
|
|
|
if m.module.ue.type == UE_STANDARD
|
|
|
|
]
|
|
|
|
|
2024-02-27 17:03:15 +01:00
|
|
|
if formsemestre.est_courant():
|
|
|
|
choices.move_to_end(formsemestre.titre_annee(), last=False)
|
|
|
|
|
2024-01-19 17:06:01 +01:00
|
|
|
return render_template(
|
|
|
|
"assiduites/widgets/moduleimpl_selector_multiple.j2",
|
|
|
|
choices=choices,
|
|
|
|
moduleimpl_id=moduleimpl_id,
|
2024-06-27 19:13:39 +02:00
|
|
|
no_default=no_default,
|
2024-01-19 17:06:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-05-24 09:36:42 +02:00
|
|
|
def _timeline(heures=None) -> str:
|
2023-10-27 16:05:40 +02:00
|
|
|
"""
|
|
|
|
_timeline retourne l'html de la timeline
|
|
|
|
|
|
|
|
Args:
|
|
|
|
formsemestre_id (int, optional): un formsemestre. Defaults to None.
|
|
|
|
Le formsemestre sert à obtenir la période par défaut de la timeline
|
|
|
|
sinon ce sera de 2 heure dès le début de la timeline
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: l'html en chaîne de caractères
|
|
|
|
"""
|
2023-04-25 22:59:06 +02:00
|
|
|
return render_template(
|
2023-06-20 08:33:49 +02:00
|
|
|
"assiduites/widgets/timeline.j2",
|
2023-09-20 22:38:01 +02:00
|
|
|
t_start=ScoDocSiteConfig.assi_get_rounded_time("assi_morning_time", "08:00:00"),
|
2024-05-23 09:17:56 +02:00
|
|
|
t_mid=ScoDocSiteConfig.assi_get_rounded_time("assi_lunch_time", "13:00:00"),
|
2023-09-20 22:38:01 +02:00
|
|
|
t_end=ScoDocSiteConfig.assi_get_rounded_time("assi_afternoon_time", "18:00:00"),
|
2023-06-02 17:19:55 +02:00
|
|
|
tick_time=ScoDocSiteConfig.get("assi_tick_time", 15),
|
2023-11-13 08:35:19 +01:00
|
|
|
heures=heures,
|
2023-04-25 22:59:06 +02:00
|
|
|
)
|
2023-05-30 10:17:49 +02:00
|
|
|
|
|
|
|
|
2023-10-27 16:05:40 +02:00
|
|
|
def _mini_timeline() -> str:
|
|
|
|
"""
|
|
|
|
_mini_timeline Retourne l'html lié au mini timeline d'assiduités
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
str: l'html en chaîne de caractères
|
|
|
|
"""
|
2023-05-30 10:17:49 +02:00
|
|
|
return render_template(
|
2023-06-20 08:33:49 +02:00
|
|
|
"assiduites/widgets/minitimeline.j2",
|
2023-09-20 22:38:01 +02:00
|
|
|
t_start=ScoDocSiteConfig.assi_get_rounded_time("assi_morning_time", "08:00:00"),
|
|
|
|
t_end=ScoDocSiteConfig.assi_get_rounded_time("assi_afternoon_time", "18:00:00"),
|
2023-05-30 10:17:49 +02:00
|
|
|
)
|
2023-06-12 17:54:30 +02:00
|
|
|
|
|
|
|
|
2023-09-20 22:38:01 +02:00
|
|
|
def _non_work_days() -> str:
|
|
|
|
"""Abbréviation des jours non travaillés: "'sam','dim'".
|
|
|
|
donnés par les préférences du département
|
|
|
|
"""
|
|
|
|
non_travail = sco_preferences.get_preference("non_travail")
|
2023-06-12 17:54:30 +02:00
|
|
|
non_travail = non_travail.replace(" ", "").split(",")
|
|
|
|
return ",".join([f"'{i.lower()}'" for i in non_travail])
|
|
|
|
|
|
|
|
|
2023-09-20 22:38:01 +02:00
|
|
|
def _get_seuil() -> int:
|
|
|
|
"""Seuil d'alerte des absences (en unité de la métrique),
|
|
|
|
tel que fixé dans les préférences du département."""
|
2023-06-28 17:15:24 +02:00
|
|
|
return sco_preferences.get_preference("assi_seuil", dept_id=g.scodoc_dept_id)
|
2023-07-25 19:59:47 +02:00
|
|
|
|
|
|
|
|
2023-09-20 22:38:01 +02:00
|
|
|
def _get_etuds_dem_def(formsemestre) -> str:
|
|
|
|
"""Une chaine json donnant les étudiants démissionnaires ou défaillants
|
|
|
|
du formsemestre, sous la forme
|
|
|
|
'{"516" : "D", ... }'
|
|
|
|
"""
|
|
|
|
return (
|
|
|
|
"{"
|
|
|
|
+ ", ".join(
|
|
|
|
[
|
|
|
|
f'"{ins.etudid}" : "{ins.etat}"'
|
|
|
|
for ins in formsemestre.inscriptions
|
|
|
|
if ins.etat != scu.INSCRIT
|
|
|
|
]
|
|
|
|
)
|
|
|
|
+ "}"
|
|
|
|
)
|
2024-01-11 17:19:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
# --- Gestion du calendrier ---
|
|
|
|
|
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
class JourAssi(sco_gen_cal.Jour):
|
2024-02-27 15:59:48 +01:00
|
|
|
"""
|
2024-05-07 15:16:40 +02:00
|
|
|
Représente un jour d'assiduité
|
2024-02-27 15:59:48 +01:00
|
|
|
"""
|
2024-01-11 17:19:56 +01:00
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
date: datetime.date,
|
|
|
|
assiduites: Query,
|
|
|
|
justificatifs: Query,
|
|
|
|
parent: "CalendrierAssi",
|
|
|
|
):
|
|
|
|
super().__init__(date)
|
2024-01-11 17:19:56 +01:00
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
# assiduités et justificatifs du jour
|
2024-01-11 17:19:56 +01:00
|
|
|
self.assiduites = assiduites
|
|
|
|
self.justificatifs = justificatifs
|
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
self.parent = parent
|
|
|
|
|
|
|
|
def get_html(self) -> str:
|
|
|
|
# si non travaillé on renvoie une case vide
|
|
|
|
if self.is_non_work():
|
|
|
|
return ""
|
|
|
|
|
|
|
|
html: str = (
|
|
|
|
self._get_html_demi() if self.parent.mode_demi else self._get_html_normal()
|
2024-02-27 15:59:48 +01:00
|
|
|
)
|
2024-05-07 15:16:40 +02:00
|
|
|
html = f'<div class="assi_case">{html}</div>'
|
|
|
|
|
|
|
|
if self.has_assiduite():
|
|
|
|
minitimeline: str = f"""
|
|
|
|
<div class="dayline">
|
|
|
|
<div class="dayline-title">
|
|
|
|
<span>{self.get_date()}</span>
|
|
|
|
{self._generate_minitimeline()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
html += minitimeline
|
2024-01-11 17:19:56 +01:00
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
return html
|
|
|
|
|
|
|
|
def has_assiduite(self) -> bool:
|
|
|
|
"""Renvoie True si le jour a une assiduité"""
|
|
|
|
return self.assiduites.count() > 0
|
|
|
|
|
|
|
|
def _get_html_normal(self) -> str:
|
2024-02-27 15:59:48 +01:00
|
|
|
"""
|
2024-05-07 15:16:40 +02:00
|
|
|
Renvoie l'html de la case du calendrier
|
|
|
|
(version journee normale (donc une couleur))
|
2024-02-27 15:59:48 +01:00
|
|
|
"""
|
2024-05-07 15:16:40 +02:00
|
|
|
class_name = self._get_color_normal()
|
|
|
|
return f'<span class="{class_name}"></span>'
|
2024-01-11 17:19:56 +01:00
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
def _get_html_demi(self) -> str:
|
|
|
|
"""
|
|
|
|
Renvoie l'html de la case du calendrier
|
|
|
|
(version journee divisée en demi-journées (donc 2 couleurs))
|
2024-02-27 15:59:48 +01:00
|
|
|
"""
|
2024-05-07 15:16:40 +02:00
|
|
|
matin = self._get_color_demi(True)
|
|
|
|
aprem = self._get_color_demi(False)
|
|
|
|
return f'<span class="{matin}"></span><span class="{aprem}"></span>'
|
|
|
|
|
|
|
|
def _get_color_normal(self) -> str:
|
|
|
|
"""renvoie la classe css correspondant
|
|
|
|
à la case du calendrier
|
|
|
|
(version journee normale)
|
2024-02-27 15:59:48 +01:00
|
|
|
"""
|
2024-01-11 17:19:56 +01:00
|
|
|
etat = ""
|
|
|
|
est_just = ""
|
|
|
|
|
|
|
|
if self.is_non_work():
|
|
|
|
return "color nonwork"
|
|
|
|
|
|
|
|
etat = self._get_color_assiduites_cascade(
|
|
|
|
self._get_etats_from_assiduites(self.assiduites),
|
2024-05-07 15:16:40 +02:00
|
|
|
show_pres=self.parent.show_pres,
|
|
|
|
show_reta=self.parent.show_reta,
|
2024-01-11 17:19:56 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
est_just = self._get_color_justificatifs_cascade(
|
|
|
|
self._get_etats_from_justificatifs(self.justificatifs),
|
|
|
|
)
|
|
|
|
|
|
|
|
return f"color {etat} {est_just}"
|
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
def _get_color_demi(self, matin: bool) -> str:
|
|
|
|
"""renvoie la classe css correspondant
|
|
|
|
à la case du calendrier
|
|
|
|
(version journee divisée en demi-journees)
|
2024-02-27 15:59:48 +01:00
|
|
|
"""
|
|
|
|
heure_midi = scass.str_to_time(ScoDocSiteConfig.get("assi_lunch_time", "13:00"))
|
2024-06-04 16:26:55 +02:00
|
|
|
plage: tuple[datetime.datetime, datetime.datetime] = ()
|
2024-01-11 17:19:56 +01:00
|
|
|
if matin:
|
2024-02-27 15:59:48 +01:00
|
|
|
heure_matin = scass.str_to_time(
|
|
|
|
ScoDocSiteConfig.get("assi_morning_time", "08:00")
|
|
|
|
)
|
2024-06-04 16:26:55 +02:00
|
|
|
plage = (
|
2024-01-11 17:19:56 +01:00
|
|
|
# date debut
|
|
|
|
scu.localize_datetime(
|
|
|
|
datetime.datetime.combine(self.date, heure_matin)
|
|
|
|
),
|
|
|
|
# date fin
|
|
|
|
scu.localize_datetime(datetime.datetime.combine(self.date, heure_midi)),
|
|
|
|
)
|
2024-06-04 16:26:55 +02:00
|
|
|
else:
|
|
|
|
heure_soir = scass.str_to_time(
|
|
|
|
ScoDocSiteConfig.get("assi_afternoon_time", "17:00")
|
2024-01-11 17:19:56 +01:00
|
|
|
)
|
|
|
|
|
2024-06-04 16:26:55 +02:00
|
|
|
# séparation en demi journées
|
|
|
|
plage = (
|
|
|
|
# date debut
|
|
|
|
scu.localize_datetime(datetime.datetime.combine(self.date, heure_midi)),
|
|
|
|
# date fin
|
|
|
|
scu.localize_datetime(datetime.datetime.combine(self.date, heure_soir)),
|
2024-01-11 17:19:56 +01:00
|
|
|
)
|
|
|
|
|
2024-06-04 16:26:55 +02:00
|
|
|
assiduites = [
|
2024-01-11 17:19:56 +01:00
|
|
|
assi
|
|
|
|
for assi in self.assiduites
|
2024-02-27 08:58:09 +01:00
|
|
|
if scu.is_period_overlapping(
|
2024-06-04 16:26:55 +02:00
|
|
|
(assi.date_debut, assi.date_fin), plage, bornes=False
|
2024-02-27 08:58:09 +01:00
|
|
|
)
|
2024-01-11 17:19:56 +01:00
|
|
|
]
|
|
|
|
|
2024-06-04 16:26:55 +02:00
|
|
|
justificatifs = [
|
2024-01-11 17:19:56 +01:00
|
|
|
justi
|
|
|
|
for justi in self.justificatifs
|
2024-02-27 08:58:09 +01:00
|
|
|
if scu.is_period_overlapping(
|
2024-06-04 16:26:55 +02:00
|
|
|
(justi.date_debut, justi.date_fin), plage, bornes=False
|
2024-02-27 08:58:09 +01:00
|
|
|
)
|
2024-01-11 17:19:56 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
etat = self._get_color_assiduites_cascade(
|
2024-06-04 16:26:55 +02:00
|
|
|
self._get_etats_from_assiduites(assiduites),
|
2024-05-07 15:16:40 +02:00
|
|
|
show_pres=self.parent.show_pres,
|
|
|
|
show_reta=self.parent.show_reta,
|
2024-01-11 17:19:56 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
est_just = self._get_color_justificatifs_cascade(
|
2024-06-04 16:26:55 +02:00
|
|
|
self._get_etats_from_justificatifs(justificatifs),
|
2024-01-11 17:19:56 +01:00
|
|
|
)
|
|
|
|
|
2024-06-04 16:26:55 +02:00
|
|
|
if est_just == "est_just" and any(
|
|
|
|
not assi.est_just
|
|
|
|
for assi in assiduites
|
|
|
|
if assi.etat != scu.EtatAssiduite.PRESENT
|
|
|
|
):
|
|
|
|
est_just = ""
|
|
|
|
|
2024-01-11 17:19:56 +01:00
|
|
|
return f"color {etat} {est_just}"
|
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
def _get_etats_from_assiduites(self, assiduites: Query) -> list[scu.EtatAssiduite]:
|
|
|
|
return list(set(scu.EtatAssiduite(assi.etat) for assi in assiduites))
|
|
|
|
|
|
|
|
def _get_etats_from_justificatifs(
|
|
|
|
self, justificatifs: Query
|
|
|
|
) -> list[scu.EtatJustificatif]:
|
|
|
|
return list(set(scu.EtatJustificatif(justi.etat) for justi in justificatifs))
|
|
|
|
|
|
|
|
def _get_color_assiduites_cascade(
|
|
|
|
self,
|
|
|
|
etats: list[scu.EtatAssiduite],
|
|
|
|
show_pres: bool = False,
|
|
|
|
show_reta: bool = False,
|
|
|
|
) -> str:
|
|
|
|
if scu.EtatAssiduite.ABSENT in etats:
|
|
|
|
return "absent"
|
|
|
|
if scu.EtatAssiduite.RETARD in etats and show_reta:
|
|
|
|
return "retard"
|
|
|
|
if scu.EtatAssiduite.PRESENT in etats and show_pres:
|
|
|
|
return "present"
|
|
|
|
|
|
|
|
return "sans_etat"
|
|
|
|
|
|
|
|
def _get_color_justificatifs_cascade(
|
|
|
|
self,
|
|
|
|
etats: list[scu.EtatJustificatif],
|
|
|
|
) -> str:
|
|
|
|
if scu.EtatJustificatif.VALIDE in etats:
|
|
|
|
return "est_just"
|
|
|
|
if scu.EtatJustificatif.ATTENTE in etats:
|
|
|
|
return "attente"
|
|
|
|
if scu.EtatJustificatif.MODIFIE in etats:
|
|
|
|
return "modifie"
|
|
|
|
if scu.EtatJustificatif.NON_VALIDE in etats:
|
|
|
|
return "invalide"
|
2024-01-11 17:19:56 +01:00
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
return ""
|
|
|
|
|
|
|
|
def _generate_minitimeline(self) -> str:
|
2024-02-27 15:59:48 +01:00
|
|
|
"""
|
|
|
|
Génère la minitimeline du jour
|
|
|
|
"""
|
2024-01-11 17:19:56 +01:00
|
|
|
# Récupérer le référenciel de la timeline
|
2024-02-27 23:14:12 +01:00
|
|
|
heure_matin: datetime.timedelta = _time_to_timedelta(
|
|
|
|
scass.str_to_time(ScoDocSiteConfig.get("assi_morning_time", "08:00"))
|
2024-01-11 17:19:56 +01:00
|
|
|
)
|
2024-02-27 23:14:12 +01:00
|
|
|
heure_soir: datetime.timedelta = _time_to_timedelta(
|
|
|
|
scass.str_to_time(ScoDocSiteConfig.get("assi_afternoon_time", "17:00"))
|
2024-01-11 17:19:56 +01:00
|
|
|
)
|
|
|
|
# longueur_timeline = heure_soir - heure_matin
|
|
|
|
longueur_timeline: datetime.timedelta = heure_soir - heure_matin
|
|
|
|
|
|
|
|
# chaque block d'assiduité est défini par:
|
|
|
|
# longueur = ( (fin-deb) / longueur_timeline ) * 100
|
|
|
|
# emplacement = ( (deb - heure_matin) / longueur_timeline ) * 100
|
2024-02-27 08:58:09 +01:00
|
|
|
# longueur + emplacement = 100% sinon on réduit longueur
|
2024-01-11 17:19:56 +01:00
|
|
|
|
|
|
|
assiduite_blocks: list[dict[str, float | str]] = []
|
|
|
|
|
|
|
|
for assi in self.assiduites:
|
|
|
|
deb: datetime.timedelta = _time_to_timedelta(
|
|
|
|
assi.date_debut.time()
|
|
|
|
if assi.date_debut.date() == self.date
|
|
|
|
else heure_matin
|
|
|
|
)
|
|
|
|
fin: datetime.timedelta = _time_to_timedelta(
|
|
|
|
assi.date_fin.time()
|
|
|
|
if assi.date_fin.date() == self.date
|
|
|
|
else heure_soir
|
|
|
|
)
|
|
|
|
|
2024-02-28 10:50:15 +01:00
|
|
|
emplacement: float = max(((deb - heure_matin) / longueur_timeline) * 100, 0)
|
2024-02-27 08:58:09 +01:00
|
|
|
longueur: float = ((fin - deb) / longueur_timeline) * 100
|
|
|
|
if longueur + emplacement > 100:
|
|
|
|
longueur = 100 - emplacement
|
2024-05-07 15:16:40 +02:00
|
|
|
|
2024-01-11 17:19:56 +01:00
|
|
|
etat: str = scu.EtatAssiduite(assi.etat).name.lower()
|
|
|
|
est_just: str = "est_just" if assi.est_just else ""
|
|
|
|
|
|
|
|
assiduite_blocks.append(
|
|
|
|
{
|
|
|
|
"longueur": longueur,
|
|
|
|
"emplacement": emplacement,
|
|
|
|
"etat": etat,
|
|
|
|
"est_just": est_just,
|
|
|
|
"bubble": _generate_assiduite_bubble(assi),
|
|
|
|
"id": assi.assiduite_id,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return render_template(
|
|
|
|
"assiduites/widgets/minitimeline_simple.j2",
|
|
|
|
assi_blocks=assiduite_blocks,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
class CalendrierAssi(sco_gen_cal.Calendrier):
|
|
|
|
"""
|
|
|
|
Représente un calendrier d'assiduité d'un étudiant
|
|
|
|
"""
|
2024-01-11 17:19:56 +01:00
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
def __init__(self, annee: int, etudiant: Identite, **options):
|
|
|
|
# On prend du 01/09 au 31/08
|
|
|
|
date_debut: datetime.datetime = datetime.datetime(annee, 9, 1, 0, 0)
|
|
|
|
date_fin: datetime.datetime = datetime.datetime(annee + 1, 8, 31, 23, 59)
|
|
|
|
super().__init__(date_debut, date_fin)
|
2024-01-11 17:19:56 +01:00
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
# On récupère les assiduités et les justificatifs
|
|
|
|
self.etud_assiduites: Query = scass.filter_by_date(
|
|
|
|
etudiant.assiduites,
|
|
|
|
Assiduite,
|
|
|
|
date_deb=date_debut,
|
|
|
|
date_fin=date_fin,
|
|
|
|
)
|
|
|
|
self.etud_justificatifs: Query = scass.filter_by_date(
|
|
|
|
etudiant.justificatifs,
|
|
|
|
Justificatif,
|
|
|
|
date_deb=date_debut,
|
|
|
|
date_fin=date_fin,
|
|
|
|
)
|
2024-01-11 17:19:56 +01:00
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
# Ajout des options (exemple : mode_demi, show_pres, show_reta, ...)
|
|
|
|
for key, value in options.items():
|
|
|
|
setattr(self, key, value)
|
2024-01-11 17:19:56 +01:00
|
|
|
|
2024-05-07 15:16:40 +02:00
|
|
|
def instanciate_jour(self, date: datetime.date) -> JourAssi:
|
|
|
|
"""
|
|
|
|
Instancie un jour d'assiduité
|
|
|
|
"""
|
|
|
|
assiduites: Query = scass.filter_by_date(
|
|
|
|
self.etud_assiduites,
|
2024-01-11 17:19:56 +01:00
|
|
|
Assiduite,
|
|
|
|
date_deb=datetime.datetime.combine(date, datetime.time(0, 0)),
|
|
|
|
date_fin=datetime.datetime.combine(date, datetime.time(23, 59, 59)),
|
|
|
|
)
|
2024-05-07 15:16:40 +02:00
|
|
|
justificatifs: Query = scass.filter_by_date(
|
|
|
|
self.etud_justificatifs,
|
2024-01-11 17:19:56 +01:00
|
|
|
Justificatif,
|
|
|
|
date_deb=datetime.datetime.combine(date, datetime.time(0, 0)),
|
|
|
|
date_fin=datetime.datetime.combine(date, datetime.time(23, 59, 59)),
|
|
|
|
)
|
2024-05-07 15:16:40 +02:00
|
|
|
return JourAssi(date, assiduites, justificatifs, parent=self)
|
2024-01-11 17:19:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
def _time_to_timedelta(t: datetime.time) -> datetime.timedelta:
|
|
|
|
if isinstance(t, datetime.timedelta):
|
|
|
|
return t
|
|
|
|
return datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
|
|
|
|
|
|
|
|
|
|
|
|
def _generate_assiduite_bubble(assiduite: Assiduite) -> str:
|
|
|
|
# Récupérer informations modules impl
|
|
|
|
moduleimpl_infos: str = assiduite.get_module(traduire=True)
|
|
|
|
|
|
|
|
# Récupérer informations saisie
|
|
|
|
saisie: str = assiduite.get_saisie()
|
|
|
|
|
2024-05-24 16:51:44 +02:00
|
|
|
motif: str = assiduite.description or "Non spécifié"
|
|
|
|
|
|
|
|
# Récupérer date
|
|
|
|
|
|
|
|
if assiduite.date_debut.date() == assiduite.date_fin.date():
|
|
|
|
jour = assiduite.date_debut.strftime("%d/%m/%Y")
|
|
|
|
heure_deb: str = assiduite.date_debut.strftime("%H:%M")
|
|
|
|
heure_fin: str = assiduite.date_fin.strftime("%H:%M")
|
|
|
|
date: str = f"{jour} de {heure_deb} à {heure_fin}"
|
|
|
|
else:
|
|
|
|
date: str = (
|
|
|
|
f"du {assiduite.date_debut.strftime('%d/%m/%Y')} "
|
|
|
|
+ f"au {assiduite.date_fin.strftime('%d/%m/%Y')}"
|
|
|
|
)
|
2024-01-19 17:06:01 +01:00
|
|
|
|
2024-01-11 17:19:56 +01:00
|
|
|
return render_template(
|
|
|
|
"assiduites/widgets/assiduite_bubble.j2",
|
|
|
|
moduleimpl=moduleimpl_infos,
|
|
|
|
etat=scu.EtatAssiduite(assiduite.etat).name.lower(),
|
2024-05-24 16:51:44 +02:00
|
|
|
date=date,
|
2024-01-11 17:19:56 +01:00
|
|
|
saisie=saisie,
|
2024-01-19 17:06:01 +01:00
|
|
|
motif=motif,
|
2024-01-11 17:19:56 +01:00
|
|
|
)
|