mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-09 19:04:33 -04:00
refactor org model and removed enum
This commit is contained in:
@@ -106,9 +106,3 @@ class VerificationStatus(StrEnum):
|
||||
class AuthType(StrEnum):
|
||||
EMAIL_AUTH = "email_auth"
|
||||
SMS_AUTH = "sms_auth"
|
||||
|
||||
|
||||
class ServiceStatus(StrEnum):
|
||||
LIVE = "live"
|
||||
TRIAL = "trial"
|
||||
SUSPENDED = "suspended"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from collections import Counter, OrderedDict
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
from functools import partial
|
||||
|
||||
@@ -11,7 +11,6 @@ from app import (
|
||||
organizations_client,
|
||||
service_api_client,
|
||||
)
|
||||
from app.enums import ServiceStatus
|
||||
from app.main import main
|
||||
from app.main.forms import (
|
||||
AdminBillingDetailsForm,
|
||||
@@ -68,25 +67,6 @@ 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)
|
||||
@@ -110,13 +90,15 @@ 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,
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -103,7 +103,11 @@ class Organization(JSONModel, SortByNameMixin):
|
||||
|
||||
@property
|
||||
def trial_services(self):
|
||||
return [s for s in self.services if not s["active"] or s["restricted"]]
|
||||
return [s for s in self.services if s["active"] and s["restricted"]]
|
||||
|
||||
@property
|
||||
def suspended_services(self):
|
||||
return [s for s in self.services if not s["active"]]
|
||||
|
||||
@cached_property
|
||||
def invited_users(self):
|
||||
|
||||
Reference in New Issue
Block a user