Add Service Status and message usage count

This commit is contained in:
Beverly Nguyen
2025-10-14 15:28:58 -07:00
parent 2db7152bc4
commit 11d7f5839d
2 changed files with 47 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
from collections import OrderedDict
from collections import Counter, OrderedDict
from datetime import datetime
from functools import partial
@@ -34,6 +34,28 @@ from app.utils.user import user_has_permissions, user_is_platform_admin
from notifications_python_client.errors import HTTPError
def get_service_counts_by_status(services):
"""
Calculate service counts by status.
"""
def get_status(service):
if not service.get("active"):
return "suspended"
elif service.get("restricted"):
return "trial"
else:
return "live"
status_counts = Counter(get_status(service) for service in services)
return {
"live": status_counts["live"],
"trial": status_counts["trial"],
"suspended": status_counts["suspended"],
"total": len(services),
}
@main.route("/organizations", methods=["GET"])
@user_is_platform_admin
def organizations():
@@ -77,6 +99,9 @@ def organization_dashboard(org_id):
services = current_organization.services_and_usage(financial_year=year)["services"]
all_services = current_organization.services
service_counts = get_service_counts_by_status(all_services)
total_messages_sent = 0
total_messages_remaining = 0
@@ -92,6 +117,11 @@ def organization_dashboard(org_id):
selected_year=year,
messages_sent=total_messages_sent,
messages_remaining=total_messages_remaining,
total_services=service_counts["total"],
live_services=service_counts["live"],
trial_services=service_counts["trial"],
suspended_services=service_counts["suspended"],
all_services=all_services
)