Little bit of cleanup

This commit is contained in:
Alex Janousek
2025-10-01 11:13:44 -04:00
parent 24a735ffc2
commit 35590fed0f
2 changed files with 6 additions and 18 deletions
+2 -4
View File
@@ -279,9 +279,7 @@ def get_notifications(service_id, message_type, status_override=None): # noqa
to=search_term, to=search_term,
) )
notifications_list = notifications.get( notifications_list = notifications.get("notifications", [])
"notifications", notifications.get("items", [])
)
url_args = {"message_type": message_type, "status": request.args.get("status")} url_args = {"message_type": message_type, "status": request.args.get("status")}
prev_page = None prev_page = None
@@ -291,7 +289,7 @@ def get_notifications(service_id, message_type, status_override=None): # noqa
) )
next_page = None next_page = None
total_items = notifications.get("total", len(notifications_list)) total_items = notifications.get("total", 0)
page_size = notifications.get("page_size", 50) page_size = notifications.get("page_size", 50)
total_pages = (total_items + page_size - 1) // page_size total_pages = (total_items + page_size - 1) // page_size
if ( if (
+4 -14
View File
@@ -1039,20 +1039,10 @@ def send_notification(service_id, template_id):
) )
attempts = 0 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 # The response can come back in different forms of incompleteness
while ( while (
get_total(notifications) == 0 notifications["total"] == 0
and get_items(notifications) == [] and notifications["notifications"] == []
and attempts < 50 and attempts < 50
): ):
notifications = notification_api_client.get_notifications_for_service( notifications = notification_api_client.get_notifications_for_service(
@@ -1061,7 +1051,7 @@ def send_notification(service_id, template_id):
time.sleep(0.1) time.sleep(0.1)
attempts = attempts + 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 # This shows the job we auto-generated for the user
return redirect( return redirect(
url_for( url_for(
@@ -1070,7 +1060,7 @@ def send_notification(service_id, template_id):
job_id=upload_id, job_id=upload_id,
) )
) )
total = get_total(notifications) total = notifications["total"]
current_app.logger.info( current_app.logger.info(
hilite( hilite(
f"job_id: {upload_id} has notifications: {total} and attempts: {attempts}" f"job_id: {upload_id} has notifications: {total} and attempts: {attempts}"