diff --git a/cl/custom_filters/templatetags/extras.py b/cl/custom_filters/templatetags/extras.py index 39d535b2df..6532ca2881 100644 --- a/cl/custom_filters/templatetags/extras.py +++ b/cl/custom_filters/templatetags/extras.py @@ -1,7 +1,7 @@ import random import re import urllib.parse -from datetime import datetime +from datetime import datetime, timezone import waffle from django import template @@ -337,6 +337,21 @@ def format_date(date_str: str) -> str: return date_str +@register.filter +def datetime_in_utc(date_obj) -> str: + """Formats a datetime object in UTC with timezone displayed. + For example: 'Nov. 25, 2024, 01:28 p.m. UTC'""" + if date_obj is None: + return "" + try: + return date_filter( + date_obj.astimezone(timezone.utc), + "M. j, Y, h:i a T", + ) + except (ValueError, TypeError): + return date_obj + + @register.filter def build_docket_id_q_param(request_q: str, docket_id: str) -> str: """Build a query string that includes the docket ID and any existing query diff --git a/cl/users/templates/includes/webhook-event-detail.html b/cl/users/templates/includes/webhook-event-detail.html index 20f631fb53..9f70262daa 100644 --- a/cl/users/templates/includes/webhook-event-detail.html +++ b/cl/users/templates/includes/webhook-event-detail.html @@ -1,4 +1,5 @@ {% extends "profile/webhooks_base.html" %} +{% load extras %} {% load static %} {% load waffle_tags %} {% load humanize %} @@ -13,11 +14,11 @@

Webhook Event Details{% if webhook_event.debug %} (

{% if webhook_event.webhook.enabled %} Enabled {% else %} Disabled {% endif %}

{{ webhook_event.webhook.get_event_type_display }}

{{ webhook_event.event_id }}

-

{{ webhook_event.date_created }}

+

{{ webhook_event.date_created|datetime_in_utc }}

{% if webhook_event.status_code %}{{ webhook_event.status_code }} {{ webhook_event.get_status_code_display }} {% else %}-{% endif %}

{{ webhook_event.get_event_status_display }}

{{ webhook_event.retry_counter }}

-

{% if not webhook_event.debug %}{% if webhook_event.next_retry_date %}{{ webhook_event.next_retry_date }}{% else %}-{% endif %}{% else %}Test events will not be retried{% endif %}

+

{% if not webhook_event.debug %}{% if webhook_event.next_retry_date %}{{ webhook_event.next_retry_date|datetime_in_utc }}{% else %}-{% endif %}{% else %}Test events will not be retried{% endif %}

diff --git a/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html b/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html index dc022dff94..a9f8596832 100644 --- a/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html +++ b/cl/users/templates/includes/webhooks_htmx/webhook-logs-list.html @@ -1,3 +1,4 @@ +{% load extras %} {% load widget_tweaks %} {% if results %} {% for webhook in results %} @@ -21,11 +22,11 @@ {% endif %}

- {{ webhook.date_created }} + {{ webhook.date_created|datetime_in_utc }} {% if not webhook.debug %} {% if webhook.next_retry_date %} - {{ webhook.next_retry_date }} + {{ webhook.next_retry_date|datetime_in_utc }} {% else %} - {% endif %} diff --git a/cl/users/tests.py b/cl/users/tests.py index 89170a445c..f5e26aac09 100644 --- a/cl/users/tests.py +++ b/cl/users/tests.py @@ -3467,7 +3467,7 @@ async def test_list_webhook_events(self) -> None: response = await self.client.get(webhook_event_path_list) self.assertEqual(response.status_code, HTTPStatus.OK) # There shouldn't be results for user_1 - self.assertEqual(response.content, b"\n\n") + self.assertEqual(response.content.strip(), b"") sa_webhook = await sync_to_async(WebhookFactory)( user=self.user_1, @@ -3485,7 +3485,7 @@ async def test_list_webhook_events(self) -> None: response = await self.client.get(webhook_event_path_list) self.assertEqual(response.status_code, HTTPStatus.OK) # There should be results for user_1 - self.assertNotEqual(response.content, b"\n\n") + self.assertNotEqual(response.content.strip(), b"") async def test_get_available_webhook_versions(self) -> None: """Can we get users available versions for a webhook event type?"""