mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-17 04:59:37 -04:00
Add separate pages to view live/trial services
We have a lot of services now. Mostly we want to look at what live services are doing. So loading up the trial mode services every time slows things – generating, rendering and using the page – right down. This commit adds two new pages, one to view only live services, and one to view trial mode services.
This commit is contained in:
@@ -41,6 +41,37 @@ def platform_admin():
|
||||
)
|
||||
|
||||
|
||||
@main.route("/platform-admin/live-services", endpoint='live_services')
|
||||
@main.route("/platform-admin/trial-services", endpoint='trial_services')
|
||||
@login_required
|
||||
@user_has_permissions(admin_override=True)
|
||||
def platform_admin_services():
|
||||
form = DateFilterForm(request.args)
|
||||
api_args = {'detailed': True, # specifically DO get inactive services
|
||||
'include_from_test_key': form.include_from_test_key.data
|
||||
}
|
||||
|
||||
if form.start_date.data:
|
||||
api_args['start_date'] = form.start_date.data
|
||||
api_args['end_date'] = form.end_date.data or datetime.utcnow().date()
|
||||
|
||||
services = filter_and_sort_services(
|
||||
service_api_client.get_services(api_args)['data'],
|
||||
trial_mode_services=request.endpoint == 'main.trial_services',
|
||||
)
|
||||
|
||||
return render_template(
|
||||
'views/platform-admin/services.html',
|
||||
include_from_test_key=form.include_from_test_key.data,
|
||||
form=form,
|
||||
services=list(format_stats_by_service(services)),
|
||||
page_title='{} services'.format(
|
||||
'Trial mode' if request.endpoint == 'main.trial_services' else 'Live'
|
||||
),
|
||||
global_stats=create_global_stats(services),
|
||||
)
|
||||
|
||||
|
||||
def sum_service_usage(service):
|
||||
total = 0
|
||||
for notification_type in service['statistics'].keys():
|
||||
@@ -60,6 +91,21 @@ def get_statistics(services):
|
||||
}
|
||||
|
||||
|
||||
def filter_and_sort_services(services, trial_mode_services=False):
|
||||
return (
|
||||
service for service in sorted(
|
||||
services,
|
||||
key=lambda service: (
|
||||
service['active'],
|
||||
sum_service_usage(service),
|
||||
service['created_at']
|
||||
),
|
||||
reverse=True,
|
||||
)
|
||||
if service['restricted'] == trial_mode_services
|
||||
)
|
||||
|
||||
|
||||
def create_global_stats(services):
|
||||
stats = {
|
||||
'email': {
|
||||
|
||||
Reference in New Issue
Block a user