mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-18 13:39:57 -04:00
Little bit of cleanup
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user