# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
# Copyright (c) 1999 - 2020 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
#
##############################################################################
"""Pages HTML gestion absences
(la plupart portées du DTML)
"""
from stripogram import html2text, html2safehtml
from gen_tables import GenTable
from notesdb import *
from sco_utils import *
from notes_log import log
import sco_groups
import sco_find_etud
import sco_formsemestre
import sco_photos
import ZAbsences
def doSignaleAbsence(
context,
datedebut,
datefin,
moduleimpl_id=None,
demijournee=2,
estjust=False,
description=None,
REQUEST=None,
): # etudid implied
"""Signalement d'une absence"""
etud = context.getEtudInfo(filled=1, REQUEST=REQUEST)[0]
etudid = etud["etudid"]
description_abs = description
dates = context.DateRangeISO(datedebut, datefin)
nbadded = 0
for jour in dates:
if demijournee == "2":
context._AddAbsence(
etudid, jour, False, estjust, REQUEST, description_abs, moduleimpl_id
)
context._AddAbsence(
etudid, jour, True, estjust, REQUEST, description_abs, moduleimpl_id
)
nbadded += 2
else:
matin = int(demijournee)
context._AddAbsence(
etudid, jour, matin, estjust, REQUEST, description_abs, moduleimpl_id
)
nbadded += 1
#
if estjust:
J = ""
else:
J = "NON "
M = ""
if moduleimpl_id and moduleimpl_id != "NULL":
mod = context.Notes.do_moduleimpl_list(moduleimpl_id=moduleimpl_id)[0]
formsemestre_id = mod["formsemestre_id"]
nt = context.Notes._getNotesCache().get_NotesTable(
context.Notes, formsemestre_id
)
ues = nt.get_ues(etudid=etudid)
for ue in ues:
modimpls = nt.get_modimpls(ue_id=ue["ue_id"])
for modimpl in modimpls:
if modimpl["moduleimpl_id"] == moduleimpl_id:
M = "dans le module %s" % modimpl["module"]["code"]
H = [
context.sco_header(
REQUEST, page_title="Signalement d'une absence pour %(nomprenom)s" % etud
),
"""
"""
% etud
)
H.append(sco_find_etud.form_search_etud(context, REQUEST))
H.append(context.sco_footer(REQUEST))
return "\n".join(H)
def EtatAbsences(context, REQUEST=None):
"""Etat des absences: choix du groupe"""
# crude portage from 1999 DTML
H = [
context.sco_header(REQUEST, page_title="Etat des absences"),
"""
Etat des absences pour un groupe
"""
% (AnneeScolaire(REQUEST), datetime.datetime.now().strftime("%d/%m/%Y")),
context.sco_footer(REQUEST),
]
return "\n".join(H)
def formChoixSemestreGroupe(context, all=False):
"""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:
sems = sco_formsemestre.do_formsemestre_list(context)
else:
sems = sco_formsemestre.do_formsemestre_list(context, args={"etat": "1"})
if not sems:
raise ScoValueError("aucun semestre !")
H = ['")
return "\n".join(H)
def CalAbs(context, REQUEST=None): # etud implied
"""Calendrier des absences d un etudiant"""
# crude portage from 1999 DTML
etud = context.getEtudInfo(filled=1, REQUEST=REQUEST)[0]
etudid = etud["etudid"]
anneescolaire = int(AnneeScolaire(REQUEST))
datedebut = str(anneescolaire) + "-08-31"
datefin = str(anneescolaire + 1) + "-07-31"
nbabs = context.CountAbs(etudid=etudid, debut=datedebut, fin=datefin)
nbabsjust = context.CountAbsJust(etudid=etudid, debut=datedebut, fin=datefin)
events = []
for a in context.ListeAbsJust(etudid=etudid, datedebut=datedebut):
events.append(
(str(a["jour"]), "a", "#F8B7B0", "", a["matin"], a["description"])
)
for a in context.ListeAbsNonJust(etudid=etudid, datedebut=datedebut):
events.append(
(str(a["jour"]), "A", "#EE0000", "", a["matin"], a["description"])
)
justifs_noabs = context.ListeJustifs(
etudid=etudid, datedebut=datedebut, only_no_abs=True
)
for a in justifs_noabs:
events.append(
(str(a["jour"]), "X", "#8EA2C6", "", a["matin"], a["description"])
)
CalHTML = ZAbsences.YearTable(context, anneescolaire, events=events, halfday=1)
#
H = [
context.sco_header(
REQUEST,
page_title="Calendrier des absences de %(nomprenom)s" % etud,
cssstyles=["css/calabs.css"],
),
"""
Absences de %(nomprenom)s (%(inscription)s)
"""
% etud,
"""A : absence NON justifiée
a : absence justifiée
X : justification sans absence
%d absences sur l'année, dont %d justifiées (soit %d non justifiées)(%d justificatifs inutilisés)
"""
% (
context.ScoURL(),
etudid,
sco_photos.etud_photo_html(
context,
etudid=etudid,
title="fiche de " + etud["nomprenom"],
REQUEST=REQUEST,
),
),
CalHTML,
"""""")
H.append(context.sco_footer(REQUEST))
return "\n".join(H)
def ListeAbsEtud(
context,
etudid,
with_evals=True, # indique les evaluations aux dates d'absences
format="html",
absjust_only=0, # si vrai, renvoie table absences justifiées
REQUEST=None,
):
"""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).
En format xls ou pdf: l'un ou l'autre des table, suivant absjust_only.
En format 'text': texte avec liste d'absences (pour mails).
"""
absjust_only = int(absjust_only) # si vrai, table absjust seule (export xls ou pdf)
datedebut = "%s-08-31" % AnneeScolaire(REQUEST)
etud = context.getEtudInfo(etudid=etudid, filled=True)[0]
# Liste des absences et titres colonnes tables:
titles, columns_ids, absnonjust, absjust = context.Absences._TablesAbsEtud(
etudid, datedebut, with_evals=with_evals, format=format
)
if REQUEST:
base_url_nj = "%s?etudid=%s&absjust_only=0" % (REQUEST.URL0, etudid)
base_url_j = "%s?etudid=%s&absjust_only=1" % (REQUEST.URL0, etudid)
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_" + make_filename(etud["nomprenom"]),
caption="Absences non justifiées de %(nomprenom)s" % etud,
preferences=context.get_preferences(),
)
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_" + make_filename(etud["nomprenom"]),
caption="Absences justifiées de %(nomprenom)s" % etud,
preferences=context.get_preferences(),
)
# Formats non HTML et demande d'une seule table:
if format != "html" and format != "text":
if absjust_only == 1:
return tab_absjust.make_page(context, format=format, REQUEST=REQUEST)
else:
return tab_absnonjust.make_page(context, format=format, REQUEST=REQUEST)
if format == "html":
# Mise en forme HTML:
H = []
H.append(
context.sco_header(REQUEST, page_title="Absences de %s" % etud["nomprenom"])
)
H.append(
"""
Absences de %s (à partir du %s)
"""
% (etud["nomprenom"], DateISOtoDMY(datedebut))
)
if len(absnonjust):
H.append("