From 72b0637f926f3a8502da415937857cce650c056f Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 25 Jun 2018 16:29:40 +0100 Subject: [PATCH 1/2] Add the download activity link for notifications. This works locally for a long running request and a large number of messages. However I suspect that nginx may be timing out the request. I'd like to try this on staging. --- app/main/views/notifications.py | 4 +++- app/templates/views/notifications.html | 5 +++++ app/utils.py | 11 +++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/main/views/notifications.py b/app/main/views/notifications.py index ca27f94f0..7a03e7443 100644 --- a/app/main/views/notifications.py +++ b/app/main/views/notifications.py @@ -12,6 +12,7 @@ from flask import ( request, stream_with_context, url_for, + current_app ) from flask_login import login_required from notifications_python_client.errors import APIError @@ -178,7 +179,8 @@ def download_notifications_csv(service_id): page=request.args.get('page', 1), page_size=5000, format_for_csv=True, - template_type=filter_args.get('message_type') + template_type=filter_args.get('message_type'), + limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS'], ) ), mimetype='text/csv', diff --git a/app/templates/views/notifications.html b/app/templates/views/notifications.html index 1b47e8906..56e2be966 100644 --- a/app/templates/views/notifications.html +++ b/app/templates/views/notifications.html @@ -47,6 +47,11 @@ {% endif %} +

+ Download this report +   + Data available for 7 days +

{{ ajax_block( partials, url_for('.get_notifications_as_json', service_id=current_service.id, message_type=message_type, status=status, page=page), diff --git a/app/utils.py b/app/utils.py index 69c85c280..702aa58a5 100644 --- a/app/utils.py +++ b/app/utils.py @@ -149,13 +149,12 @@ def generate_notifications_csv(**kwargs): ] else: values = [ - notification['to'], - notification['template']['name'], - notification['template']['template_type'], - notification.get('job_name', None), + notification['recipient'], + notification['template_name'], + notification['template_type'], + notification['job_name'], notification['status'], - notification['created_at'], - notification['updated_at'] + notification['created_at'] ] yield Spreadsheet.from_rows([map(str, values)]).as_csv_data From 472f87b3255d177559778fa452cb747a58c93059 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 25 Jun 2018 16:57:49 +0100 Subject: [PATCH 2/2] Fix order of imports --- app/main/views/notifications.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main/views/notifications.py b/app/main/views/notifications.py index 7a03e7443..f17eb458f 100644 --- a/app/main/views/notifications.py +++ b/app/main/views/notifications.py @@ -7,12 +7,12 @@ from datetime import datetime from flask import ( Response, abort, + current_app, jsonify, render_template, request, stream_with_context, url_for, - current_app ) from flask_login import login_required from notifications_python_client.errors import APIError