From 35590fed0f9ee0518b7681ade0c7fbaf92430ba4 Mon Sep 17 00:00:00 2001 From: Alex Janousek Date: Wed, 1 Oct 2025 11:13:44 -0400 Subject: [PATCH] Little bit of cleanup --- app/main/views/jobs.py | 6 ++---- app/main/views/send.py | 18 ++++-------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index 5254a5757..3010e5b53 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -279,9 +279,7 @@ def get_notifications(service_id, message_type, status_override=None): # noqa to=search_term, ) - notifications_list = notifications.get( - "notifications", notifications.get("items", []) - ) + notifications_list = notifications.get("notifications", []) url_args = {"message_type": message_type, "status": request.args.get("status")} prev_page = None @@ -291,7 +289,7 @@ def get_notifications(service_id, message_type, status_override=None): # noqa ) next_page = None - total_items = notifications.get("total", len(notifications_list)) + total_items = notifications.get("total", 0) page_size = notifications.get("page_size", 50) total_pages = (total_items + page_size - 1) // page_size if ( diff --git a/app/main/views/send.py b/app/main/views/send.py index 142f2d8da..af9eb7df6 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -1039,20 +1039,10 @@ def send_notification(service_id, template_id): ) attempts = 0 - # Handle both old and new response formats - # New format: { items: [...] } - # Old format: { notifications: [...], total: X } - def get_items(response): - return response.get("items", response.get("notifications", [])) - - def get_total(response): - items = get_items(response) - return response.get("total", len(items)) - # The response can come back in different forms of incompleteness while ( - get_total(notifications) == 0 - and get_items(notifications) == [] + notifications["total"] == 0 + and notifications["notifications"] == [] and attempts < 50 ): notifications = notification_api_client.get_notifications_for_service( @@ -1061,7 +1051,7 @@ def send_notification(service_id, template_id): time.sleep(0.1) attempts = attempts + 1 - if get_total(notifications) == 0 and attempts == 50: + if notifications["total"] == 0 and attempts == 50: # This shows the job we auto-generated for the user return redirect( url_for( @@ -1070,7 +1060,7 @@ def send_notification(service_id, template_id): job_id=upload_id, ) ) - total = get_total(notifications) + total = notifications["total"] current_app.logger.info( hilite( f"job_id: {upload_id} has notifications: {total} and attempts: {attempts}"