mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 21:49:37 -04:00
Add Service Status and message usage count
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user