mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
Merge pull request #1067 from alphagov/add-date-range-filter-to-platform-admin
Add date range filter to platform admin
This commit is contained in:
@@ -16,8 +16,8 @@ from wtforms import (
|
||||
HiddenField,
|
||||
IntegerField,
|
||||
RadioField,
|
||||
FieldList
|
||||
)
|
||||
FieldList,
|
||||
DateField)
|
||||
from wtforms.fields.html5 import EmailField, TelField
|
||||
from wtforms.validators import (DataRequired, Email, Length, Regexp, Optional)
|
||||
|
||||
@@ -516,3 +516,9 @@ class Whitelist(Form):
|
||||
max_entries=5,
|
||||
label="Mobile numbers"
|
||||
)
|
||||
|
||||
|
||||
class DateFilterForm(Form):
|
||||
start_date = DateField("Start Date", [validators.optional()])
|
||||
end_date = DateField("End Date", [validators.optional()])
|
||||
include_from_test_key = BooleanField("Include test keys", default="checked", false_values={"N"})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import itertools
|
||||
|
||||
from datetime import datetime
|
||||
from flask import (
|
||||
render_template,
|
||||
request
|
||||
@@ -8,6 +9,7 @@ from flask_login import login_required
|
||||
|
||||
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
|
||||
|
||||
@@ -16,15 +18,21 @@ from app.statistics_utils import get_formatted_percentage
|
||||
@login_required
|
||||
@user_has_permissions(admin_override=True)
|
||||
def platform_admin():
|
||||
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
|
||||
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 = service_api_client.get_services(api_args)['data']
|
||||
|
||||
return render_template(
|
||||
'views/platform-admin.html',
|
||||
include_from_test_key=include_from_test_key,
|
||||
include_from_test_key=form.include_from_test_key.data,
|
||||
form=form,
|
||||
**get_statistics(sorted(
|
||||
services,
|
||||
key=lambda service: (service['active'], service['created_at']),
|
||||
@@ -64,7 +72,6 @@ def create_global_stats(services):
|
||||
|
||||
for stat in stats.values():
|
||||
stat['failure_rate'] = get_formatted_percentage(stat['failed'], stat['requested'])
|
||||
|
||||
return stats
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
{% extends "withoutnav_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% from "components/checkbox.html" import checkbox %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
{% from "components/big-number.html" import big_number, big_number_with_status %}
|
||||
{% from "components/message-count-label.html" import message_count_label %}
|
||||
{% from "components/table.html" import mapping_table, field, stats_fields, row_group, row, right_aligned_field_heading, hidden_field_heading, text_field %}
|
||||
@@ -87,14 +90,16 @@
|
||||
Platform admin
|
||||
</h1>
|
||||
|
||||
<p class="bottom-gutter-2">
|
||||
Showing stats for today 
|
||||
{% if include_from_test_key %}
|
||||
Including test keys (<a href="{{ url_for('.platform_admin', include_from_test_key=False) }}">change</a>)
|
||||
{% else %}
|
||||
Excluding test keys (<a href="{{ url_for('.platform_admin') }}">change</a>)
|
||||
{% endif %}
|
||||
</p>
|
||||
<details>
|
||||
<summary>Apply filters</summary>
|
||||
<form autocomplete="off" method="get">
|
||||
{{ textbox(form.start_date, hint="Enter start date in format YYYY-MM-DD") }}
|
||||
{{ textbox(form.end_date, hint="Enter end date in format YYYY-MM-DD") }}
|
||||
{{ checkbox(form.include_from_test_key) }}
|
||||
</br>
|
||||
<input type="submit" class="button">
|
||||
</form>
|
||||
</details>
|
||||
|
||||
<div class="grid-row bottom-gutter">
|
||||
<div class="column-half">
|
||||
|
||||
Reference in New Issue
Block a user