261 lines
9.5 KiB
Python
261 lines
9.5 KiB
Python
# -*- mode: python -*-
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
#
|
|
# Gestion scolarite IUT
|
|
#
|
|
# Copyright (c) 1999 - 2023 Emmanuel Viennet. All rights reserved.
|
|
#
|
|
# 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
|
|
#
|
|
##############################################################################
|
|
|
|
"""Vérification des absences à une évaluation
|
|
"""
|
|
from flask import url_for, g
|
|
|
|
from app import db
|
|
from app.models import Evaluation, Identite
|
|
import app.scodoc.sco_utils as scu
|
|
from app.scodoc import html_sco_header
|
|
from app.scodoc import sco_abs
|
|
from app.scodoc import sco_etud
|
|
from app.scodoc import sco_evaluations
|
|
from app.scodoc import sco_evaluation_db
|
|
from app.scodoc import sco_formsemestre
|
|
from app.scodoc import sco_groups
|
|
from app.scodoc import sco_moduleimpl
|
|
|
|
|
|
def evaluation_check_absences(evaluation: Evaluation):
|
|
"""Vérifie les absences au moment de cette évaluation.
|
|
Cas incohérents que l'on peut rencontrer pour chaque étudiant:
|
|
note et absent
|
|
ABS et pas noté absent
|
|
ABS et absent justifié
|
|
EXC et pas noté absent
|
|
EXC et pas justifie
|
|
Ramene 5 listes d'etudid
|
|
"""
|
|
if not evaluation.date_debut:
|
|
return [], [], [], [], [] # evaluation sans date
|
|
|
|
am, pm = evaluation.is_matin(), evaluation.is_apresmidi()
|
|
|
|
# Liste les absences à ce moment:
|
|
absences = sco_abs.list_abs_jour(evaluation.date_debut, am=am, pm=pm)
|
|
abs_etudids = set([x["etudid"] for x in absences]) # ensemble des etudiants absents
|
|
abs_non_just = sco_abs.list_abs_non_just_jour(
|
|
evaluation.date_debut.date(), am=am, pm=pm
|
|
)
|
|
abs_nj_etudids = set(
|
|
[x["etudid"] for x in abs_non_just]
|
|
) # ensemble des etudiants absents non justifies
|
|
justifs = sco_abs.list_abs_jour(
|
|
evaluation.date_debut.date(), am=am, pm=pm, is_abs=None, is_just=True
|
|
)
|
|
just_etudids = set(
|
|
[x["etudid"] for x in justifs]
|
|
) # ensemble des etudiants avec justif
|
|
|
|
# Les notes:
|
|
notes_db = sco_evaluation_db.do_evaluation_get_all_notes(evaluation.id)
|
|
ValButAbs = [] # une note mais noté absent
|
|
AbsNonSignalee = [] # note ABS mais pas noté absent
|
|
ExcNonSignalee = [] # note EXC mais pas noté absent
|
|
ExcNonJust = [] # note EXC mais absent non justifie
|
|
AbsButExc = [] # note ABS mais justifié
|
|
for etudid, _ in sco_groups.do_evaluation_listeetuds_groups(
|
|
evaluation.id, getallstudents=True
|
|
):
|
|
if etudid in notes_db:
|
|
val = notes_db[etudid]["value"]
|
|
if (
|
|
val is not None
|
|
and val != scu.NOTES_NEUTRALISE
|
|
and val != scu.NOTES_ATTENTE
|
|
) and etudid in abs_etudids:
|
|
# note valide et absent
|
|
ValButAbs.append(etudid)
|
|
if val is None and not etudid in abs_etudids:
|
|
# absent mais pas signale comme tel
|
|
AbsNonSignalee.append(etudid)
|
|
if val == scu.NOTES_NEUTRALISE and not etudid in abs_etudids:
|
|
# Neutralisé mais pas signale absent
|
|
ExcNonSignalee.append(etudid)
|
|
if val == scu.NOTES_NEUTRALISE and etudid in abs_nj_etudids:
|
|
# EXC mais pas justifié
|
|
ExcNonJust.append(etudid)
|
|
if val is None and etudid in just_etudids:
|
|
# ABS mais justificatif
|
|
AbsButExc.append(etudid)
|
|
|
|
return ValButAbs, AbsNonSignalee, ExcNonSignalee, ExcNonJust, AbsButExc
|
|
|
|
|
|
def evaluation_check_absences_html(evaluation_id, with_header=True, show_ok=True):
|
|
"""Affiche état vérification absences d'une évaluation"""
|
|
evaluation: Evaluation = db.session.get(Evaluation, evaluation_id)
|
|
am, pm = evaluation.is_matin(), evaluation.is_apresmidi()
|
|
# 1 si matin, 0 si apres midi, 2 si toute la journee:
|
|
match am, pm:
|
|
case False, True:
|
|
demijournee = 0
|
|
case True, False:
|
|
demijournee = 1
|
|
case _:
|
|
demijournee = 2
|
|
|
|
(
|
|
ValButAbs,
|
|
AbsNonSignalee,
|
|
ExcNonSignalee,
|
|
ExcNonJust,
|
|
AbsButExc,
|
|
) = evaluation_check_absences(evaluation)
|
|
|
|
if with_header:
|
|
H = [
|
|
html_sco_header.html_sem_header("Vérification absences à l'évaluation"),
|
|
sco_evaluations.evaluation_describe(evaluation_id=evaluation.id),
|
|
"""<p class="help">Vérification de la cohérence entre les notes saisies
|
|
et les absences signalées.</p>""",
|
|
]
|
|
else:
|
|
# pas de header, mais un titre
|
|
H = [
|
|
f"""<h2 class="eval_check_absences">{
|
|
evaluation.description or "évaluation"
|
|
} du {
|
|
evaluation.date_debut.strftime("%d/%m/%Y") if evaluation.date_debut else ""
|
|
} """
|
|
]
|
|
if (
|
|
not ValButAbs
|
|
and not AbsNonSignalee
|
|
and not ExcNonSignalee
|
|
and not ExcNonJust
|
|
):
|
|
H.append(': <span class="eval_check_absences_ok">ok</span>')
|
|
H.append("</h2>")
|
|
|
|
def etudlist(etudids, linkabs=False):
|
|
H.append("<ul>")
|
|
if not etudids and show_ok:
|
|
H.append("<li>aucun</li>")
|
|
for etudid in etudids:
|
|
etud: Identite = db.session.get(Identite, etudid)
|
|
H.append(
|
|
f"""<li><a class="discretelink" href="{
|
|
url_for(
|
|
"scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etudid
|
|
)
|
|
}">{etud.nomprenom}</a>"""
|
|
)
|
|
if linkabs:
|
|
url = url_for(
|
|
"absences.doSignaleAbsence",
|
|
scodoc_dept=g.scodoc_dept,
|
|
etudid=etudid,
|
|
# par defaut signale le jour du début de l'éval
|
|
datedebut=evaluation.date_debut.strftime("%d/%m/%Y"),
|
|
datefin=evaluation.date_debut.strftime("%d/%m/%Y"),
|
|
demijournee=demijournee,
|
|
moduleimpl_id=evaluation.moduleimpl_id,
|
|
)
|
|
H.append(
|
|
f"""<a class="stdlink" href="{url}">signaler cette absence</a>"""
|
|
)
|
|
H.append("</li>")
|
|
H.append("</ul>")
|
|
|
|
if ValButAbs or show_ok:
|
|
H.append(
|
|
"<h3>Etudiants ayant une note alors qu'ils sont signalés absents:</h3>"
|
|
)
|
|
etudlist(ValButAbs)
|
|
|
|
if AbsNonSignalee or show_ok:
|
|
H.append(
|
|
"""<h3>Etudiants avec note "ABS" alors qu'ils ne sont <em>pas</em> signalés absents:</h3>"""
|
|
)
|
|
etudlist(AbsNonSignalee, linkabs=True)
|
|
|
|
if ExcNonSignalee or show_ok:
|
|
H.append(
|
|
"""<h3>Etudiants avec note "EXC" alors qu'ils ne sont <em>pas</em> signalés absents:</h3>"""
|
|
)
|
|
etudlist(ExcNonSignalee)
|
|
|
|
if ExcNonJust or show_ok:
|
|
H.append(
|
|
"""<h3>Etudiants avec note "EXC" alors qu'ils sont absents <em>non justifiés</em>:</h3>"""
|
|
)
|
|
etudlist(ExcNonJust)
|
|
|
|
if AbsButExc or show_ok:
|
|
H.append(
|
|
"""<h3>Etudiants avec note "ABS" alors qu'ils ont une <em>justification</em>:</h3>"""
|
|
)
|
|
etudlist(AbsButExc)
|
|
|
|
if with_header:
|
|
H.append(html_sco_header.sco_footer())
|
|
return "\n".join(H)
|
|
|
|
|
|
def formsemestre_check_absences_html(formsemestre_id):
|
|
"""Affiche etat verification absences pour toutes les evaluations du semestre !"""
|
|
sem = sco_formsemestre.get_formsemestre(formsemestre_id)
|
|
H = [
|
|
html_sco_header.html_sem_header(
|
|
"Vérification absences aux évaluations de ce semestre",
|
|
),
|
|
"""<p class="help">Vérification de la cohérence entre les notes saisies et les absences signalées.
|
|
Sont listés tous les modules avec des évaluations.<br>Aucune action n'est effectuée:
|
|
il vous appartient de corriger les erreurs détectées si vous le jugez nécessaire.
|
|
</p>""",
|
|
]
|
|
# Modules, dans l'ordre
|
|
Mlist = sco_moduleimpl.moduleimpl_withmodule_list(formsemestre_id=formsemestre_id)
|
|
for M in Mlist:
|
|
evals = sco_evaluation_db.get_evaluation_dict(
|
|
{"moduleimpl_id": M["moduleimpl_id"]}
|
|
)
|
|
if evals:
|
|
H.append(
|
|
'<div class="module_check_absences"><h2><a href="moduleimpl_status?moduleimpl_id=%s">%s: %s</a></h2>'
|
|
% (
|
|
M["moduleimpl_id"],
|
|
M["module"]["code"] or "",
|
|
M["module"]["abbrev"] or "",
|
|
)
|
|
)
|
|
for E in evals:
|
|
H.append(
|
|
evaluation_check_absences_html(
|
|
E["evaluation_id"],
|
|
with_header=False,
|
|
show_ok=False,
|
|
)
|
|
)
|
|
if evals:
|
|
H.append("</div>")
|
|
H.append(html_sco_header.sco_footer())
|
|
return "\n".join(H)
|