Change activity to view to request 7 days data.

Cleaned up filters a bit so that if you want both templates
email and sms is passed.

Added mock assertion to test.
This commit is contained in:
Adam Shimali
2016-04-28 15:50:05 +01:00
parent 5572058e50
commit a627cf9002
7 changed files with 94 additions and 19 deletions

View File

@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
import time
import itertools
from flask import (
render_template,
abort,
jsonify,
request,
url_for
url_for,
current_app
)
from flask_login import login_required
from werkzeug.datastructures import MultiDict
@@ -28,7 +28,6 @@ from app.utils import (
def _parse_filter_args(filter_dict):
if not isinstance(filter_dict, MultiDict):
filter_dict = MultiDict(filter_dict)
@@ -114,12 +113,15 @@ 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))
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 ['delivered', 'failed'])
template_type=filter_args.get('template_type') if 'template_type' in filter_args else ['email', 'sms'],
status=filter_args.get('status') if 'status' in filter_args else ['delivered', 'failed'],
limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS'])
view_dict = MultiDict(request.args)
prev_page = None
if notifications['links'].get('prev', None):
@@ -147,7 +149,8 @@ def view_notifications(service_id):
page_size=notifications['total'],
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 ['delivered', 'failed'])['notifications'])
if 'status' in filter_args else ['delivered', 'failed'],
limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS'])['notifications'])
return csv_content, 200, {
'Content-Type': 'text/csv; charset=utf-8',
'Content-Disposition': 'inline; filename="notifications.csv"'
@@ -168,14 +171,14 @@ def view_notifications(service_id):
)] for item in [
['Emails', 'email'],
['Text messages', 'sms'],
['Both', '']
['Both', 'email,sms']
]
],
status_filters=[
[item[0], item[1], url_for(
'.view_notifications',
service_id=current_service['id'],
template_type=request.args.get('template_type', ''),
template_type=request.args.get('template_type', 'email,sms'),
status=item[1]
)] for item in [
['Successful', 'delivered'],

View File

@@ -27,7 +27,8 @@ class NotificationApiClient(BaseAPIClient):
template_type=None,
status=None,
page=None,
page_size=None):
page_size=None,
limit_days=None):
params = {}
if page is not None:
params['page'] = page
@@ -43,6 +44,9 @@ class NotificationApiClient(BaseAPIClient):
params=params
)
else:
if limit_days is not None:
params['limit_days'] = limit_days
return self.get(
url='/service/{}/notifications'.format(service_id),
params=params

View File

@@ -4,7 +4,7 @@
</h2>
<ul>
{% if current_user.has_permissions(['view_activity'], admin_override=True) %}
<li><a href="{{ url_for('.view_notifications', service_id=current_service.id, status='delivered,failed') }}">Activity</a></li>
<li><a href="{{ url_for('.view_notifications', service_id=current_service.id, status='delivered,failed', template_type='email,sms') }}">Activity</a></li>
{% endif %}
{% if current_user.has_permissions(['view_activity', 'manage_templates', 'manage_api_keys'], admin_override=True, any_=True) %}
<li><a href="{{ url_for('.choose_template', service_id=current_service.id, template_type='email') }}">Email templates</a></li>

View File

@@ -45,7 +45,7 @@
{%- endif -%}
</h1>
<div class='grid-row bottom-gutter'>
<div class='column-half'>
{{ pill(