choix groupe sur formulaire saisie absences hebdo

This commit is contained in:
Emmanuel Viennet 2021-02-19 00:13:47 +01:00
parent 8711d88352
commit 264fd60336
3 changed files with 106 additions and 60 deletions

View File

@ -67,6 +67,7 @@ from sco_permissions import ScoAbsAddBillet, ScoAbsChange, ScoView
from sco_exceptions import ScoValueError, ScoInvalidDateError from sco_exceptions import ScoValueError, ScoInvalidDateError
from TrivialFormulator import TrivialFormulator, TF from TrivialFormulator import TrivialFormulator, TF
from gen_tables import GenTable from gen_tables import GenTable
import html_sco_header
import scolars import scolars
import sco_formsemestre import sco_formsemestre
import sco_moduleimpl import sco_moduleimpl
@ -78,6 +79,8 @@ import sco_compute_moy
import sco_abs import sco_abs
from sco_abs import ddmmyyyy from sco_abs import ddmmyyyy
CSSSTYLES = html_sco_header.BOOTSTRAP_MULTISELECT_CSS
def _toboolean(x): def _toboolean(x):
"convert a value to boolean (ensure backward compat with OLD intranet code)" "convert a value to boolean (ensure backward compat with OLD intranet code)"
@ -343,11 +346,17 @@ class ZAbsences(
) )
cnx.commit() cnx.commit()
security.declareProtected(ScoView, "CountAbs") def ListAbsInRange(
self, etudid, debut, fin, matin=None, moduleimpl_id=None, cursor=None
):
"""Liste des absences entre deux dates.
def CountAbs(self, etudid, debut, fin, matin=None, moduleimpl_id=None): Args:
"""CountAbs etudid
matin= 1 ou 0. debut string iso date ("2020-03-12")
end string iso date ("2020-03-12")
matin None, True, False
moduleimpl_id
""" """
if matin != None: if matin != None:
matin = _toboolean(matin) matin = _toboolean(matin)
@ -358,10 +367,11 @@ class ZAbsences(
modul = " AND A.MODULEIMPL_ID = %(moduleimpl_id)s " modul = " AND A.MODULEIMPL_ID = %(moduleimpl_id)s "
else: else:
modul = "" modul = ""
if not cursor:
cnx = self.GetDBConnexion() cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor) cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
cursor.execute( cursor.execute(
"""SELECT COUNT(*) AS NbAbs FROM ( """
SELECT DISTINCT A.JOUR, A.MATIN SELECT DISTINCT A.JOUR, A.MATIN
FROM ABSENCES A FROM ABSENCES A
WHERE A.ETUDID = %(etudid)s WHERE A.ETUDID = %(etudid)s
@ -370,13 +380,27 @@ class ZAbsences(
+ modul + modul
+ """ + """
AND A.JOUR BETWEEN %(debut)s AND %(fin)s AND A.JOUR BETWEEN %(debut)s AND %(fin)s
) AS tmp
""", """,
vars(), vars(),
) )
res = cursor.fetchone()[0] res = cursor.dictfetchall()
return res return res
security.declareProtected(ScoView, "CountAbs")
def CountAbs(self, etudid, debut, fin, matin=None, moduleimpl_id=None):
"""CountAbs
matin= 1 ou 0.
Returns:
An integer.
"""
return len(
self.ListAbsInRange(
etudid, debut, fin, matin=matin, moduleimpl_id=moduleimpl_id
)
)
security.declareProtected(ScoView, "CountAbsJust") security.declareProtected(ScoView, "CountAbsJust")
def CountAbsJust(self, etudid, debut, fin, matin=None, moduleimpl_id=None): def CountAbsJust(self, etudid, debut, fin, matin=None, moduleimpl_id=None):
@ -750,20 +774,41 @@ class ZAbsences(
self.sco_header( self.sco_header(
page_title="Saisie hebdomadaire des absences", page_title="Saisie hebdomadaire des absences",
init_qtip=True, init_qtip=True,
javascripts=["js/etud_info.js", "js/abs_ajax.js"], javascripts=html_sco_header.BOOTSTRAP_MULTISELECT_JS
+ [
"js/etud_info.js",
"js/abs_ajax.js",
"js/groups_view.js",
],
cssstyles=CSSSTYLES,
no_side_bar=1, no_side_bar=1,
REQUEST=REQUEST, REQUEST=REQUEST,
), ),
"""<table border="0" cellspacing="16"><tr><td> """<table border="0" cellspacing="16"><tr><td>
<h2>Saisie des absences %s %s, <h2>Saisie des absences %s %s,
<span class="fontred">semaine du lundi %s</span></h2> <span class="fontred">semaine du lundi %s</span></h2>
<div>
<p><a href="index_html">Annuler</a></p> <form id="group_selector" method="get">
<input type="hidden" name="formsemestre_id" id="formsemestre_id" value="%s"/>
<p> <input type="hidden" name="datelundi" id="datelundi" value="%s"/>
<form action="doSignaleAbsenceGrHebdo" method="post" action="%s"> <input type="hidden" name="destination" id="destination" value="%s"/>
<input type="hidden" name="moduleimpl_id" id="moduleimpl_id_o" value="%s"/>
Groupes: %s
</form>
<form>
""" """
% (gr_tit, sem["titre_num"], datelundi, REQUEST.URL0), % (
gr_tit,
sem["titre_num"],
datelundi,
groups_infos.formsemestre_id,
datelundi,
destination,
moduleimpl_id or "",
sco_groups_view.menu_groups_choice(
self, groups_infos, submit_on_change=True
),
),
] ]
# #
modimpls_list = [] modimpls_list = []
@ -802,12 +847,12 @@ class ZAbsences(
sel = "selected" # aucun module specifie sel = "selected" # aucun module specifie
H.append( H.append(
""" """Module concerné:
Module concerné par ces absences (optionnel): <select id="moduleimpl_id" name="moduleimpl_id" onchange="document.location='%(url)s&amp;moduleimpl_id='+document.getElementById('moduleimpl_id').value"> <select id="moduleimpl_id" name="moduleimpl_id" onchange="change_moduleimpl('%(url)s')">
<option value="" %(sel)s>non spécifié</option> <option value="" %(sel)s>non spécifié</option>
%(menu_module)s %(menu_module)s
</select> </select>
</p>""" </div>"""
% {"menu_module": menu_module, "url": base_url, "sel": sel} % {"menu_module": menu_module, "url": base_url, "sel": sel}
) )
@ -831,7 +876,6 @@ class ZAbsences(
REQUEST=None, REQUEST=None,
): ):
"""Saisie des absences sur une journée sur un semestre (ou intervalle de dates) entier""" """Saisie des absences sur une journée sur un semestre (ou intervalle de dates) entier"""
# log('SignaleAbsenceGrSemestre: moduleimpl_id=%s destination=%s' % (moduleimpl_id, destination))
groups_infos = sco_groups_view.DisplayedGroupsInfos( groups_infos = sco_groups_view.DisplayedGroupsInfos(
self, group_ids, REQUEST=REQUEST self, group_ids, REQUEST=REQUEST
) )
@ -1011,7 +1055,7 @@ class ZAbsences(
Args: Args:
etuds: liste des étudiants etuds: liste des étudiants
dates: liste de dates iso, par exemple: [ '2020-12-24', ... ] dates: liste ordonnée de dates iso, par exemple: [ '2020-12-24', ... ]
moduleimpl_id: optionnel, module concerné. moduleimpl_id: optionnel, module concerné.
""" """
H = [ H = [
@ -1048,6 +1092,8 @@ class ZAbsences(
] ]
# Dates # Dates
odates = [datetime.date(*[int(x) for x in d.split("-")]) for d in dates] odates = [datetime.date(*[int(x) for x in d.split("-")]) for d in dates]
begin = dates[0]
end = dates[-1]
# Titres colonnes # Titres colonnes
noms_jours = [] # eg [ "Lundi", "mardi", "Samedi", ... ] noms_jours = [] # eg [ "Lundi", "mardi", "Samedi", ... ]
jn = sco_abs.day_names(self) jn = sco_abs.day_names(self)
@ -1076,6 +1122,8 @@ class ZAbsences(
'<tr><td><span class="redboldtext">Aucun étudiant inscrit !</span></td></tr>' '<tr><td><span class="redboldtext">Aucun étudiant inscrit !</span></td></tr>'
) )
i = 1 i = 1
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
for etud in etuds: for etud in etuds:
i += 1 i += 1
etudid = etud["etudid"] etudid = etud["etudid"]
@ -1101,17 +1149,20 @@ class ZAbsences(
'<tr class="%s"><td><b class="etudinfo" id="%s"><a class="discretelink" href="ficheEtud?etudid=%s" target="new">%s</a></b>%s</td>' '<tr class="%s"><td><b class="etudinfo" id="%s"><a class="discretelink" href="ficheEtud?etudid=%s" target="new">%s</a></b>%s</td>'
% (tr_class, etudid, etudid, etud["nomprenom"], capstr) % (tr_class, etudid, etudid, etud["nomprenom"], capstr)
) )
for date in dates: etud_abs = self.ListAbsInRange(
etudid, begin, end, moduleimpl_id=moduleimpl_id, cursor=cursor
)
for d in odates:
date = d.strftime("%Y-%m-%d")
# matin # matin
if self.CountAbs(etudid, date, date, True, moduleimpl_id=moduleimpl_id): is_abs = {"jour": d, "matin": True} in etud_abs
if is_abs:
checked = "checked" checked = "checked"
else: else:
checked = "" checked = ""
# bulle lors du passage souris # bulle lors du passage souris
coljour = sco_abs.DAYNAMES[ coljour = sco_abs.DAYNAMES[(calendar.weekday(d.year, d.month, d.day))]
(calendar.weekday(int(date[:4]), int(date[5:7]), int(date[8:]))) datecol = coljour + " " + d.strftime("%d/%m/%Y")
]
datecol = coljour + " " + date[8:] + "/" + date[5:7] + "/" + date[:4]
bulle_am = '"' + etud["nomprenom"] + " - " + datecol + ' (matin)"' bulle_am = '"' + etud["nomprenom"] + " - " + datecol + ' (matin)"'
bulle_pm = '"' + etud["nomprenom"] + " - " + datecol + ' (ap.midi)"' bulle_pm = '"' + etud["nomprenom"] + " - " + datecol + ' (ap.midi)"'
@ -1127,9 +1178,8 @@ class ZAbsences(
) )
) )
# après-midi # après-midi
if self.CountAbs( is_abs = {"jour": d, "matin": False} in etud_abs
etudid, date, date, False, moduleimpl_id=moduleimpl_id if is_abs:
):
checked = "checked" checked = "checked"
else: else:
checked = "" checked = ""

