From 4aa5c0e277dc9133b2b736407d59c7e4102527b7 Mon Sep 17 00:00:00 2001
From: Emmanuel Viennet <emmanuel.viennet@gmail.com>
Date: Thu, 24 Oct 2024 10:49:22 +0200
Subject: [PATCH] =?UTF-8?q?Am=C3=A9liore=20translate=5Fcalendar?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/scodoc/notesdb.py     | 26 --------------------------
 app/scodoc/sco_edt_cal.py | 17 ++++++++---------
 app/scodoc/sco_utils.py   | 12 ++++++++++++
 3 files changed, 20 insertions(+), 35 deletions(-)

diff --git a/app/scodoc/notesdb.py b/app/scodoc/notesdb.py
index add7d84a..a0e7ff4b 100644
--- a/app/scodoc/notesdb.py
+++ b/app/scodoc/notesdb.py
@@ -514,32 +514,6 @@ def DateISOtoDMY(isodate):
     return "%02d/%02d/%04d" % (day, month, year)
 
 
-def TimetoISO8601(t, null_is_empty=False) -> str:
-    "convert time string to ISO 8601 (allow 16:03, 16h03, 16)"
-    if isinstance(t, datetime.time):
-        return t.isoformat()
-    if not t and null_is_empty:
-        return ""
-    t = t.strip().upper().replace("H", ":")
-    if t and t.count(":") == 0 and len(t) < 3:
-        t = t + ":00"
-    return t
-
-
-def TimefromISO8601(t) -> str:
-    "convert time string from ISO 8601 to our display format"
-    if not t:
-        return t
-    # XXX strange bug turnaround...
-    try:
-        t = "%s:%s" % (t.hour(), t.minute())
-        # log('TimefromISO8601: converted isotime to iso !')
-    except:
-        pass
-    fs = str(t).split(":")
-    return fs[0] + "h" + fs[1]  # discard seconds
-
-
 def float_null_is_zero(x):
     if x is None or x == "":
         return 0.0
diff --git a/app/scodoc/sco_edt_cal.py b/app/scodoc/sco_edt_cal.py
index be011204..fe1477fe 100644
--- a/app/scodoc/sco_edt_cal.py
+++ b/app/scodoc/sco_edt_cal.py
@@ -224,20 +224,19 @@ def translate_calendar(
         modimpl: ModuleImpl | bool = event["modimpl"]
         params = {
             "scodoc_dept": g.scodoc_dept,
-            "group_ids": group.id,
-            "heure_deb": event["heure_deb"].replace("h", ":") if "h" in event["heure_deb"] else event["heure_deb"],
-            "heure_fin": event["heure_fin"].replace("h", ":") if "h" in event["heure_fin"] else event["heure_fin"],
-            "day": event["jour"]
+            "heure_deb": scu.heure_to_iso8601(event["heure_deb"]),
+            "heure_fin": scu.heure_to_iso8601(event["heure_fin"]),
+            "day": event["jour"],
         }
+        if group:
+            params["group_ids"] = group.id
         if modimpl:
-             params["moduleimpl_id"] = modimpl.id
+            params["moduleimpl_id"] = modimpl.id
         elif group:
-             params["formsemestre_id"] = group.partition.formsemestre_id
+            params["formsemestre_id"] = group.partition.formsemestre_id
 
         url_abs = (
-            url_for("assiduites.signal_assiduites_group", **params)
-              if group
-              else None
+            url_for("assiduites.signal_assiduites_group", **params) if group else None
         )
         match modimpl:
             case False:  # EDT non configuré
diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py
index a437b3da..53d2c66c 100644
--- a/app/scodoc/sco_utils.py
+++ b/app/scodoc/sco_utils.py
@@ -152,6 +152,18 @@ def convert_fr_date(
     raise ScoValueError("Date (j/m/a) invalide")
 
 
+def heure_to_iso8601(t, null_is_empty=False) -> str:
+    "convert time string to ISO 8601 (allow 16:03, 16h03, 16)"
+    if isinstance(t, datetime.time):
+        return t.isoformat()
+    if not t and null_is_empty:
+        return ""
+    t = t.strip().upper().replace("H", ":")
+    if t and t.count(":") == 0 and len(t) < 3:
+        t = t + ":00"
+    return t
+
+
 def print_progress_bar(
     iteration,
     total,
-- 
GitLab