Skip to content

Commit

Permalink
Merge pull request #4734 from freelawproject/3274-show-tz-webhook-events
Browse files Browse the repository at this point in the history
feat(webhook_logs): Display timezone in all datetimes
  • Loading branch information
mlissner authored Nov 26, 2024
2 parents 65f59cb + 877cf13 commit 56a41d4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
17 changes: 16 additions & 1 deletion cl/custom_filters/templatetags/extras.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions cl/users/templates/includes/webhook-event-detail.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "profile/webhooks_base.html" %}
{% load extras %}
{% load static %}
{% load waffle_tags %}
{% load humanize %}
Expand All @@ -13,11 +14,11 @@ <h3 class="v-offset-below-2">Webhook Event Details{% if webhook_event.debug %} (
<label class="col-md-3">Endpoint status: </label><p class="col-md-9">{% if webhook_event.webhook.enabled %} Enabled {% else %} Disabled {% endif %}</p>
<label class="col-md-3">Event type: </label><p class="col-md-9">{{ webhook_event.webhook.get_event_type_display }}</p>
<label class="col-md-3">Idempotency-key: </label><p class="col-md-9">{{ webhook_event.event_id }}</p>
<label class="col-md-3">Event date: </label><p class="col-md-9">{{ webhook_event.date_created }}</p>
<label class="col-md-3">Event date: </label><p class="col-md-9">{{ webhook_event.date_created|datetime_in_utc }}</p>
<label class="col-md-3">Status code: </label><p class="col-md-9 bold"> {% if webhook_event.status_code %}{{ webhook_event.status_code }} {{ webhook_event.get_status_code_display }} {% else %}-{% endif %}</p>
<label class="col-md-3">Event status: </label><p class="col-md-9 bold {{ webhook_event.event_status|webhook_status_class }}">{{ webhook_event.get_event_status_display }}</p>
<label class="col-md-3">Failure count: </label><p class="col-md-9">{{ webhook_event.retry_counter }}</p>
<label class="col-md-3">Next retry date: </label><p class="col-md-9">{% 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 %}</p>
<label class="col-md-3">Next retry date: </label><p class="col-md-9">{% 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 %}</p>
</div>
<div class="row form-group">
<div class="col-xs-12">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load extras %}
{% load widget_tweaks %}
{% if results %}
{% for webhook in results %}
Expand All @@ -21,11 +22,11 @@
{% endif %}
</p>
</td>
<td>{{ webhook.date_created }}</td>
<td>{{ webhook.date_created|datetime_in_utc }}</td>
{% if not webhook.debug %}
<td class="text-center">
{% if webhook.next_retry_date %}
{{ webhook.next_retry_date }}
{{ webhook.next_retry_date|datetime_in_utc }}
{% else %}
-
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions cl/users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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?"""
Expand Down

0 comments on commit 56a41d4

Please sign in to comment.