mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 16:24:08 -04:00
Add date filter for platform admin page.
This commit is contained in:
@@ -516,3 +516,8 @@ class Whitelist(Form):
|
|||||||
max_entries=5,
|
max_entries=5,
|
||||||
label="Mobile numbers"
|
label="Mobile numbers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class DateFilterForm(Form):
|
||||||
|
start_date = DateField("Start Date", [validators.optional()])
|
||||||
|
end_date = StringField("End Date", [validators.optional()])
|
||||||
|
include_from_test_key = BooleanField("Include test keys", default='checked')
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from flask import (
|
from flask import (
|
||||||
render_template,
|
render_template,
|
||||||
request
|
request
|
||||||
@@ -8,6 +9,7 @@ from flask_login import login_required
|
|||||||
|
|
||||||
from app import service_api_client
|
from app import service_api_client
|
||||||
from app.main import main
|
from app.main import main
|
||||||
|
from app.main.forms import DateFilterForm
|
||||||
from app.utils import user_has_permissions
|
from app.utils import user_has_permissions
|
||||||
from app.statistics_utils import get_formatted_percentage
|
from app.statistics_utils import get_formatted_percentage
|
||||||
|
|
||||||
@@ -16,9 +18,10 @@ from app.statistics_utils import get_formatted_percentage
|
|||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions(admin_override=True)
|
@user_has_permissions(admin_override=True)
|
||||||
def platform_admin():
|
def platform_admin():
|
||||||
include_from_test_key = request.args.get('include_from_test_key') != 'False'
|
form = DateFilterForm(request.args)
|
||||||
start_date = request.args.get('start_date', None)
|
include_from_test_key = form.include_from_test_key.data
|
||||||
end_date = request.args.get('end_date', None)
|
start_date = form.start_date.data
|
||||||
|
end_date = form.end_date.data
|
||||||
# specifically DO get inactive services
|
# specifically DO get inactive services
|
||||||
api_args = {'detailed': True}
|
api_args = {'detailed': True}
|
||||||
if not include_from_test_key:
|
if not include_from_test_key:
|
||||||
@@ -29,13 +32,14 @@ def platform_admin():
|
|||||||
# but I could get the validation right, not did the page look good.
|
# but I could get the validation right, not did the page look good.
|
||||||
# This is just an intermediate pass at returning the data.
|
# This is just an intermediate pass at returning the data.
|
||||||
api_args['start_date'] = start_date
|
api_args['start_date'] = start_date
|
||||||
api_args['end_date'] = end_date
|
api_args['end_date'] = end_date or datetime.utcnow().date()
|
||||||
|
|
||||||
services = service_api_client.get_services(api_args)['data']
|
services = service_api_client.get_services(api_args)['data']
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/platform-admin.html',
|
'views/platform-admin.html',
|
||||||
include_from_test_key=include_from_test_key,
|
include_from_test_key=include_from_test_key,
|
||||||
|
form=form,
|
||||||
**get_statistics(sorted(
|
**get_statistics(sorted(
|
||||||
services,
|
services,
|
||||||
key=lambda service: (service['active'], service['created_at']),
|
key=lambda service: (service['active'], service['created_at']),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{% extends "withoutnav_template.html" %}
|
{% extends "withoutnav_template.html" %}
|
||||||
{% from "components/textbox.html" import textbox %}
|
{% from "components/textbox.html" import textbox %}
|
||||||
|
{% from "components/checkbox.html" import checkbox %}
|
||||||
{% from "components/page-footer.html" import page_footer %}
|
{% from "components/page-footer.html" import page_footer %}
|
||||||
{% from "components/big-number.html" import big_number, big_number_with_status %}
|
{% from "components/big-number.html" import big_number, big_number_with_status %}
|
||||||
{% from "components/message-count-label.html" import message_count_label %}
|
{% from "components/message-count-label.html" import message_count_label %}
|
||||||
@@ -89,14 +90,16 @@
|
|||||||
Platform admin
|
Platform admin
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<p class="bottom-gutter-2">
|
<details>
|
||||||
Showing stats for today 
|
<summary>Apply filters</summary>
|
||||||
{% if include_from_test_key %}
|
<form autocomplete="off" method="get">
|
||||||
Including test keys (<a href="{{ url_for('.platform_admin', include_from_test_key=False) }}">change</a>)
|
{{ textbox(form.start_date, hint="Enter start date in format YYYY-MM-DD") }}
|
||||||
{% else %}
|
{{ textbox(form.end_date, hint="Enter end date in format YYYY-MM-DD") }}
|
||||||
Excluding test keys (<a href="{{ url_for('.platform_admin') }}">change</a>)
|
{{ checkbox(form.include_from_test_key) }}
|
||||||
{% endif %}
|
</br>
|
||||||
</p>
|
<input type="submit" class="button">
|
||||||
|
</form>
|
||||||
|
</details>
|
||||||
|
|
||||||
<div class="grid-row bottom-gutter">
|
<div class="grid-row bottom-gutter">
|
||||||
<div class="column-half">
|
<div class="column-half">
|
||||||
|
|||||||
Reference in New Issue
Block a user