about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2026-01-08 09:42:25 -0600
committerFrederick Muriuki Muriithi2026-01-08 09:42:25 -0600
commit0f93a6585446b8ff22adc6eafb2742984fe75adc (patch)
tree16c2ca3d1666c6ba18be7517a7f4fb1704e1a736
parent05687ca762e8ed2a6b551ec9202f396a11f9008a (diff)
downloadgn-uploader-0f93a6585446b8ff22adc6eafb2742984fe75adc.tar.gz
Generalize datetime formatting function for templates.
-rw-r--r--uploader/background_jobs.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/uploader/background_jobs.py b/uploader/background_jobs.py
index 64d55e9..fc534dc 100644
--- a/uploader/background_jobs.py
+++ b/uploader/background_jobs.py
@@ -130,6 +130,15 @@ def job_error(job_id: uuid.UUID):
             return render_template("jobs/job-not-found.html", job_id=job_id)
 
 
+def make_datetime_formatter(dtformat: str = "") -> str:
+    """Make a datetime formatter with the provided `dtformat`"""
+    def __formatter__(val: str) -> str:
+        dt = datetime.datetime.fromisoformat(val)
+        return dt.strftime(dtformat.strip() or "%A, %d %B %Y at %H:%M %Z")
+
+    return __formatter__
+
+
 @background_jobs_bp.route("/list")
 @require_login
 def list_jobs():
@@ -139,8 +148,7 @@ def list_jobs():
             "background-jobs/list-jobs.html",
             jobs=jobs.jobs_by_external_id(
                 conn, session.user_details()["user_id"]),
-            display_datetime=lambda val: datetime.datetime.fromisoformat(
-                val).strftime("%A, %d %B %Y at %H:%M %Z"))
+            display_datetime=make_datetime_formatter())
 
 
 @background_jobs_bp.route("/summary/<uuid:job_id>")
@@ -153,7 +161,9 @@ def job_summary(job_id: uuid.UUID):
             status = job["metadata"]["status"]
 
             if status in ("completed", "error"):
-                return render_template("background-jobs/job-summary.html", job=job)
+                return render_template("background-jobs/job-summary.html",
+                                       job=job,
+                                       display_datetime=make_datetime_formatter())
             return redirect(url_for("background-jobs.job_status", job["job_id"]))
         except JobNotFound as _jnf:
             return render_template("jobs/job-not-found.html", job_id=job_id)