mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-04-14 06:11:45 -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
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,22 @@
|
||||
<div id="message"></div>
|
||||
</div>
|
||||
<div id="totalMessageTable" class="margin-bottom-3"></div>
|
||||
<div class="grid-row">
|
||||
<div class="grid-col-12 tablet:grid-col-6">
|
||||
<div class="usa-card margin-bottom-3">
|
||||
<div class="usa-card__container">
|
||||
<div class="usa-card__body padding-2">
|
||||
<p class="margin-0">
|
||||
<strong>Services:</strong> {{ total_services }} (Live: {{ live_services }} - Trial: {{ trial_services }} - Suspended: {{ suspended_services }})
|
||||
</p>
|
||||
<p class="margin-0">
|
||||
<strong>Agreement:</strong> Jan 1 - Dec 31
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="margin-top-5 margin-bottom-5">
|
||||
<h2 class="font-heading-lg">What is a service?</h2>
|
||||
|
||||
Reference in New Issue
Block a user