From 2b5a4705167bba12ea9dccb88ffb9636815145b2 Mon Sep 17 00:00:00 2001 From: viennet Date: Thu, 24 Dec 2020 14:56:01 +0100 Subject: [PATCH] itre form saisie + pylint --- ZAbsences.py | 184 ++++++++++++++++++++++++--------------------------- 1 file changed, 85 insertions(+), 99 deletions(-) diff --git a/ZAbsences.py b/ZAbsences.py index 1bdd11b7..d450d09f 100644 --- a/ZAbsences.py +++ b/ZAbsences.py @@ -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&datefin=%s&%s&destination=%s" - % ( - datedebut, - datefin, - groups_infos.groups_query_args, - urllib.quote(destination), - ) + moduleimpl_id = None + base_url_noweeks = "SignaleAbsenceGrSemestre?datedebut=%s&datefin=%s&%s&destination=%s" % ( + datedebut, + datefin, + groups_infos.groups_query_args, + urllib.quote(destination), ) base_url = ( base_url_noweeks + "&nbweeks=%s" % nbweeks @@ -1139,7 +1131,6 @@ class ZAbsences( if moduleimpl_id: url_link_semaines += "&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 + '' + groups_infos.groups_titles + "" ) @@ -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 = [ """