mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
Working functionality for filtering notifications and all tests passing.
This commit is contained in:
@@ -9,6 +9,7 @@ from flask import (
|
||||
request
|
||||
)
|
||||
from flask_login import login_required
|
||||
from werkzeug.datastructures import MultiDict
|
||||
from utils.template import Template
|
||||
|
||||
from app import (job_api_client, notification_api_client, service_api_client)
|
||||
@@ -19,6 +20,17 @@ from app.utils import (
|
||||
user_has_permissions)
|
||||
|
||||
|
||||
def _parse_filter_args(filter_dict):
|
||||
if not isinstance(filter_dict, MultiDict):
|
||||
filter_dict = MultiDict(filter_dict)
|
||||
out_dict = MultiDict()
|
||||
if 'type' in filter_dict:
|
||||
out_dict.setlist('template_type', filter_dict.getlist('type'))
|
||||
if 'status' in filter_dict:
|
||||
out_dict.setlist('status', filter_dict.getlist('status'))
|
||||
return out_dict
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/jobs")
|
||||
@login_required
|
||||
@user_has_permissions('view_activity', admin_override=True)
|
||||
@@ -96,17 +108,31 @@ def view_notifications(service_id):
|
||||
page = get_page_from_request()
|
||||
if page is None:
|
||||
abort(404, "Invalid page argument ({}) reverting to page 1.".format(request.args['page'], None))
|
||||
notifications = notification_api_client.get_notifications_for_service(service_id=service_id, page=page)
|
||||
filter_args = _parse_filter_args(request.args)
|
||||
notifications = notification_api_client.get_notifications_for_service(
|
||||
service_id=service_id,
|
||||
page=page,
|
||||
template_type=filter_args.getlist('template_type') if 'template_type' in filter_args else None,
|
||||
status=filter_args.getlist('status') if 'status' in filter_args else None)
|
||||
view_dict = MultiDict(request.args)
|
||||
prev_page = None
|
||||
if notifications['links'].get('prev', None):
|
||||
prev_page = generate_previous_next_dict(
|
||||
'main.view_notifications',
|
||||
{'service_id': service_id}, page - 1, 'Previous page', 'page {}'.format(page - 1))
|
||||
service_id,
|
||||
view_dict,
|
||||
page - 1,
|
||||
'Previous page',
|
||||
'page {}'.format(page - 1))
|
||||
next_page = None
|
||||
if notifications['links'].get('next', None):
|
||||
next_page = generate_previous_next_dict(
|
||||
'main.view_notifications',
|
||||
{'service_id': service_id}, page + 1, 'Next page', 'page {}'.format(page + 1))
|
||||
service_id,
|
||||
view_dict,
|
||||
page + 1,
|
||||
'Next page',
|
||||
'page {}'.format(page + 1))
|
||||
return render_template(
|
||||
'views/notifications.html',
|
||||
service_id=service_id,
|
||||
|
||||
Reference in New Issue
Block a user