From 1c4e10a75f10bf7818f0f93f76bfe8478e0a238a Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Mon, 23 Sep 2024 16:10:41 +1000 Subject: [PATCH] Use formats.localize helper function --- src/webmon_app/reporting/dasmon/view_util.py | 29 +++++++------------- src/webmon_app/reporting/dasmon/views.py | 5 ++-- src/webmon_app/reporting/pvmon/view_util.py | 5 ++-- src/webmon_app/reporting/pvmon/views.py | 5 ++-- src/webmon_app/reporting/report/view_util.py | 8 ++---- src/webmon_app/reporting/report/views.py | 14 ++++------ 6 files changed, 24 insertions(+), 42 deletions(-) diff --git a/src/webmon_app/reporting/dasmon/view_util.py b/src/webmon_app/reporting/dasmon/view_util.py index cac9428b..0cf5d217 100644 --- a/src/webmon_app/reporting/dasmon/view_util.py +++ b/src/webmon_app/reporting/dasmon/view_util.py @@ -16,7 +16,7 @@ from reporting.pvmon.models import PVCache, PVStringCache, MonitoredVariable from django.shortcuts import get_object_or_404 from django.urls import reverse -from django.utils import dateformat, timezone, formats +from django.utils import timezone, formats from django.contrib.auth.models import Group from django.conf import settings import datetime @@ -68,7 +68,6 @@ def get_cached_variables(instrument_id, monitored_only=False): localtime = timezone.localtime(kvp.timestamp) except: # noqa: E722 localtime = kvp.timestamp - df = dateformat.DateFormat(localtime) # Check whether we have a number try: @@ -84,7 +83,7 @@ def get_cached_variables(instrument_id, monitored_only=False): variable_dict = { "key": str(kvp.key_id), "value": string_value, - "timestamp": df.format(formats.get_format("DATETIME_FORMAT")), + "timestamp": formats.localize(localtime), } key_value_pairs.append(variable_dict) @@ -492,11 +491,11 @@ def workflow_diagnostics(timeout=None): time_diff = timezone.now() - status_time.replace(tzinfo=None) if time_diff > delay_time: dasmon_listener_warning = True - df = dateformat.DateFormat(status_time) + wf_conditions.append( "No heartbeat since %s: %s" % ( - df.format(formats.get_format("DATETIME_FORMAT")), + formats.localize(status_time), _red_message("contact the Neutron Data Sciences Group or Linux Support"), ) ) @@ -648,12 +647,11 @@ def pvstreamer_diagnostics(instrument_id, timeout=None, process="pvstreamer"): timediff = timezone.now() - status_time.replace(tzinfo=None) if timediff > delay_time: dasmon_listener_warning = True - df = dateformat.DateFormat(status_time) pv_conditions.append( "No %s heartbeat since %s: %s" % ( process, - df.format(formats.get_format("DATETIME_FORMAT")), + formats.localize(status_time), _red_message("ask Linux Support or DAS to restart pvsd"), ) ) @@ -746,10 +744,7 @@ def dasmon_diagnostics(instrument_id, timeout=None): dt = timezone.now().replace(tzinfo=None) - last_amq_time.replace(tzinfo=None) if dt > delay_time: slow_amq = True - df = dateformat.DateFormat(last_amq_time) - dasmon_conditions.append( - "No ActiveMQ updates from DASMON since %s" % df.format(formats.get_format("DATETIME_FORMAT")) - ) + dasmon_conditions.append("No ActiveMQ updates from DASMON since %s" % formats.localize(last_amq_time)) # Heartbeat try: @@ -758,11 +753,10 @@ def dasmon_diagnostics(instrument_id, timeout=None): dt = timezone.now().replace(tzinfo=None) - status_time.replace(tzinfo=None) if dt > delay_time: slow_status = True - df = dateformat.DateFormat(status_time) dasmon_conditions.append( "No heartbeat since %s: %s" % ( - df.format(formats.get_format("DATETIME_FORMAT")), + formats.localize(status_time), _red_message("ask Linux Support or DAS to restart DASMON"), ) ) @@ -943,14 +937,13 @@ def get_live_runs_update(request, instrument_id, ipts_id, **data_dict): localtime = timezone.localtime(r.created_on) except: # noqa: E722 localtime = r.created_on - df = dateformat.DateFormat(localtime) reduce_url = reverse( "report:submit_for_reduction", args=[str(r.instrument_id), r.run_number], ) expt_dict = { "run": r.run_number, - "timestamp": df.format(formats.get_format("DATETIME_FORMAT")), + "timestamp": formats.localize(localtime), "last_error": status, "run_id": r.id, "reduce_url": ("