diff --git a/app/main/forms.py b/app/main/forms.py index 1a4c577f7..9e96a8ccc 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -516,16 +516,3 @@ 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 diff --git a/app/main/views/platform_admin.py b/app/main/views/platform_admin.py index 6c5fb8f06..70f598efb 100644 --- a/app/main/views/platform_admin.py +++ b/app/main/views/platform_admin.py @@ -5,62 +5,44 @@ 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", methods=['GET', 'POST']) +@main.route("/platform-admin") @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' + start_date = request.args.get('start_date', None) + end_date = request.args.get('end_date', None) # specifically DO get inactive services api_args = {'detailed': True} if not include_from_test_key: api_args['include_from_test_key'] = False - 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 + if start_date: + # For now the start and end date are only set as query params. The previous commit added a form + # but I could get the validation right, not did the page look good. + # This is just an intermediate pass at returning the data. + api_args['start_date'] = start_date + api_args['end_date'] = end_date - services = service_api_client.get_services(api_args)['data'] + 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, + **get_statistics(sorted( + services, + key=lambda service: (service['active'], service['created_at']), + reverse=True + )) + ) - 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 { diff --git a/app/templates/views/platform-admin.html b/app/templates/views/platform-admin.html index b5a94cd10..6147edaa3 100644 --- a/app/templates/views/platform-admin.html +++ b/app/templates/views/platform-admin.html @@ -96,11 +96,6 @@ {% else %} Excluding test keys (change) {% endif %} -