From 6d17f030e25d67304a7a8ec5f41cda4d0715e96b Mon Sep 17 00:00:00 2001 From: IDK Date: Fri, 5 Feb 2021 18:21:34 +0100 Subject: [PATCH] removed old mxDateTime --- ZAbsences.py | 17 ++++++++--------- config/install_debian10.sh | 2 -- sco_abs_notification.py | 6 ++---- sco_archives.py | 5 ++--- sco_formsemestre_status.py | 1 - sco_liste_notes.py | 8 ++++---- sco_report.py | 16 +++++++--------- sco_utils.py | 4 ++-- 8 files changed, 25 insertions(+), 34 deletions(-) diff --git a/ZAbsences.py b/ZAbsences.py index 08cef6781..9d44e3444 100644 --- a/ZAbsences.py +++ b/ZAbsences.py @@ -44,17 +44,16 @@ L'API de plus bas niveau est en gros: """ -import urllib -import datetime -import jaxml -import cgi import string import re import time +import datetime +import dateutil +import dateutil.parser import calendar - -from mx.DateTime import DateTime as mxDateTime -from mx.DateTime.ISO import ParseDateTimeUTC +import urllib +import cgi +import jaxml # --------------- from sco_zope import * @@ -1542,8 +1541,8 @@ ou entrez une date pour visualiser les absents un jour donnĂ© : return scu.log_unknown_etud(self, REQUEST=REQUEST) etud = etuds[0] # check dates - begin_date = ParseDateTimeUTC(begin) # may raises ValueError - end_date = ParseDateTimeUTC(end) + begin_date = dateutil.parser.isoparse(begin) # may raises ValueError + end_date = dateutil.parser.isoparse(end) if begin_date > end_date: raise ValueError("invalid dates") # diff --git a/config/install_debian10.sh b/config/install_debian10.sh index 8e28134df..a7a6cd793 100755 --- a/config/install_debian10.sh +++ b/config/install_debian10.sh @@ -96,8 +96,6 @@ apt-get -y install python-cracklib # was python-crack apt-get -y install python-icalendar apt-get -y install python-requests -apt-get -y install python-egenix-mxtools python-egenix-mxdatetime - # ------------ SVNVERSION=$(cd ..; svnversion) diff --git a/sco_abs_notification.py b/sco_abs_notification.py index af9f1490d..cc3080572 100644 --- a/sco_abs_notification.py +++ b/sco_abs_notification.py @@ -226,10 +226,8 @@ def user_nbdays_since_last_notif(context, email_addr, etudid): ) res = cursor.dictfetchone() if res: - mxd = res["notification_date"] # mx.DateTime instance - lastdate = datetime.datetime(mxd.year, mxd.month, mxd.day) - now = datetime.datetime.now() - return (now - lastdate).days + now = datetime.datetime.now(res["notification_date"].tzinfo) + return (now - res["notification_date"]).days else: return None diff --git a/sco_archives.py b/sco_archives.py index fc50dc5d6..987797a03 100644 --- a/sco_archives.py +++ b/sco_archives.py @@ -47,8 +47,7 @@ """ import os import time -from mx.DateTime import DateTime as mxDateTime -import mx.DateTime +import datetime import re import shutil import glob @@ -140,7 +139,7 @@ class BaseArchiver: def get_archive_date(self, archive_id): """Returns date (as a DateTime object) of an archive""" dt = [int(x) for x in os.path.split(archive_id)[1].split("-")] - return mxDateTime(*dt) + return datetime.datetime(*dt) def list_archive(self, archive_id): """Return list of filenames (without path) in archive""" diff --git a/sco_formsemestre_status.py b/sco_formsemestre_status.py index e71e4624c..99267a291 100644 --- a/sco_formsemestre_status.py +++ b/sco_formsemestre_status.py @@ -29,7 +29,6 @@ """ # Rewritten from ancient DTML code -from mx.DateTime import DateTime as mxDateTime from notes_log import log import sco_utils as scu diff --git a/sco_liste_notes.py b/sco_liste_notes.py index 66dfbf61b..55cd2e19c 100644 --- a/sco_liste_notes.py +++ b/sco_liste_notes.py @@ -601,13 +601,13 @@ def _add_eval_columns( coefs[evaluation_id] = "coef. %s" % e["coefficient"] if note_sur_20: - nmx = 20.0 + nmax = 20.0 else: - nmx = e["note_max"] + nmax = e["note_max"] if keep_numeric: - note_max[evaluation_id] = nmx + note_max[evaluation_id] = nmax else: - note_max[evaluation_id] = "/ %s" % nmx + note_max[evaluation_id] = "/ %s" % nmax if nb_notes > 0: moys[evaluation_id] = "%.3g" % (sum_notes / nb_notes) diff --git a/sco_report.py b/sco_report.py index 55927dfa5..ed795c534 100644 --- a/sco_report.py +++ b/sco_report.py @@ -34,9 +34,7 @@ import tempfile import urllib import re import time -import mx -import mx.DateTime -from mx.DateTime import DateTime as mxDateTime +import datetime import sco_utils as scu import VERSION @@ -435,8 +433,8 @@ def table_suivi_cohorte( # tri les semestres par date de debut for s in sems: d, m, y = [int(x) for x in s["date_debut"].split("/")] - s["date_debut_mx"] = mxDateTime(y, m, d) # pylint: disable=not-callable - sems.sort(lambda x, y: cmp(x["date_debut_mx"], y["date_debut_mx"])) + s["date_debut_dt"] = datetime.datetime(y, m, d) + sems.sort(lambda x, y: cmp(x["date_debut_dt"], y["date_debut_dt"])) # 2-- Pour chaque semestre, trouve l'ensemble des etudiants venant de sem logt("B: etuds sets") @@ -467,21 +465,21 @@ def table_suivi_cohorte( # semestre de depart: porigin = periodsem() d, m, y = [int(x) for x in sem["date_debut"].split("/")] - porigin.datedebut = mxDateTime(y, m, d) # pylint: disable=not-callable + porigin.datedebut = datetime.datetime(y, m, d) porigin.sems = [sem] # - tolerance = mx.DateTime.DateTimeDelta(45) # 45 days + tolerance = datetime.timedelta(days=45) for s in sems: merged = False for p in P: - if abs(s["date_debut_mx"] - p.datedebut) < tolerance: + if abs(s["date_debut_dt"] - p.datedebut) < tolerance: p.sems.append(s) merged = True break if not merged: p = periodsem() - p.datedebut = s["date_debut_mx"] + p.datedebut = s["date_debut_dt"] p.sems = [s] P.append(p) diff --git a/sco_utils.py b/sco_utils.py index 7c946d17c..88c2a29a6 100644 --- a/sco_utils.py +++ b/sco_utils.py @@ -543,15 +543,15 @@ class ScoDocJSONEncoder(json.JSONEncoder): def default(self, o): # pylint: disable=E0202 import sco_formsemestre - # horrible hack pour encoder les dates mx + # ScoDoc 7.22 n'utilise plus mx: if str(type(o)) == "": + log("Warning: mx.DateTime object detected !") return o.strftime("%Y-%m-%dT%H:%M:%S") if isinstance(o, (datetime.date, datetime.datetime)): return o.isoformat() elif isinstance(o, sco_formsemestre.ApoEtapeVDI): return str(o) else: - log("not mx: %s" % type(o)) return json.JSONEncoder.default(self, o)