mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 19:03:30 -05: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:
@@ -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,16 @@ class Whitelist(Form):
|
||||
max_entries=5,
|
||||
label="Mobile numbers"
|
||||
)
|
||||
|
||||
|
||||
class DateFilterForm(Form):
|
||||
start_date = DateField("Start Date", [validators.optional()])
|
||||
end_date = StringField("End Date", [validators.optional()])
|
||||
|
||||
def validate(self):
|
||||
print("****In validate")
|
||||
if self.start_date.data and not self.end_date.data:
|
||||
print("***** false {}".format(type(self.end_date.errors)))
|
||||
raise ValidationError('Both required')
|
||||
else:
|
||||
return True
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
||||
"""
|
||||
Retrieve a list of services.
|
||||
"""
|
||||
print(params_dict)
|
||||
return self.get('/service', params=params_dict)
|
||||
|
||||
def get_active_services(self, params_dict=None):
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
{% extends "withoutnav_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% 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 %}
|
||||
@@ -94,6 +96,11 @@
|
||||
{% else %}
|
||||
Excluding test keys (<a href="{{ url_for('.platform_admin') }}">change</a>)
|
||||
{% endif %}
|
||||
<form autocomplete="off" method="post">
|
||||
{{ 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") }}
|
||||
{{ page_footer('Apply filter') }}
|
||||
</form>
|
||||
</p>
|
||||
|
||||
<div class="grid-row bottom-gutter">
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
from datetime import date
|
||||
|
||||
from flask import url_for
|
||||
from freezegun import freeze_time
|
||||
import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from tests.conftest import mock_get_user
|
||||
from tests import service_json
|
||||
|
||||
from app.main.views.platform_admin import get_statistics, format_stats_by_service, create_global_stats
|
||||
from app.main.views.platform_admin import format_stats_by_service, create_global_stats
|
||||
|
||||
|
||||
def test_should_redirect_if_not_logged_in(app_):
|
||||
|
||||
Reference in New Issue
Block a user