Merge branch 'main' of github.com:GSA/notifications-admin into 3021-create-aggregate-table-of-services-per-org

This commit is contained in:
Beverly Nguyen
2025-10-21 11:13:01 -07:00
15 changed files with 130 additions and 78 deletions

View File

@@ -1,17 +1,11 @@
from collections import Counter, OrderedDict
from collections import OrderedDict
from datetime import datetime
from functools import partial
from flask import current_app, flash, redirect, render_template, request, url_for
from flask_login import current_user
from app import (
current_organization,
org_invite_api_client,
organizations_client,
service_api_client,
)
from app.enums import ServiceStatus
from app import current_organization, org_invite_api_client, organizations_client
from app.main import main
from app.main.forms import (
AdminBillingDetailsForm,
@@ -68,28 +62,9 @@ def add_organization():
return render_template("views/organizations/add-organization.html", form=form)
def get_service_counts_by_status(services):
def get_status(service):
if not service.get("active"):
return ServiceStatus.SUSPENDED
elif service.get("restricted"):
return ServiceStatus.TRIAL
else:
return ServiceStatus.LIVE
status_counts = Counter(get_status(service) for service in services)
return {
"live_services": status_counts[ServiceStatus.LIVE],
"trial_services": status_counts[ServiceStatus.TRIAL],
"suspended_services": status_counts[ServiceStatus.SUSPENDED],
"total_services": len(services),
}
def get_organization_message_allowance(org_id):
try:
message_usage = service_api_client.get_organization_message_usage(org_id)
message_usage = organizations_client.get_organization_message_usage(org_id)
except Exception as e:
current_app.logger.error(f"Error fetching organization message usage: {e}")
message_usage = {}
@@ -110,14 +85,16 @@ def organization_dashboard(org_id):
year = requested_and_current_financial_year(request)[0]
message_allowance = get_organization_message_allowance(org_id)
service_counts = get_service_counts_by_status(current_organization.services)
return render_template(
"views/organizations/organization/index.html",
selected_year=year,
services=current_organization.services,
live_services=len(current_organization.live_services),
trial_services=len(current_organization.trial_services),
suspended_services=len(current_organization.suspended_services),
total_services=len(current_organization.services),
**message_allowance,
**service_counts,
)