Améliore translate_calendar

This commit is contained in:
Emmanuel Viennet 2024-10-24 10:49:22 +02:00
parent 3c5cb3e517
commit 4aa5c0e277
3 changed files with 20 additions and 35 deletions

View File

@ -514,32 +514,6 @@ def DateISOtoDMY(isodate):
return "%02d/%02d/%04d" % (day, month, year) 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): def float_null_is_zero(x):
if x is None or x == "": if x is None or x == "":
return 0.0 return 0.0

View File

@ -224,20 +224,19 @@ def translate_calendar(
modimpl: ModuleImpl | bool = event["modimpl"] modimpl: ModuleImpl | bool = event["modimpl"]
params = { params = {
"scodoc_dept": g.scodoc_dept, "scodoc_dept": g.scodoc_dept,
"group_ids": group.id, "heure_deb": scu.heure_to_iso8601(event["heure_deb"]),
"heure_deb": event["heure_deb"].replace("h", ":") if "h" in event["heure_deb"] else event["heure_deb"], "heure_fin": scu.heure_to_iso8601(event["heure_fin"]),
"heure_fin": event["heure_fin"].replace("h", ":") if "h" in event["heure_fin"] else event["heure_fin"], "day": event["jour"],
"day": event["jour"]
} }
if group:
params["group_ids"] = group.id
if modimpl: if modimpl:
params["moduleimpl_id"] = modimpl.id params["moduleimpl_id"] = modimpl.id
elif group: elif group:
params["formsemestre_id"] = group.partition.formsemestre_id params["formsemestre_id"] = group.partition.formsemestre_id
url_abs = ( url_abs = (
url_for("assiduites.signal_assiduites_group", **params) url_for("assiduites.signal_assiduites_group", **params) if group else None
if group
else None
) )
match modimpl: match modimpl:
case False: # EDT non configuré case False: # EDT non configuré

View File

@ -152,6 +152,18 @@ def convert_fr_date(
raise ScoValueError("Date (j/m/a) invalide") 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( def print_progress_bar(
iteration, iteration,
total, total,