View File

@ -534,14 +534,6 @@ class GenTable:
) )
] ]
pdf_style_list += self.pdf_table_style pdf_style_list += self.pdf_table_style
# log('len(Pt)=%s' % len(Pt))
# log( 'line lens=%s' % [ len(x) for x in Pt ] )
# log( 'style=\n%s' % pdf_style_list)
# col_min = min([x[1][0] for x in pdf_style_list])
# col_max = max([x[2][0] for x in pdf_style_list])
# lin_min = min([x[1][1] for x in pdf_style_list])
# lin_max = max([x[2][1] for x in pdf_style_list])
# log('col_min=%s col_max=%s lin_min=%s lin_max=%s' % (col_min, col_max, lin_min, lin_max))
T = Table(Pt, repeatRows=1, colWidths=self.pdf_col_widths, style=pdf_style_list) T = Table(Pt, repeatRows=1, colWidths=self.pdf_col_widths, style=pdf_style_list)
objects = [] objects = []

View File

@ -30,7 +30,7 @@ function ajaxFunction(mod, etudid, dat){
} }
ajaxRequest.open("POST", "doSignaleAbsenceGrSemestre", true); ajaxRequest.open("POST", "doSignaleAbsenceGrSemestre", true);
ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
oForm = document.forms[0]; oForm = document.forms[1];
oSelectOne = oForm.elements["moduleimpl_id"]; oSelectOne = oForm.elements["moduleimpl_id"];
index = oSelectOne.selectedIndex; index = oSelectOne.selectedIndex;
modul_id = oSelectOne.options[index].value; modul_id = oSelectOne.options[index].value;
@ -42,3 +42,7 @@ function ajaxFunction(mod, etudid, dat){
} }
} }
// -----
function change_moduleimpl(url) {
document.location = url + '&amp;moduleimpl_id=' + document.getElementById('moduleimpl_id').value;
}