itre form saisie + pylint

This commit is contained in:
viennet 2020-12-24 14:56:01 +01:00
parent 7efe8cd194
commit 2b5a470516

View File

@ -45,17 +45,19 @@ L'API de plus bas niveau est en gros:
"""
import urllib
import datetime
import jaxml
# ---------------
from sco_zope import *
# ---------------
from notesdb import *
import sco_utils as scu
import notesdb
from notes_log import log
from scolog import logdb
from sco_utils import *
# import notes_users
from sco_permissions import ScoAbsAddBillet, ScoAbsChange, ScoView
from sco_exceptions import ScoValueError, ScoInvalidDateError
from TrivialFormulator import TrivialFormulator, TF
from gen_tables import GenTable
import scolars
@ -201,7 +203,7 @@ class ddmmyyyy:
return self.prev(self.weekday)
def __cmp__(self, other):
"""return a negative integer if self < other,
"""return a negative integer if self < other,
zero if self == other, a positive integer if self > other"""
return int(self.time - other.time)
@ -356,7 +358,7 @@ class ZAbsences(
estjust = _toboolean(estjust)
matin = _toboolean(matin)
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
cursor.execute(
"insert into absences (etudid,jour,estabs,estjust,matin,description, moduleimpl_id) values (%(etudid)s, %(jour)s, TRUE, %(estjust)s, %(matin)s, %(description)s, %(moduleimpl_id)s )",
vars(),
@ -380,7 +382,7 @@ class ZAbsences(
raise ScoValueError("date justificatif trop loin dans le futur !")
matin = _toboolean(matin)
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
cursor.execute(
"insert into absences (etudid,jour,estabs,estjust,matin, description) values (%(etudid)s,%(jour)s, FALSE, TRUE, %(matin)s, %(description)s )",
vars(),
@ -402,7 +404,7 @@ class ZAbsences(
# unpublished
matin = _toboolean(matin)
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
req = "delete from absences where jour=%(jour)s and matin=%(matin)s and etudid=%(etudid)s and estabs"
if moduleimpl_id:
req += " and moduleimpl_id=%(moduleimpl_id)s"
@ -423,7 +425,7 @@ class ZAbsences(
# unpublished
matin = _toboolean(matin)
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
cursor.execute(
"delete from absences where jour=%(jour)s and matin=%(matin)s and etudid=%(etudid)s and ESTJUST AND NOT ESTABS",
vars(),
@ -450,7 +452,7 @@ class ZAbsences(
# """
# # unpublished
# cnx = self.GetDBConnexion()
# cursor = cnx.cursor(cursor_factory=ScoDocCursor)
# cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
# # supr les absences non justifiees
# cursor.execute("delete from absences where etudid=%(etudid)s and (not estjust) and moduleimpl_id=(moduleimpl_id)s and jour BETWEEN %(datedebut)s AND %(datefin)s",
# vars() )
@ -487,7 +489,7 @@ class ZAbsences(
self._AnnuleAbsence(etudid, jour, matin, moduleimpl_id, REQUEST)
return
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
# supr les absences non justifiees
for date in dates:
cursor.execute(
@ -534,7 +536,7 @@ class ZAbsences(
else:
modul = ""
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
cursor.execute(
"""SELECT COUNT(*) AS NbAbs FROM (
SELECT DISTINCT A.JOUR, A.MATIN
@ -565,7 +567,7 @@ class ZAbsences(
else:
modul = ""
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
cursor.execute(
"""SELECT COUNT(*) AS NbAbsJust FROM (
SELECT DISTINCT A.JOUR, A.MATIN
@ -588,7 +590,7 @@ class ZAbsences(
def _ListeAbsDate(self, etudid, beg_date, end_date):
# Liste des absences et justifs entre deux dates
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
cursor.execute(
"""SELECT jour, matin, estabs, estjust, description FROM ABSENCES A
WHERE A.ETUDID = %(etudid)s
@ -598,7 +600,6 @@ class ZAbsences(
vars(),
)
Abs = cursor.dictfetchall()
# log('ListeAbsDate: abs=%s' % Abs)
# remove duplicates
A = {} # { (jour, matin) : abs }
for a in Abs:
@ -625,7 +626,6 @@ class ZAbsences(
# sort
R = A.values()
R.sort(key=lambda x: (x["begin"]))
# log('R=%s' % R)
return R
security.declareProtected(ScoView, "ListeAbsJust")
@ -633,7 +633,7 @@ class ZAbsences(
def ListeAbsJust(self, etudid, datedebut):
"Liste des absences justifiees (par ordre chronologique)"
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
cursor.execute(
"""SELECT DISTINCT A.ETUDID, A.JOUR, A.MATIN FROM ABSENCES A, ABSENCES B
WHERE A.ETUDID = %(etudid)s
@ -654,7 +654,7 @@ class ZAbsences(
def ListeAbsNonJust(self, etudid, datedebut):
"Liste des absences NON justifiees (par ordre chronologique)"
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
cursor.execute(
"""SELECT ETUDID, JOUR, MATIN FROM ABSENCES A
WHERE A.ETUDID = %(etudid)s
@ -680,7 +680,7 @@ class ZAbsences(
Si only_no_abs: seulement les justificatifs correspondant aux jours sans absences relevées.
"""
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
req = """SELECT DISTINCT ETUDID, JOUR, MATIN FROM ABSENCES A
WHERE A.ETUDID = %(etudid)s
AND A.ESTJUST
@ -704,7 +704,7 @@ class ZAbsences(
"Description associee a l'absence"
if not cursor:
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
a = a.copy()
# a['jour'] = a['jour'].date()
if a["matin"]: # devrait etre booleen... :-(
@ -732,7 +732,6 @@ class ZAbsences(
if desc:
return "(%s) %s" % (desc, module)
return desc
if module:
return module
return ""
@ -745,7 +744,7 @@ class ZAbsences(
is_just: idem
"""
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
req = """SELECT DISTINCT etudid, jour, matin FROM ABSENCES A
WHERE A.jour = %(date)s
"""
@ -769,7 +768,7 @@ class ZAbsences(
def ListeAbsNonJustJour(self, date, am=True, pm=True):
"Liste des absences non justifiees ce jour"
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
reqa = ""
if not am:
reqa += " AND NOT matin "
@ -849,7 +848,7 @@ class ZAbsences(
def CalSelectWeek(self, year=None, REQUEST=None):
"display calendar allowing week selection"
if not year:
year = AnneeScolaire(REQUEST)
year = scu.AnneeScolaire(REQUEST)
sems = sco_formsemestre.do_formsemestre_list(self)
if not sems:
js = ""
@ -886,10 +885,9 @@ class ZAbsences(
security.declareProtected(ScoView, "ListMondays")
def ListMondays(self, year=None, REQUEST=None):
"""return list of mondays (ISO dates), from september to june
"""
"""return list of mondays (ISO dates), from september to june"""
if not year:
year = AnneeScolaire(REQUEST)
year = scu.AnneeScolaire(REQUEST)
d = ddmmyyyy("1/9/%d" % year, work_saturday=self.is_work_saturday())
while d.weekday != 0:
d = d.next()
@ -934,7 +932,7 @@ class ZAbsences(
):
"Saisie hebdomadaire des absences"
if not moduleimpl_id:
moduleimp_id = None
moduleimpl_id = None
groups_infos = sco_groups_view.DisplayedGroupsInfos(
self, group_ids, REQUEST=REQUEST
@ -963,10 +961,10 @@ class ZAbsences(
)[0]
# calcule dates jours de cette semaine
datessem = [DateDMYtoISO(datelundi)]
for jour in self.day_names()[1:]:
# liste de dates iso "yyyy-mm-dd"
datessem = [notesdb.DateDMYtoISO(datelundi)]
for _ in self.day_names()[1:]:
datessem.append(self.NextISODay(datessem[-1]))
#
if groups_infos.tous_les_etuds_du_sem:
gr_tit = "en"
@ -1044,9 +1042,7 @@ class ZAbsences(
% {"menu_module": menu_module, "url": base_url, "sel": sel}
)
H += self._gen_form_saisie_groupe(
etuds, self.day_names(), datessem, destination, None, moduleimpl_id
)
H += self._gen_form_saisie_groupe(etuds, datessem, destination, moduleimpl_id)
H.append(self.sco_footer(REQUEST))
return "\n".join(H)
@ -1063,8 +1059,7 @@ class ZAbsences(
moduleimpl_id=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(
self, group_ids, REQUEST=REQUEST
@ -1083,15 +1078,12 @@ class ZAbsences(
]
if not moduleimpl_id:
moduleimp_id = None
base_url_noweeks = (
"SignaleAbsenceGrSemestre?datedebut=%s&amp;datefin=%s&amp;%s&amp;destination=%s"
% (
datedebut,
datefin,
groups_infos.groups_query_args,
urllib.quote(destination),
)
moduleimpl_id = None
base_url_noweeks = "SignaleAbsenceGrSemestre?datedebut=%s&amp;datefin=%s&amp;%s&amp;destination=%s" % (
datedebut,
datefin,
groups_infos.groups_query_args,
urllib.quote(destination),
)
base_url = (
base_url_noweeks + "&amp;nbweeks=%s" % nbweeks
@ -1139,7 +1131,6 @@ class ZAbsences(
if moduleimpl_id:
url_link_semaines += "&amp;moduleimpl_id=" + moduleimpl_id
#
colnames = [str(x) for x in dates]
dates = [x.ISO() for x in dates]
dayname = self.day_names()[jourdebut.weekday]
@ -1147,9 +1138,9 @@ class ZAbsences(
gr_tit = "en"
else:
if len(groups_infos.group_ids) > 1:
p = "des groupes"
p = "des groupes "
else:
p = "du groupe"
p = "du groupe "
gr_tit = (
p + '<span class="fontred">' + groups_infos.groups_titles + "</span>"
)
@ -1217,15 +1208,18 @@ class ZAbsences(
% {"menu_module": menu_module, "url": base_url, "sel": sel}
)
H += self._gen_form_saisie_groupe(
etuds, colnames, dates, destination, dayname, moduleimpl_id
)
H += self._gen_form_saisie_groupe(etuds, dates, destination, moduleimpl_id)
H.append(self.sco_footer(REQUEST))
return "\n".join(H)
def _gen_form_saisie_groupe(
self, etuds, colnames, dates, destination="", dayname="", moduleimpl_id=None
):
def _gen_form_saisie_groupe(self, etuds, dates, destination="", moduleimpl_id=None):
"""Formulaire saisie absences
Args:
etuds: liste des étudiants
dates: liste de dates iso, par exemple: [ '2020-12-24', ... ]
moduleimpl_id: optionnel, module concerné.
"""
H = [
"""
<script type="text/javascript">
@ -1252,25 +1246,29 @@ class ZAbsences(
"""
% len(etuds)
]
# Dates
odates = [datetime.date(*[int(x) for x in d.split("-")]) for d in dates]
# Titres colonnes
if dayname:
for jour in colnames:
H.append(
'<th colspan="2" width="100px" style="padding-left: 5px; padding-right: 5px;">'
+ dayname
+ "</th>"
)
H.append("</tr><tr><td>&nbsp;</td>")
for jour in colnames:
noms_jours = [] # eg [ "Lundi", "mardi", "Samedi", ... ]
jn = self.day_names()
for d in odates:
idx_jour = d.weekday()
noms_jours.append(jn[idx_jour])
for jour in noms_jours:
H.append(
'<th colspan="2" width="100px" style="padding-left: 5px; padding-right: 5px;">'
+ jour
+ "</th>"
)
H.append("</tr><tr><td>&nbsp;</td>")
H.append("<th>AM</th><th>PM</th>" * len(colnames))
for d in odates:
H.append(
'<th colspan="2" width="100px" style="padding-left: 5px; padding-right: 5px;">'
+ d.strftime("%d/%m/%Y")
+ "</th>"
)
H.append("</tr><tr><td>&nbsp;</td>")
H.append("<th>AM</th><th>PM</th>" * len(dates))
H.append("</tr>")
#
if not etuds:
@ -1373,14 +1371,13 @@ class ZAbsences(
absjust_only=0,
REQUEST=None,
):
"""Tables des absences justifiees et non justifiees d'un étudiant sur l'année en cours
"""
"""Tables des absences justifiees et non justifiees d'un étudiant sur l'année en cours"""
absjust = self.ListeAbsJust(etudid=etudid, datedebut=datedebut)
absnonjust = self.ListeAbsNonJust(etudid=etudid, datedebut=datedebut)
# examens ces jours là ?
if with_evals:
cnx = self.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ScoDocCursor)
cursor = cnx.cursor(cursor_factory=notesdb.ScoDocCursor)
for a in absnonjust + absjust:
cursor.execute(
"""select eval.*
@ -1499,10 +1496,9 @@ class ZAbsences(
format="html",
REQUEST=None,
):
"""Liste les absences de groupes
"""
datedebut = DateDMYtoISO(debut)
datefin = DateDMYtoISO(fin)
"""Liste les absences de groupes"""
datedebut = notesdb.DateDMYtoISO(debut)
datefin = notesdb.DateDMYtoISO(fin)
# Informations sur les groupes à afficher:
groups_infos = sco_groups_view.DisplayedGroupsInfos(
self, group_ids, REQUEST=REQUEST
@ -1603,7 +1599,7 @@ class ZAbsences(
base_url="%s&amp;formsemestre_id=%s&amp;debut=%s&amp;fin=%s"
% (groups_infos.base_url, formsemestre_id, debut, fin),
filename="etat_abs_"
+ make_filename(
+ scu.make_filename(
"%s de %s" % (groups_infos.groups_filename, sem["titreannee"])
),
caption=title,
@ -1632,26 +1628,20 @@ ou entrez une date pour visualiser les absents un jour donné&nbsp;:
def EtatAbsencesDate(
self, group_ids=[], date=None, REQUEST=None # list of groups to display
):
"""Etat des absences pour un groupe à une date donnée
"""
"""Etat des absences pour un groupe à une date donnée"""
# Informations sur les groupes à afficher:
groups_infos = sco_groups_view.DisplayedGroupsInfos(
self, group_ids, REQUEST=REQUEST
)
formsemestre_id = groups_infos.formsemestre_id
sem = sco_formsemestre.do_formsemestre_list(
self, {"formsemestre_id": formsemestre_id}
)[0]
H = [self.sco_header(page_title="Etat des absences", REQUEST=REQUEST)]
if date:
dateiso = DateDMYtoISO(date)
dateiso = notesdb.DateDMYtoISO(date)
nbetud = 0
t_nbabsjustam = 0
t_nbabsam = 0
t_nbabsjustpm = 0
t_nbabspm = 0
etuds = self.getEtudInfoGroupes(groups_infos.group_ids)
H.append("<h2>Etat des absences le %s</h2>" % date)
H.append("<h2>État des absences le %s</h2>" % date)
H.append(
"""<table border="0" cellspacing="4" cellpadding="0">
<tr><th>&nbsp;</th>
@ -1738,7 +1728,7 @@ ou entrez une date pour visualiser les absents un jour donné&nbsp;:
etudid=etudid, code_nip=code_nip, REQUEST=REQUEST, filled=True
)
if not etuds:
return log_unknown_etud(self, REQUEST=REQUEST)
return scu.log_unknown_etud(self, REQUEST=REQUEST)
etud = etuds[0]
# check dates
begin_date = ParseDateTimeUTC(begin) # may raises ValueError
@ -1763,7 +1753,7 @@ ou entrez une date pour visualiser les absents un jour donné&nbsp;:
if xml_reply:
# Renvoie le nouveau billet en XML
if REQUEST:
REQUEST.RESPONSE.setHeader("content-type", XML_MIMETYPE)
REQUEST.RESPONSE.setHeader("content-type", scu.XML_MIMETYPE)
billets = billet_absence_list(cnx, {"billet_id": billet_id})
tab = self._tableBillets(billets, etud=etud)
@ -1884,11 +1874,10 @@ ou entrez une date pour visualiser les absents un jour donné&nbsp;:
security.declareProtected(ScoView, "listeBilletsEtud")
def listeBilletsEtud(self, etudid=False, REQUEST=None, format="html"):
"""Liste billets pour un etudiant
"""
"""Liste billets pour un etudiant"""
etuds = self.getEtudInfo(etudid=etudid, filled=1, REQUEST=REQUEST)
if not etuds:
return log_unknown_etud(self, format=format, REQUEST=REQUEST)
return scu.log_unknown_etud(self, format=format, REQUEST=REQUEST)
etud = etuds[0]
cnx = self.GetDBConnexion()
@ -1899,8 +1888,7 @@ ou entrez une date pour visualiser les absents un jour donné&nbsp;:
security.declareProtected(ScoView, "XMLgetBilletsEtud")
def XMLgetBilletsEtud(self, etudid=False, REQUEST=None):
"""Liste billets pour un etudiant
"""
"""Liste billets pour un etudiant"""
if not self.get_preference("handle_billets_abs"):
return ""
t0 = time.time()
@ -1937,8 +1925,7 @@ ou entrez une date pour visualiser les absents un jour donné&nbsp;:
security.declareProtected(ScoAbsChange, "deleteBilletAbsence")
def deleteBilletAbsence(self, billet_id, REQUEST=None, dialog_confirmed=False):
"""Supprime un billet.
"""
"""Supprime un billet."""
cnx = self.GetDBConnexion()
billets = billet_absence_list(cnx, {"billet_id": billet_id})
if not billets:
@ -2107,8 +2094,8 @@ ou entrez une date pour visualiser les absents un jour donné&nbsp;:
Abs = self._ListeAbsDate(etud["etudid"], beg_date, end_date)
REQUEST.RESPONSE.setHeader("content-type", XML_MIMETYPE)
doc = jaxml.XML_document(encoding=SCO_ENCODING)
REQUEST.RESPONSE.setHeader("content-type", scu.XML_MIMETYPE)
doc = jaxml.XML_document(encoding=scu.SCO_ENCODING)
doc.absences(etudid=etud["etudid"], beg_date=beg_date, end_date=end_date)
doc._push()
for a in Abs:
@ -2126,7 +2113,7 @@ ou entrez une date pour visualiser les absents un jour donné&nbsp;:
return repr(doc)
_billet_absenceEditor = EditableTable(
_billet_absenceEditor = notesdb.EditableTable(
"billet_absence",
"billet_id",
(
@ -2210,7 +2197,6 @@ def MonthTableTail():
def MonthTableBody(
month, year, events=[], halfday=0, trattributes="", work_saturday=False, pad_width=8
):
# log('XXX events=%s' % events)
firstday, nbdays = calendar.monthrange(year, month)
localtime = time.localtime()
current_weeknum = time.strftime("%U", localtime)
@ -2443,8 +2429,8 @@ class CAbsSemEtud:
self.sem = sco_formsemestre.get_formsemestre(
self.context, self.sem["formsemestre_id"]
)
debut_sem = DateDMYtoISO(self.sem["date_debut"])
fin_sem = DateDMYtoISO(self.sem["date_fin"])
debut_sem = notesdb.DateDMYtoISO(self.sem["date_debut"])
fin_sem = notesdb.DateDMYtoISO(self.sem["date_fin"])
self._CountAbs = self.context.Absences.CountAbs(
etudid=self.etudid, debut=debut_sem, fin=fin_sem