From 5a6d16f5af905ee135c2cea98cf39564aca5d787 Mon Sep 17 00:00:00 2001 From: Stephen Tomkinson Date: Fri, 8 Nov 2024 15:57:45 +0000 Subject: [PATCH] Improve robustness of built-in tags to better cope with invalid bloodhound data --- event_tracker/templatetags/custom_tags.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/event_tracker/templatetags/custom_tags.py b/event_tracker/templatetags/custom_tags.py index 16e35ce..f0a6aba 100644 --- a/event_tracker/templatetags/custom_tags.py +++ b/event_tracker/templatetags/custom_tags.py @@ -227,7 +227,10 @@ def linebreaksword(value): @register.filter def epoch_to_ts(epoch_time): - return datetime.datetime.fromtimestamp(epoch_time, tz=datetime.timezone.utc) + try: + return datetime.datetime.fromtimestamp(epoch_time, tz=datetime.timezone.utc) + except: + return f"Could not convert: {epoch_time}" @register.filter @@ -245,7 +248,10 @@ def render_ts_to_ts_utc(value, until): @register.filter def render_ts_local(value): - return f"{date_format(value, 'SHORT_DATE_FORMAT')} {localtime(value).strftime('%H:%M')}" + if isinstance(value, datetime.datetime): + return f"{date_format(value, 'SHORT_DATE_FORMAT')} {localtime(value).strftime('%H:%M')}" + else: + return f"Not a datetime: {value}" @register.filter