From b8c6f087c6381add5c5e645c0df58a20dca60fc6 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Wed, 22 Sep 2021 00:57:51 +0100 Subject: [PATCH] Tidy up alert rendering. --- alerts/player.py | 3 ++- alerts/server.py | 3 ++- baps_types/happytime.py | 3 +++ ui-templates/alerts.html | 12 ++++-------- ui-templates/parts/alert_list.html | 16 ++++++---------- web_server.py | 6 ++++++ 6 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 baps_types/happytime.py diff --git a/alerts/player.py b/alerts/player.py index 45184c1..ff1b437 100644 --- a/alerts/player.py +++ b/alerts/player.py @@ -5,6 +5,7 @@ from datetime import datetime, timedelta from helpers.os_environment import resolve_external_file_path from helpers.alert_manager import AlertProvider from baps_types.alert import CRITICAL, WARNING, Alert +from baps_types.happytime import happytime MODULE = "Player" # This should match the log file, so the UI will link to the logs page. @@ -86,7 +87,7 @@ class PlayerAlertProvider(AlertProvider): This likely means there was an unhandled exception in the player code, causing the server to restart the player. Please check player logs to investigate the cause. Please restart the server to clear this warning.""" - .format(channel, str(start_time).rsplit(".",1)[0], str(server_start_time).rsplit(".",1)[0]), + .format(channel, happytime(start_time), happytime(server_start_time)), "module": MODULE+str(channel), "severity": WARNING })) diff --git a/alerts/server.py b/alerts/server.py index 7b56151..375f87d 100644 --- a/alerts/server.py +++ b/alerts/server.py @@ -5,6 +5,7 @@ from datetime import datetime, timedelta from helpers.os_environment import resolve_external_file_path from helpers.alert_manager import AlertProvider from baps_types.alert import CRITICAL, WARNING, Alert +from baps_types.happytime import happytime MODULE = "BAPSicleServer" # This should match the log file, so the UI will link to the logs page. @@ -66,7 +67,7 @@ class ServerAlertProvider(AlertProvider): It may have been automatically restarted by the OS. If this is not expected, please check logs to investigate why BAPSicle restarted/crashed.""" - .format(str(start_time).rsplit(".",1)[0]), + .format(happytime(start_time)), "module": MODULE, "severity": WARNING })] diff --git a/baps_types/happytime.py b/baps_types/happytime.py new file mode 100644 index 0000000..898730e --- /dev/null +++ b/baps_types/happytime.py @@ -0,0 +1,3 @@ +from datetime import datetime +def happytime(date: datetime): + return date.strftime("%Y-%m-%d %H:%M:%S") diff --git a/ui-templates/alerts.html b/ui-templates/alerts.html index 36e5fdd..c90fd60 100644 --- a/ui-templates/alerts.html +++ b/ui-templates/alerts.html @@ -5,14 +5,10 @@ {% endblock %} {% block content_inner %} {% if data %} -

Current Alerts: {{ data.alert_count_current }}

-
- {{ alert_list(data.alerts_current) }} -
+

Current Alerts: {{ data.alerts_current | length }}

+ {{ alert_list(data.alerts_current) }}
-

Previous Alerts: {{ data.alert_count_previous }}

-
- {{ alert_list(data.alerts_previous) }} -
+

Previous Alerts: {{ data.alerts_previous | length }}

+ {{ alert_list(data.alerts_previous) }} {% endif %} {% endblock %} diff --git a/ui-templates/parts/alert_list.html b/ui-templates/parts/alert_list.html index 6c8ae48..c559d18 100644 --- a/ui-templates/parts/alert_list.html +++ b/ui-templates/parts/alert_list.html @@ -2,21 +2,17 @@ {% for alert in alerts %}
-

- - {{ alert.severity }} -

- Since {{ alert.start_time }} - Last Seen {{ alert.last_time }} + {{ alert.severity }} +

{{ alert.title }}

+ Since {{ alert.start_time | happytime }} + Last Seen {{ alert.last_time | happytime }} {% if alert.end_time %} - Ended {{ alert.end_time }} + Ended {{ alert.end_time | happytime }} {% endif %}
-
+
Module: {{ alert.module }} {% autoescape false %}

{{ alert.description | replace("\n\n", "

") | replace("\n", "
")}}

diff --git a/web_server.py b/web_server.py index 08252a7..b0187a2 100644 --- a/web_server.py +++ b/web_server.py @@ -28,6 +28,7 @@ from helpers.normalisation import get_normalised_filename_if_available from helpers.myradio_api import MyRadioAPI from helpers.alert_manager import AlertManager import package +from baps_types.happytime import happytime env = Environment( loader=FileSystemLoader("%s/ui-templates/" % os.path.dirname(__file__)), @@ -95,6 +96,11 @@ def render_template(file, data, status=200): return html(html_content, status=status) +def _filter_happytime(date): + return happytime(date) + +env.filters["happytime"] = _filter_happytime + logger: LoggingManager server_state: StateManager api: MyRadioAPI