From 0d4296c89c1aa7274c6f457e4503267e3b662ea1 Mon Sep 17 00:00:00 2001 From: Iain Learmonth Date: Wed, 20 Apr 2022 15:56:09 +0100 Subject: [PATCH] alarms: handle missing last update --- app/portal/__init__.py | 7 +++++++ app/portal/templates/alarms.html.j2 | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/portal/__init__.py b/app/portal/__init__.py index 81227ef..af9bae5 100644 --- a/app/portal/__init__.py +++ b/app/portal/__init__.py @@ -20,6 +20,13 @@ def calculate_mirror_expiry(s): return f"{countdown.days} days" +@portal.app_template_filter("format_datetime") +def format_datetime(s): + if s is None: + return "Unknown" + return s.strftime("%a, %d %b %Y %H:%M:%S") + + @portal.route("/") def portal_home(): return render_template("home.html.j2", section="home") diff --git a/app/portal/templates/alarms.html.j2 b/app/portal/templates/alarms.html.j2 index 362cdbe..0e8bea8 100644 --- a/app/portal/templates/alarms.html.j2 +++ b/app/portal/templates/alarms.html.j2 @@ -28,7 +28,7 @@ {{ alarm.alarm_type }} {{ alarm.alarm_state.name }} {{ alarm.text }} - {{ alarm.last_updated.strftime("%a, %d %b %Y %H:%M:%S") }} + {{ alarm.last_updated | format_date }} {% endfor %}