mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
[WIP] Attempt at adding a form to the platform admin page is not working well for me here. But I want to commit it so I can look at it again.
This commit is contained in:
@@ -5,33 +5,62 @@ from flask import (
|
||||
request
|
||||
)
|
||||
from flask_login import login_required
|
||||
from wtforms import ValidationError
|
||||
|
||||
from app import service_api_client
|
||||
from app.main import main
|
||||
from app.main.forms import DateFilterForm
|
||||
from app.utils import user_has_permissions
|
||||
from app.statistics_utils import get_formatted_percentage
|
||||
|
||||
|
||||
@main.route("/platform-admin")
|
||||
@main.route("/platform-admin", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_has_permissions(admin_override=True)
|
||||
def platform_admin():
|
||||
form = DateFilterForm()
|
||||
include_from_test_key = request.args.get('include_from_test_key') != 'False'
|
||||
# specifically DO get inactive services
|
||||
api_args = {'detailed': True}
|
||||
if not include_from_test_key:
|
||||
api_args['include_from_test_key'] = False
|
||||
services = service_api_client.get_services(api_args)['data']
|
||||
return render_template(
|
||||
'views/platform-admin.html',
|
||||
include_from_test_key=include_from_test_key,
|
||||
**get_statistics(sorted(
|
||||
services,
|
||||
key=lambda service: (service['active'], service['created_at']),
|
||||
reverse=True
|
||||
))
|
||||
)
|
||||
if form.validate_on_submit():
|
||||
start_date = form.start_date.data
|
||||
end_date = form.end_date.data
|
||||
|
||||
if start_date:
|
||||
print(start_date)
|
||||
print(end_date)
|
||||
api_args['start_date'] = start_date
|
||||
if not end_date:
|
||||
raise ValidationError(message='requires end date', field =form.end_date)
|
||||
api_args['end_date'] = end_date
|
||||
|
||||
services = service_api_client.get_services(api_args)['data']
|
||||
|
||||
return render_template(
|
||||
'views/platform-admin.html',
|
||||
include_from_test_key=include_from_test_key,
|
||||
form=form,
|
||||
**get_statistics(sorted(
|
||||
services,
|
||||
key=lambda service: (service['active'], service['created_at']),
|
||||
reverse=True
|
||||
))
|
||||
)
|
||||
else:
|
||||
services = service_api_client.get_services(api_args)['data']
|
||||
|
||||
return render_template(
|
||||
'views/platform-admin.html',
|
||||
include_from_test_key=include_from_test_key,
|
||||
form=form,
|
||||
**get_statistics(sorted(
|
||||
services,
|
||||
key=lambda service: (service['active'], service['created_at']),
|
||||
reverse=True
|
||||
))
|
||||
)
|
||||
|
||||
def get_statistics(services):
|
||||
return {
|
||||
@@ -64,7 +93,6 @@ def create_global_stats(services):
|
||||
|
||||
for stat in stats.values():
|
||||
stat['failure_rate'] = get_formatted_percentage(stat['failed'], stat['requested'])
|
||||
|
||||
return stats
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user