MonScoDocEssai/app/scodoc/sco_abs_views.py

1095 lines
36 KiB
Python
Raw Normal View History

2020-09-26 16:19:37 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
2023-01-02 13:16:27 +01:00
# Copyright (c) 1999 - 2023 Emmanuel Viennet. All rights reserved.
2020-09-26 16:19:37 +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
#
##############################################################################
"""Pages HTML gestion absences
2020-09-26 16:19:37 +02:00
(la plupart portées du DTML)
"""
import datetime
2020-09-26 16:19:37 +02:00
2021-12-21 23:05:49 +01:00
from flask import url_for, g, request, abort
2020-09-26 16:19:37 +02:00
2021-12-26 19:15:47 +01:00
from app import log
from app.comp import res_sem
from app.comp.res_compat import NotesTableCompat
from app.models import Identite, FormSemestre
import app.scodoc.sco_utils as scu
from app.scodoc import notesdb as ndb
from app.scodoc.scolog import logdb
from app.scodoc.gen_tables import GenTable
from app.scodoc import html_sco_header
from app.scodoc import sco_abs
from app.scodoc import sco_etud
from app.scodoc import sco_find_etud
from app.scodoc import sco_formsemestre
from app.scodoc import sco_groups
from app.scodoc import sco_moduleimpl
from app.scodoc import sco_photos
from app.scodoc import sco_preferences
from app.scodoc.sco_exceptions import ScoValueError
2020-09-26 16:19:37 +02:00
def doSignaleAbsence(
datedebut,
datefin,
moduleimpl_id=None,
demijournee=2,
estjust=False,
description=None,
2021-02-04 23:16:18 +01:00
etudid=False,
2020-09-26 16:19:37 +02:00
): # etudid implied
2021-02-04 23:16:18 +01:00
"""Signalement d'une absence.
Args:
datedebut: dd/mm/yyyy
datefin: dd/mm/yyyy (non incluse)
moduleimpl_id: module auquel imputer les absences
demijournee: 2 si journée complète, 1 matin, 0 après-midi
estjust: absence justifiée
description: str
2021-09-24 12:10:53 +02:00
etudid: etudiant concerné. Si non spécifié, cherche dans
les paramètres de la requête courante.
2021-02-04 23:16:18 +01:00
"""
2021-12-26 19:15:47 +01:00
etud = Identite.from_request(etudid)
2021-08-16 22:41:09 +02:00
if not moduleimpl_id:
moduleimpl_id = None
2020-09-26 16:19:37 +02:00
description_abs = description
dates = sco_abs.DateRangeISO(datedebut, datefin)
2020-09-26 16:19:37 +02:00
nbadded = 0
2021-05-03 11:56:41 +02:00
demijournee = int(demijournee)
2020-09-26 16:19:37 +02:00
for jour in dates:
2021-05-03 11:56:41 +02:00
if demijournee == 2:
sco_abs.add_absence(
2021-12-26 19:15:47 +01:00
etud.id,
jour,
False,
estjust,
description_abs,
moduleimpl_id,
2020-09-26 16:19:37 +02:00
)
sco_abs.add_absence(
2021-12-26 19:15:47 +01:00
etud.id,
jour,
True,
estjust,
description_abs,
moduleimpl_id,
2020-09-26 16:19:37 +02:00
)
nbadded += 2
else:
sco_abs.add_absence(
2021-12-26 19:15:47 +01:00
etud.id,
2021-06-12 22:43:22 +02:00
jour,
demijournee,
estjust,
description_abs,
moduleimpl_id,
2020-09-26 16:19:37 +02:00
)
nbadded += 1
#
if estjust:
2022-10-04 21:55:43 +02:00
just_str = ""
2020-09-26 16:19:37 +02:00
else:
2022-10-04 21:55:43 +02:00
just_str = "NON "
2021-12-26 19:15:47 +01:00
indication_module = ""
2020-09-26 16:19:37 +02:00
if moduleimpl_id and moduleimpl_id != "NULL":
mod = sco_moduleimpl.moduleimpl_list(moduleimpl_id=moduleimpl_id)[0]
2020-09-26 16:19:37 +02:00
formsemestre_id = mod["formsemestre_id"]
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
2021-12-24 00:08:25 +01:00
ues = nt.get_ues_stat_dict()
2020-09-26 16:19:37 +02:00
for ue in ues:
2021-12-26 19:15:47 +01:00
modimpls = nt.get_modimpls_dict(ue_id=ue["ue_id"])
2020-09-26 16:19:37 +02:00
for modimpl in modimpls:
if modimpl["moduleimpl_id"] == moduleimpl_id:
indication_module = "dans le module %s" % (
modimpl["module"]["code"] or "(pas de code)"
)
2020-09-26 16:19:37 +02:00
H = [
2021-06-13 19:12:20 +02:00
html_sco_header.sco_header(
2021-12-26 19:15:47 +01:00
page_title=f"Signalement d'une absence pour {etud.nomprenom}",
2020-09-26 16:19:37 +02:00
),
"""<h2>Signalement d'absences</h2>""",
]
if dates:
H.append(
2023-08-23 01:42:03 +02:00
f"""<p>Ajout de {nbadded} absences <b>{just_str}justifiées</b>
2022-10-04 21:55:43 +02:00
du {datedebut} au {datefin} {indication_module}
</p>
"""
2020-09-26 16:19:37 +02:00
)
else:
H.append(
2023-08-23 01:42:03 +02:00
f"""<p class="warning">Aucune date ouvrable
2022-10-04 21:55:43 +02:00
entre le {datedebut} et le {datefin} !
</p>
"""
2020-09-26 16:19:37 +02:00
)
H.append(
2021-12-26 19:15:47 +01:00
f"""<ul>
2023-08-23 01:42:03 +02:00
<li><a class="stdlink" href="{url_for("absences.SignaleAbsenceEtud",
2021-12-26 19:15:47 +01:00
scodoc_dept=g.scodoc_dept, etudid=etud.id
)}">Autre absence pour <b>{etud.nomprenom}</b></a>
</li>
2023-08-23 01:42:03 +02:00
<li><a class="stdlink" href="{url_for("absences.CalAbs",
2021-12-26 19:15:47 +01:00
scodoc_dept=g.scodoc_dept, etudid=etud.id
)}">Calendrier de ses absences</a>
</li>
</ul>
<hr>
2022-10-04 21:55:43 +02:00
{sco_find_etud.form_search_etud()}
{html_sco_header.sco_footer()}
2021-12-26 19:15:47 +01:00
"""
2020-09-26 16:19:37 +02:00
)
return "\n".join(H)
2021-09-24 12:10:53 +02:00
def SignaleAbsenceEtud(): # etudid implied
2020-12-28 22:59:59 +01:00
"""Formulaire individuel simple de signalement d'une absence"""
2020-09-26 16:19:37 +02:00
# brute-force portage from very old dtml code ...
2021-08-22 13:24:36 +02:00
etud = sco_etud.get_etud_info(filled=True)[0]
2020-09-26 16:19:37 +02:00
etudid = etud["etudid"]
disabled = False
2020-09-26 16:19:37 +02:00
if not etud["cursem"]:
2021-06-14 00:23:22 +02:00
require_module = sco_preferences.get_preference(
"abs_require_module"
) # on utilise la pref globale car pas de sem courant
if require_module:
2023-08-23 01:42:03 +02:00
menu_module = """<div class="ue_warning">Pas
inscrit dans un semestre courant,
et l'indication du module est requise.
Donc pas de saisie d'absence possible !
</div>
"""
disabled = True
else:
menu_module = ""
2020-09-26 16:19:37 +02:00
else:
formsemestre_id = etud["cursem"]["formsemestre_id"]
formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
ues = nt.get_ues_stat_dict()
2021-06-14 00:23:22 +02:00
require_module = sco_preferences.get_preference(
"abs_require_module", formsemestre_id
2021-06-14 00:23:22 +02:00
)
if require_module:
menu_module = """
<script type="text/javascript">
function form_enable_disable() {
2023-08-23 01:42:03 +02:00
if ( $("select#sel_moduleimpl_id").val() == "" ) {
$("#butsubmit").prop("disabled", true);
} else {
$("#butsubmit").prop("disabled", false);
};
}
$(document).ready(function() {
form_enable_disable();
});
</script>
2023-08-23 01:42:03 +02:00
<p>Module:
<select id="sel_moduleimpl_id" name="moduleimpl_id"
onChange="form_enable_disable();">"""
else:
menu_module = (
"""<p>Module: <select id="sel_moduleimpl_id" name="moduleimpl_id">"""
)
2021-08-16 22:41:09 +02:00
menu_module += """<option value="" selected>(Module)</option>"""
2020-09-26 16:19:37 +02:00
for ue in ues:
2021-12-26 19:15:47 +01:00
modimpls = nt.get_modimpls_dict(ue_id=ue["ue_id"])
2020-09-26 16:19:37 +02:00
for modimpl in modimpls:
menu_module += (
"""<option value="%(modimpl_id)s">%(modname)s</option>\n"""
% {
"modimpl_id": modimpl["moduleimpl_id"],
"modname": modimpl["module"]["code"] or "",
2020-09-26 16:19:37 +02:00
}
)
menu_module += """</select></p>"""
H = [
2021-06-13 19:12:20 +02:00
html_sco_header.sco_header(
page_title="Signalement d'une absence pour %(nomprenom)s" % etud,
2020-09-26 16:19:37 +02:00
),
"""<table><tr><td>
<h2>Signalement d'une absence pour %(nomprenom)s</h2>
</td><td>
"""
% etud,
"""<a href="%s">"""
% url_for("scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etud["etudid"]),
2020-09-26 16:19:37 +02:00
sco_photos.etud_photo_html(
2020-12-28 22:59:59 +01:00
etudid=etudid,
title="fiche de " + etud["nomprenom"],
2020-09-26 16:19:37 +02:00
),
"""</a></td></tr></table>""",
"""
<form action="doSignaleAbsence" method="get">
<input type="hidden" name="etudid" value="%(etudid)s">
<p>
<table><tr>
<td>Date début : </td>
2023-08-23 01:42:03 +02:00
<td>
<input type="text" name="datedebut" size="10" class="datepicker"/>
<em>j/m/a</em>
</td>
<td>&nbsp;&nbsp;&nbsp;Date fin (optionnelle):</td>
2020-09-26 16:19:37 +02:00
<td><input type="text" name="datefin" size="10" class="datepicker"/> <em>j/m/a</em></td>
</tr>
</table>
<br>
<input type="radio" name="demijournee" value="2" checked>Journée(s)
2020-09-26 16:19:37 +02:00
&nbsp;<input type="radio" name="demijournee" value="1">Matin(s)
&nbsp;<input type="radio" name="demijournee" value="0">Après-midi
2020-09-26 16:19:37 +02:00
%(menu_module)s
<p>
<input type="checkbox" name="estjust"/>Absence justifiée.
<br>
2020-09-26 16:19:37 +02:00
Raison: <input type="text" name="description" size="42"/> (optionnel)
</p>
<p>
2023-08-23 01:42:03 +02:00
<input id="butsubmit" type="submit" value="Envoyer" disable="%(disabled)s"/>
2020-09-26 16:19:37 +02:00
<em>
<p>Seuls les modules du semestre en cours apparaissent.</p>
<p>Évitez de saisir une absence pour un module qui n'est pas en place à cette date.</p>
<p>Toutes les dates sont au format jour/mois/annee.</p>
2020-09-26 16:19:37 +02:00
</em>
2023-08-23 01:42:03 +02:00
</form>
2020-09-26 16:19:37 +02:00
"""
% {
"etudid": etud["etudid"],
"menu_module": menu_module,
"disabled": "disabled" if disabled else "",
},
html_sco_header.sco_footer(),
2020-09-26 16:19:37 +02:00
]
return "\n".join(H)
def doJustifAbsence(
2021-02-04 23:16:18 +01:00
datedebut,
datefin,
demijournee,
description=None,
etudid=False,
2020-09-26 16:19:37 +02:00
): # etudid implied
2021-02-04 23:16:18 +01:00
"""Justification d'une absence
Args:
datedebut: dd/mm/yyyy
datefin: dd/mm/yyyy (non incluse)
demijournee: 2 si journée complète, 1 matin, 0 après-midi
estjust: absence justifiée
description: str
2021-09-24 12:10:53 +02:00
etudid: etudiant concerné. Si non spécifié, cherche dans les
paramètres de la requête.
2021-02-04 23:16:18 +01:00
"""
2021-08-22 13:24:36 +02:00
etud = sco_etud.get_etud_info(filled=True, etudid=etudid)[0]
2020-09-26 16:19:37 +02:00
etudid = etud["etudid"]
description_abs = description
dates = sco_abs.DateRangeISO(datedebut, datefin)
2020-09-26 16:19:37 +02:00
nbadded = 0
2021-05-03 11:56:41 +02:00
demijournee = int(demijournee)
2020-09-26 16:19:37 +02:00
for jour in dates:
2021-05-03 11:56:41 +02:00
if demijournee == 2:
sco_abs.add_justif(
2020-09-26 16:19:37 +02:00
etudid=etudid,
jour=jour,
matin=False,
description=description_abs,
)
sco_abs.add_justif(
2020-09-26 16:19:37 +02:00
etudid=etudid,
jour=jour,
matin=True,
description=description_abs,
)
nbadded += 2
else:
sco_abs.add_justif(
2020-09-26 16:19:37 +02:00
etudid=etudid,
jour=jour,
2021-05-03 11:56:41 +02:00
matin=demijournee,
2020-09-26 16:19:37 +02:00
description=description_abs,
)
nbadded += 1
#
H = [
2021-06-13 19:12:20 +02:00
html_sco_header.sco_header(
page_title="Justification d'une absence pour %(nomprenom)s" % etud,
2020-09-26 16:19:37 +02:00
),
"""<h2>Justification d'absences</h2>""",
]
if dates:
H.append(
"""<p>Ajout de %d <b>justifications</b> du %s au %s</p>"""
% (nbadded, datedebut, datefin)
)
else:
H.append(
"""<p class="warning">Aucune date ouvrable entre le %s et le %s !</p>"""
% (datedebut, datefin)
)
H.append(
2023-08-23 01:42:03 +02:00
"""<ul>
<li><a href="JustifAbsenceEtud?etudid=%(etudid)s">Autre justification
pour <b>%(nomprenom)s</b>
</a></li>
2020-09-26 16:19:37 +02:00
<li><a href="SignaleAbsenceEtud?etudid=%(etudid)s">Signaler une absence</a></li>
<li><a href="CalAbs?etudid=%(etudid)s">Calendrier de ses absences</a></li>
<li><a href="ListeAbsEtud?etudid=%(etudid)s">Liste de ses absences</a></li>
</ul>
<hr>"""
% etud
)
2021-08-22 13:24:36 +02:00
H.append(sco_find_etud.form_search_etud())
H.append(html_sco_header.sco_footer())
2020-09-26 16:19:37 +02:00
return "\n".join(H)
2021-09-24 12:10:53 +02:00
def JustifAbsenceEtud(): # etudid implied
2020-12-28 22:59:59 +01:00
"""Formulaire individuel simple de justification d'une absence"""
2020-09-26 16:19:37 +02:00
# brute-force portage from very old dtml code ...
2021-08-22 13:24:36 +02:00
etud = sco_etud.get_etud_info(filled=True)[0]
2020-09-26 16:19:37 +02:00
etudid = etud["etudid"]
H = [
2021-06-13 19:12:20 +02:00
html_sco_header.sco_header(
page_title="Justification d'une absence pour %(nomprenom)s" % etud,
2020-09-26 16:19:37 +02:00
),
"""<table><tr><td>
<h2>Justification d'une absence pour %(nomprenom)s</h2>
</td><td>
"""
% etud,
"""<a href="%s">"""
% url_for("scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etudid),
2020-09-26 16:19:37 +02:00
sco_photos.etud_photo_html(
2020-12-28 22:59:59 +01:00
etudid=etudid,
title="fiche de " + etud["nomprenom"],
2020-09-26 16:19:37 +02:00
),
"""</a></td></tr></table>""",
"""
2023-08-23 01:42:03 +02:00
<form action="doJustifAbsence" method="get">
2020-09-26 16:19:37 +02:00
<input type="hidden" name="etudid" value="%(etudid)s">
<p>
<table><tr>
2023-08-23 01:42:03 +02:00
<td>Date début : </td>
2020-09-26 16:19:37 +02:00
<td>
<input type="text" name="datedebut" size="10" class="datepicker"/>
</td>
<td>&nbsp;&nbsp;&nbsp;Date Fin (optionnel):</td>
<td><input type="text" name="datefin" size="10" class="datepicker"/></td>
</tr>
</table>
<br>
2020-09-26 16:19:37 +02:00
<input type="radio" name="demijournee" value="2" checked>Journée(s)
2020-09-26 16:19:37 +02:00
&nbsp;<input type="radio" name="demijournee" value="1">Matin(s)
&nbsp;<input type="radio" name="demijournee" value="0">Apr&egrave;s midi
<br><br>
2020-09-26 16:19:37 +02:00
Raison: <input type="text" name="description" size="42"/> (optionnel)
<p>
2023-08-23 01:42:03 +02:00
<input type="submit" value="Envoyer">
2020-09-26 16:19:37 +02:00
</form> """
% etud,
html_sco_header.sco_footer(),
2020-09-26 16:19:37 +02:00
]
return "\n".join(H)
2021-09-24 12:10:53 +02:00
def doAnnuleAbsence(datedebut, datefin, demijournee, etudid=False): # etudid implied
2020-12-28 22:59:59 +01:00
"""Annulation des absences pour une demi journée"""
2021-08-22 13:24:36 +02:00
etud = sco_etud.get_etud_info(filled=True, etudid=etudid)[0]
2020-09-26 16:19:37 +02:00
etudid = etud["etudid"]
dates = sco_abs.DateRangeISO(datedebut, datefin)
2020-09-26 16:19:37 +02:00
nbadded = 0
2021-05-03 11:56:41 +02:00
demijournee = int(demijournee)
2020-09-26 16:19:37 +02:00
for jour in dates:
2021-05-03 11:56:41 +02:00
if demijournee == 2:
sco_abs.annule_absence(etudid, jour, False)
sco_abs.annule_absence(etudid, jour, True)
2020-09-26 16:19:37 +02:00
nbadded += 2
else:
sco_abs.annule_absence(etudid, jour, demijournee)
2020-09-26 16:19:37 +02:00
nbadded += 1
#
H = [
2021-06-13 19:12:20 +02:00
html_sco_header.sco_header(
page_title="Annulation d'une absence pour %(nomprenom)s" % etud,
2020-09-26 16:19:37 +02:00
),
"""<h2>Annulation d'absences pour %(nomprenom)s</h2>""" % etud,
]
if dates:
H.append(
"<p>Annulation sur %d demi-journées du %s au %s"
% (nbadded, datedebut, datefin)
)
else:
H.append(
"""<p class="warning">Aucune date ouvrable entre le %s et le %s !</p>"""
% (datedebut, datefin)
)
H.append(
"""<ul><li><a href="AnnuleAbsenceEtud?etudid=%(etudid)s">Annulation d'une
autre absence pour <b>%(nomprenom)s</b></a></li>
2023-08-23 01:42:03 +02:00
<li><a href="SignaleAbsenceEtud?etudid=%(etudid)s">Ajout d'une
absence</a></li>
<li><a href="CalAbs?etudid=%(etudid)s">Calendrier de ses
absences</a></li>
2020-09-26 16:19:37 +02:00
</ul>
<hr>"""
% etud
)
2021-08-22 13:24:36 +02:00
H.append(sco_find_etud.form_search_etud())
H.append(html_sco_header.sco_footer())
2020-09-26 16:19:37 +02:00
return "\n".join(H)
2021-09-24 12:10:53 +02:00
def AnnuleAbsenceEtud(): # etudid implied
2020-12-28 22:59:59 +01:00
"""Formulaire individuel simple d'annulation d'une absence"""
2020-09-26 16:19:37 +02:00
# brute-force portage from very old dtml code ...
2021-08-22 13:24:36 +02:00
etud = sco_etud.get_etud_info(filled=True)[0]
2020-09-26 16:19:37 +02:00
etudid = etud["etudid"]
H = [
2021-06-13 19:12:20 +02:00
html_sco_header.sco_header(
page_title="Annulation d'une absence pour %(nomprenom)s" % etud,
2020-09-26 16:19:37 +02:00
),
"""<table><tr><td>
2023-08-23 01:42:03 +02:00
<h2><font color="#FF0000">Annulation</font> d'une absence
pour %(nomprenom)s</h2>
2020-09-26 16:19:37 +02:00
</td><td>
"""
2023-08-23 01:42:03 +02:00
% etud,
"""<a href="%s">"""
% url_for("scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etudid),
2020-09-26 16:19:37 +02:00
sco_photos.etud_photo_html(
2020-12-28 22:59:59 +01:00
etudid=etudid,
title="fiche de " + etud["nomprenom"],
2020-09-26 16:19:37 +02:00
),
"""</a></td></tr></table>""",
2023-08-23 01:42:03 +02:00
"""<p>A n'utiliser que suite à une erreur de saisie ou lorsqu'il s'avère que
l'étudiant était en fait présent.
</p>
<p><font color="#FF0000">Si plusieurs modules sont affectés,
les absences seront toutes effacées. </font></p>
"""
2020-09-26 16:19:37 +02:00
% etud,
"""<table frame="border" border="1"><tr><td>
2023-08-23 01:42:03 +02:00
<form action="doAnnuleAbsence" method="get">
2020-09-26 16:19:37 +02:00
<input type="hidden" name="etudid" value="%(etudid)s">
<p>
<table><tr>
2023-08-23 01:42:03 +02:00
<td>Date début : </td>
2020-09-26 16:19:37 +02:00
<td>
<input type="text" name="datedebut" size="10" class="datepicker"/> <em>j/m/a</em>
</td>
<td>&nbsp;&nbsp;&nbsp;Date Fin (optionnel):</td>
<td>
<input type="text" name="datefin" size="10" class="datepicker"/> <em>j/m/a</em>
</td>
</tr>
</table>
2023-08-23 01:42:03 +02:00
<input type="radio" name="demijournee" value="2" checked>journée(s)
2020-09-26 16:19:37 +02:00
&nbsp;<input type="radio" name="demijournee" value="1">Matin(s)
&nbsp;<input type="radio" name="demijournee" value="0">Apr&egrave;s midi
<p>
2023-08-23 01:42:03 +02:00
<input type="submit" value="Supprimer les absences">
</form>
2020-09-26 16:19:37 +02:00
</td></tr>
<tr><td>
2023-08-23 01:42:03 +02:00
<form action="doAnnuleJustif" method="get">
2020-09-26 16:19:37 +02:00
<input type="hidden" name="etudid" value="%(etudid)s">
<p>
<table><tr>
2023-08-23 01:42:03 +02:00
<td>Date début : </td>
2020-09-26 16:19:37 +02:00
<td>
<input type="text" name="datedebut0" size="10" class="datepicker"/> <em>j/m/a</em>
</td>
<td>&nbsp;&nbsp;&nbsp;Date Fin (optionnel):</td>
<td>
<input type="text" name="datefin0" size="10" class="datepicker"/> <em>j/m/a</em>
</td>
</tr>
</table>
<p>
2023-08-23 01:42:03 +02:00
<input type="radio" name="demijournee" value="2" checked>journée(s)
2020-09-26 16:19:37 +02:00
&nbsp;<input type="radio" name="demijournee" value="1">Matin(s)
&nbsp;<input type="radio" name="demijournee" value="0">Apr&egrave;s midi
<p>
2023-08-23 01:42:03 +02:00
<input type="submit" value="Supprimer les justificatifs">
<i>(utiliser ceci en cas de justificatif erroné saisi indépendemment
d'une absence)</i>
</form>
2020-09-26 16:19:37 +02:00
</td></tr></table>"""
% etud,
html_sco_header.sco_footer(),
2020-09-26 16:19:37 +02:00
]
return "\n".join(H)
2021-09-24 12:10:53 +02:00
def doAnnuleJustif(datedebut0, datefin0, demijournee): # etudid implied
2020-12-28 22:59:59 +01:00
"""Annulation d'une justification"""
2021-08-22 13:24:36 +02:00
etud = sco_etud.get_etud_info(filled=True)[0]
2020-09-26 16:19:37 +02:00
etudid = etud["etudid"]
dates = sco_abs.DateRangeISO(datedebut0, datefin0)
2020-09-26 16:19:37 +02:00
nbadded = 0
2021-05-03 11:56:41 +02:00
demijournee = int(demijournee)
2020-09-26 16:19:37 +02:00
for jour in dates:
# Attention: supprime matin et après-midi
2021-05-03 11:56:41 +02:00
if demijournee == 2:
2021-09-24 12:10:53 +02:00
sco_abs.annule_justif(etudid, jour, False)
sco_abs.annule_justif(etudid, jour, True)
2020-09-26 16:19:37 +02:00
nbadded += 2
else:
2021-09-24 12:10:53 +02:00
sco_abs.annule_justif(etudid, jour, demijournee)
2020-09-26 16:19:37 +02:00
nbadded += 1
#
H = [
2021-06-13 19:12:20 +02:00
html_sco_header.sco_header(
2020-09-26 16:19:37 +02:00
page_title="Annulation d'une justification pour %(nomprenom)s" % etud,
),
"""<h2>Annulation de justifications pour %(nomprenom)s</h2>""" % etud,
]
if dates:
H.append(
"<p>Annulation sur %d demi-journées du %s au %s"
% (nbadded, datedebut0, datefin0)
)
else:
H.append(
"""<p class="warning">Aucune date ouvrable entre le %s et le %s !</p>"""
% (datedebut0, datefin0)
)
H.append(
"""<ul><li><a href="AnnuleAbsenceEtud?etudid=%(etudid)s">Annulation d'une
autre absence pour <b>%(nomprenom)s</b></a></li>
2023-08-23 01:42:03 +02:00
<li><a href="SignaleAbsenceEtud?etudid=%(etudid)s">Ajout d'une
absence</a></li>
<li><a href="CalAbs?etudid=%(etudid)s">Calendrier de ses
absences</a></li>
2020-09-26 16:19:37 +02:00
</ul>
<hr>"""
% etud
)
2021-08-22 13:24:36 +02:00
H.append(sco_find_etud.form_search_etud())
H.append(html_sco_header.sco_footer())
2020-09-26 16:19:37 +02:00
return "\n".join(H)
def AnnuleAbsencesDatesNoJust(etudid, dates, moduleimpl_id=None):
2021-07-31 23:05:53 +02:00
"""Supprime les absences non justifiées aux dates indiquées
Ne supprime pas les justificatifs éventuels.
Args:
etudid: l'étudiant
dates: liste de dates iso, eg [ "2000-01-15", "2000-01-16" ]
moduleimpl_id: si spécifié, n'affecte que les absences de ce module
Returns:
None
"""
# log('AnnuleAbsencesDatesNoJust: moduleimpl_id=%s' % moduleimpl_id)
if not dates:
return
date0 = dates[0]
if len(date0.split(":")) == 2:
# am/pm is present
for date in dates:
jour, ampm = date.split(":")
if ampm == "am":
matin = 1
elif ampm == "pm":
matin = 0
else:
raise ValueError("invalid ampm !")
sco_abs.annule_absence(etudid, jour, matin, moduleimpl_id)
return
cnx = ndb.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
# supr les absences non justifiees
for date in dates:
cursor.execute(
2023-08-23 01:42:03 +02:00
"""DELETE FROM absences
WHERE etudid=%(etudid)s
AND (not estjust)
AND jour=%(date)s
AND moduleimpl_id=%(moduleimpl_id)s
2021-09-13 22:10:01 +02:00
""",
vars(),
)
2021-07-19 19:53:01 +02:00
sco_abs.invalidate_abs_etud_date(etudid, date)
# s'assure que les justificatifs ne sont pas "absents"
for date in dates:
cursor.execute(
2023-08-23 01:42:03 +02:00
"""UPDATE absences
SET estabs=FALSE
WHERE etudid=%(etudid)s
AND jour=%(date)s
AND moduleimpl_id=%(moduleimpl_id)s
2021-09-13 22:10:01 +02:00
""",
vars(),
)
if dates:
date0 = dates[0]
else:
date0 = None
if len(dates) > 1:
date1 = dates[1]
else:
date1 = None
logdb(
cnx,
"AnnuleAbsencesDatesNoJust",
etudid=etudid,
msg="%s - %s - %s" % (date0, date1, moduleimpl_id),
)
cnx.commit()
def EtatAbsences():
2020-09-26 16:19:37 +02:00
"""Etat des absences: choix du groupe"""
# crude portage from 1999 DTML
H = [
html_sco_header.sco_header(page_title="Etat des absences"),
2021-08-24 09:22:14 +02:00
"""<h2>État des absences pour un groupe</h2>
2020-09-26 16:19:37 +02:00
<form action="EtatAbsencesGr" method="GET">""",
formChoixSemestreGroupe(),
2020-09-26 16:19:37 +02:00
"""<input type="submit" name="" value=" OK " width=100>
<table><tr><td>Date de début (j/m/a) : </td><td>
<input type="text" name="debut" size="10" value="01/09/%s" class="datepicker"/>
</td></tr><tr><td>Date de fin : </td><td>
<input type="text" name="fin" size="10" value="%s" class="datepicker"/>
</td></tr></table>
</form>"""
% (scu.annee_scolaire(), datetime.datetime.now().strftime("%d/%m/%Y")),
html_sco_header.sco_footer(),
2020-09-26 16:19:37 +02:00
]
return "\n".join(H)
def formChoixSemestreGroupe(all=False):
2020-09-26 16:19:37 +02:00
"""partie de formulaire pour le choix d'un semestre et d'un groupe.
Si all, donne tous les semestres (même ceux verrouillés).
"""
# XXX assez primitif, à ameliorer TOTALEMENT OBSOLETE !
if all:
2021-08-19 10:28:35 +02:00
sems = sco_formsemestre.do_formsemestre_list()
2020-09-26 16:19:37 +02:00
else:
2021-08-19 10:28:35 +02:00
sems = sco_formsemestre.do_formsemestre_list(args={"etat": "1"})
2020-09-26 16:19:37 +02:00
if not sems:
raise ScoValueError("aucun semestre !")
H = ['<select name="group_ids">']
for sem in sems:
2021-08-19 10:28:35 +02:00
for p in sco_groups.get_partitions_list(sem["formsemestre_id"]):
for group in sco_groups.get_partition_groups(p):
2020-09-26 16:19:37 +02:00
if group["group_name"]:
group_tit = "%s %s" % (p["partition_name"], group["group_name"])
else:
group_tit = "tous"
H.append(
'<option value="%s">%s: %s</option>'
% (group["group_id"], sem["titremois"], group_tit)
)
H.append("</select>")
return "\n".join(H)
def _convert_sco_year(year) -> int:
try:
year = int(year)
if year > 1900 and year < 2999:
return year
2023-08-23 01:42:03 +02:00
except ValueError:
raise ScoValueError("année scolaire invalide")
def CalAbs(etudid, sco_year=None):
"""Calendrier des absences d'un etudiant"""
2020-09-26 16:19:37 +02:00
# crude portage from 1999 DTML
2021-08-22 13:24:36 +02:00
etud = sco_etud.get_etud_info(filled=True, etudid=etudid)[0]
2020-09-26 16:19:37 +02:00
etudid = etud["etudid"]
if sco_year:
annee_scolaire = _convert_sco_year(sco_year)
else:
annee_scolaire = scu.annee_scolaire()
datedebut = str(annee_scolaire) + "-08-01"
datefin = str(annee_scolaire + 1) + "-07-31"
annee_courante = scu.annee_scolaire()
2021-07-19 19:53:01 +02:00
nbabs = sco_abs.count_abs(etudid=etudid, debut=datedebut, fin=datefin)
nbabsjust = sco_abs.count_abs_just(etudid=etudid, debut=datedebut, fin=datefin)
2020-09-26 16:19:37 +02:00
events = []
2021-07-19 19:53:01 +02:00
for a in sco_abs.list_abs_just(etudid=etudid, datedebut=datedebut):
2020-09-26 16:19:37 +02:00
events.append(
(str(a["jour"]), "a", "#F8B7B0", "", a["matin"], a["description"])
)
2021-07-19 19:53:01 +02:00
for a in sco_abs.list_abs_non_just(etudid=etudid, datedebut=datedebut):
2020-09-26 16:19:37 +02:00
events.append(
(str(a["jour"]), "A", "#EE0000", "", a["matin"], a["description"])
)
2021-07-19 19:53:01 +02:00
justifs_noabs = sco_abs.list_abs_justifs(
etudid=etudid, datedebut=datedebut, only_no_abs=True
2020-09-26 16:19:37 +02:00
)
for a in justifs_noabs:
events.append(
(str(a["jour"]), "X", "#8EA2C6", "", a["matin"], a["description"])
)
CalHTML = sco_abs.YearTable(annee_scolaire, events=events, halfday=1)
2020-09-26 16:19:37 +02:00
#
H = [
2021-06-13 19:12:20 +02:00
html_sco_header.sco_header(
2020-09-26 16:19:37 +02:00
page_title="Calendrier des absences de %(nomprenom)s" % etud,
cssstyles=["css/calabs.css"],
),
"""<table><tr><td><h2>Absences de %(nomprenom)s (%(inscription)s)</h2><p>"""
% etud,
"""<b><font color="#EE0000">A : absence NON justifiée</font><br>
<font color="#F8B7B0">a : absence justifiée</font><br>
<font color="#8EA2C6">X : justification sans absence</font><br>
2023-08-23 01:42:03 +02:00
%d absences sur l'année, dont %d justifiées (soit %d non justifiées)</b>
<em>(%d justificatifs inutilisés)</em>
2020-09-26 16:19:37 +02:00
</p>
"""
% (nbabs, nbabsjust, nbabs - nbabsjust, len(justifs_noabs)),
"""</td>
<td><a href="%s">%s</a></td>
2020-09-26 16:19:37 +02:00
</tr>
</table>"""
% (
url_for("scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etudid),
2020-09-26 16:19:37 +02:00
sco_photos.etud_photo_html(
2020-12-28 22:59:59 +01:00
etudid=etudid,
title="fiche de " + etud["nomprenom"],
2020-09-26 16:19:37 +02:00
),
),
CalHTML,
"""<form method="GET" action="CalAbs" name="f">""",
"""<input type="hidden" name="etudid" value="%s"/>""" % etudid,
"""Année scolaire %s-%s""" % (annee_scolaire, annee_scolaire + 1),
2023-08-23 01:42:03 +02:00
"""&nbsp;&nbsp;Changer année:
<select name="sco_year" onchange="document.f.submit()">""",
2020-09-26 16:19:37 +02:00
]
for y in range(annee_courante, min(annee_courante - 6, annee_scolaire - 6), -1):
2020-09-26 16:19:37 +02:00
H.append("""<option value="%s" """ % y)
if y == annee_scolaire:
2020-09-26 16:19:37 +02:00
H.append("selected")
H.append(""">%s</option>""" % y)
H.append("""</select></form>""")
H.append(html_sco_header.sco_footer())
2020-09-26 16:19:37 +02:00
return "\n".join(H)
def ListeAbsEtud(
2021-12-21 23:05:49 +01:00
etudid=None,
code_nip=None,
2021-08-01 16:13:47 +02:00
with_evals=True,
2020-09-26 16:19:37 +02:00
format="html",
2021-08-01 16:13:47 +02:00
absjust_only=0,
sco_year=None,
2020-09-26 16:19:37 +02:00
):
"""Liste des absences d'un étudiant sur l'année en cours
En format 'html': page avec deux tableaux (non justifiées et justifiées).
2021-05-03 11:56:41 +02:00
En format json, xml, xls ou pdf: l'un ou l'autre des table, suivant absjust_only.
2020-09-26 16:19:37 +02:00
En format 'text': texte avec liste d'absences (pour mails).
2021-08-01 16:13:47 +02:00
Args:
etudid:
with_evals: indique les evaluations aux dates d'absences
absjust_only: si vrai, renvoie table absences justifiées
2023-08-23 01:42:03 +02:00
sco_year: année scolaire à utiliser.
Si non spécifier, utilie l'année en cours. e.g. "2005"
2020-09-26 16:19:37 +02:00
"""
2021-11-03 14:12:27 +01:00
# si absjust_only, table absjust seule (export xls ou pdf)
2022-08-06 22:31:41 +02:00
absjust_only = scu.to_bool(absjust_only)
if sco_year:
annee_scolaire = _convert_sco_year(sco_year)
else:
annee_scolaire = scu.annee_scolaire()
datedebut = f"{annee_scolaire}-{scu.MONTH_DEBUT_ANNEE_SCOLAIRE+1}-01"
2021-12-21 23:05:49 +01:00
etudid = etudid or False
etuds = sco_etud.get_etud_info(etudid=etudid, code_nip=code_nip, filled=True)
if not etuds:
log(f"ListeAbsEtud: no etuds with etudid={etudid} or nip={code_nip}")
abort(404)
etud = etuds[0]
etudid = etud["etudid"]
2020-09-26 16:19:37 +02:00
# Liste des absences et titres colonnes tables:
2021-09-24 12:10:53 +02:00
titles, columns_ids, absnonjust, absjust = _tables_abs_etud(
etudid, datedebut, with_evals=with_evals, format=format
2020-09-26 16:19:37 +02:00
)
2021-09-24 12:10:53 +02:00
if request.base_url:
base_url_nj = "%s?etudid=%s&absjust_only=0" % (request.base_url, etudid)
base_url_j = "%s?etudid=%s&absjust_only=1" % (request.base_url, etudid)
2020-09-26 16:19:37 +02:00
else:
base_url_nj = base_url_j = ""
tab_absnonjust = GenTable(
titles=titles,
columns_ids=columns_ids,
rows=absnonjust,
html_class="table_leftalign",
table_id="tab_absnonjust",
base_url=base_url_nj,
filename="abs_" + scu.make_filename(etud["nomprenom"]),
2020-09-26 16:19:37 +02:00
caption="Absences non justifiées de %(nomprenom)s" % etud,
preferences=sco_preferences.SemPreferences(),
2020-09-26 16:19:37 +02:00
)
tab_absjust = GenTable(
titles=titles,
columns_ids=columns_ids,
rows=absjust,
html_class="table_leftalign",
table_id="tab_absjust",
base_url=base_url_j,
filename="absjust_" + scu.make_filename(etud["nomprenom"]),
2020-09-26 16:19:37 +02:00
caption="Absences justifiées de %(nomprenom)s" % etud,
preferences=sco_preferences.SemPreferences(),
2020-09-26 16:19:37 +02:00
)
# Formats non HTML et demande d'une seule table:
if format != "html" and format != "text":
if absjust_only == 1:
return tab_absjust.make_page(format=format)
2020-09-26 16:19:37 +02:00
else:
return tab_absnonjust.make_page(format=format)
2020-09-26 16:19:37 +02:00
if format == "html":
# Mise en forme HTML:
H = []
H.append(
html_sco_header.sco_header(page_title="Absences de %s" % etud["nomprenom"])
2020-09-26 16:19:37 +02:00
)
H.append(
"""<h2>Absences de %s (à partir du %s)</h2>"""
% (etud["nomprenom"], ndb.DateISOtoDMY(datedebut))
2020-09-26 16:19:37 +02:00
)
if len(absnonjust):
H.append("<h3>%d absences non justifiées:</h3>" % len(absnonjust))
H.append(tab_absnonjust.html())
else:
H.append("""<h3>Pas d'absences non justifiées</h3>""")
if len(absjust):
H.append("""<h3>%d absences justifiées:</h3>""" % len(absjust))
H.append(tab_absjust.html())
else:
H.append("""<h3>Pas d'absences justifiées</h3>""")
return "\n".join(H) + html_sco_header.sco_footer()
2020-09-26 16:19:37 +02:00
elif format == "text":
T = []
if not len(absnonjust) and not len(absjust):
T.append(
"""--- Pas d'absences enregistrées depuis le %s"""
% ndb.DateISOtoDMY(datedebut)
2020-09-26 16:19:37 +02:00
)
else:
T.append(
"""--- Absences enregistrées à partir du %s:"""
% ndb.DateISOtoDMY(datedebut)
2020-09-26 16:19:37 +02:00
)
T.append("\n")
if len(absnonjust):
T.append("* %d absences non justifiées:" % len(absnonjust))
T.append(tab_absnonjust.text())
if len(absjust):
T.append("* %d absences justifiées:" % len(absjust))
T.append(tab_absjust.text())
return "\n".join(T)
else:
raise ValueError("Invalid format !")
2021-09-24 12:10:53 +02:00
def _tables_abs_etud(
etudid,
datedebut,
with_evals=True,
format="html",
absjust_only=0,
):
2021-08-16 22:41:09 +02:00
"""Tables des absences justifiees et non justifiees d'un étudiant
sur l'année en cours
"""
2021-07-19 19:53:01 +02:00
absjust = sco_abs.list_abs_just(etudid=etudid, datedebut=datedebut)
absnonjust = sco_abs.list_abs_non_just(etudid=etudid, datedebut=datedebut)
# examens ces jours là ?
if with_evals:
cnx = ndb.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
for a in absnonjust + absjust:
cursor.execute(
"""SELECT eval.*
2023-08-23 01:42:03 +02:00
FROM notes_evaluation eval,
notes_moduleimpl_inscription mi,
notes_moduleimpl m
2023-08-25 17:58:57 +02:00
WHERE DATE(eval.date_debut) = %(date_debut)s
and eval.moduleimpl_id = m.id
2023-08-23 01:42:03 +02:00
and mi.moduleimpl_id = m.id
and mi.etudid = %(etudid)s
""",
2023-08-25 17:58:57 +02:00
{"date_debut": a["jour"], "etudid": etudid},
)
a["evals"] = cursor.dictfetchall()
cursor.execute(
"""SELECT mi.moduleimpl_id
FROM absences abs, notes_moduleimpl_inscription mi, notes_moduleimpl m
2021-09-24 00:11:56 +02:00
WHERE abs.matin = %(matin)s
and abs.jour = %(jour)s
and abs.etudid = %(etudid)s
and abs.moduleimpl_id = mi.moduleimpl_id
and mi.moduleimpl_id = m.id
and mi.etudid = %(etudid)s
""",
{
"matin": bool(a["matin"]),
"jour": a["jour"].strftime("%Y-%m-%d"),
"etudid": etudid,
},
)
a["absent"] = cursor.dictfetchall()
def matin(x):
if x:
return "matin"
else:
return "après-midi"
def descr_exams(a):
2021-07-09 17:47:06 +02:00
if "evals" not in a:
return ""
ex = []
for ev in a["evals"]:
mod = sco_moduleimpl.moduleimpl_withmodule_list(
2021-08-20 01:09:55 +02:00
moduleimpl_id=ev["moduleimpl_id"]
)[0]
if format == "html":
ex.append(
2023-08-23 01:42:03 +02:00
f"""<a title="{mod['module']['titre']}" href="{
url_for('notes.moduleimpl_status',
scodoc_dept=g.scodoc_dept, moduleimpl_id=mod["moduleimpl_id"])
}">{mod["module"]["code"] or "(module sans code)"}</a>"""
)
else:
ex.append(mod["module"]["code"] or "(module sans code)")
if ex:
return ", ".join(ex)
return ""
def descr_abs(a):
ex = []
for ev in a.get("absent", []):
mod = sco_moduleimpl.moduleimpl_withmodule_list(
2021-08-20 01:09:55 +02:00
moduleimpl_id=ev["moduleimpl_id"]
)[0]
if format == "html":
ex.append(
f"""<a title="{mod['module']['titre']}"
2023-08-23 01:42:03 +02:00
href="{url_for('notes.moduleimpl_status',
2021-09-24 00:11:56 +02:00
scodoc_dept=g.scodoc_dept, moduleimpl_id=mod["moduleimpl_id"])}
">{mod["module"]["code"] or '(module sans code)'}</a>"""
)
else:
ex.append(mod["module"]["code"] or "(module sans code)")
if ex:
return ", ".join(ex)
return ""
# ajoute date formatée et évaluations
for L in (absnonjust, absjust):
for a in L:
if with_evals:
a["exams"] = descr_exams(a)
a["datedmy"] = a["jour"].strftime("%d/%m/%Y")
a["ampm"] = int(a["matin"])
a["matin"] = matin(a["matin"])
index = a["description"].find(")")
if index != -1:
a["motif"] = a["description"][1:index]
else:
a["motif"] = ""
a["description"] = descr_abs(a) or ""
# ajoute lien pour justifier
if format == "html":
for a in absnonjust:
a["justlink"] = "<em>justifier</em>"
a[
"_justlink_target"
] = "doJustifAbsence?etudid=%s&datedebut=%s&datefin=%s&demijournee=%s" % (
etudid,
a["datedmy"],
a["datedmy"],
a["ampm"],
)
#
titles = {
"datedmy": "Date",
"matin": "",
"exams": "Examens ce jour",
"justlink": "",
"description": "Modules",
"motif": "Motif",
}
columns_ids = ["datedmy", "matin"]
if format in ("json", "xml"):
columns_ids += ["jour", "ampm"]
if with_evals:
columns_ids.append("exams")
columns_ids.append("description")
columns_ids.append("motif")
if format == "html":
columns_ids.append("justlink")
return titles, columns_ids, absnonjust, absjust