mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Merge pull request #1184 from alphagov/tmp-add-logging-for-report-download
Add temporary logging for job report download
This commit is contained in:
@@ -13,7 +13,8 @@ from flask import (
|
|||||||
url_for,
|
url_for,
|
||||||
current_app,
|
current_app,
|
||||||
redirect,
|
redirect,
|
||||||
Response
|
Response,
|
||||||
|
stream_with_context
|
||||||
)
|
)
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
from werkzeug.datastructures import MultiDict
|
from werkzeug.datastructures import MultiDict
|
||||||
@@ -96,7 +97,6 @@ def view_jobs(service_id):
|
|||||||
@user_has_permissions('view_activity', admin_override=True)
|
@user_has_permissions('view_activity', admin_override=True)
|
||||||
def view_job(service_id, job_id):
|
def view_job(service_id, job_id):
|
||||||
job = job_api_client.get_job(service_id, job_id)['data']
|
job = job_api_client.get_job(service_id, job_id)['data']
|
||||||
|
|
||||||
if job['job_status'] == 'cancelled':
|
if job['job_status'] == 'cancelled':
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
@@ -144,19 +144,22 @@ def view_job_csv(service_id, job_id):
|
|||||||
filter_args['status'] = _set_status_filters(filter_args)
|
filter_args['status'] = _set_status_filters(filter_args)
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
generate_notifications_csv(
|
stream_with_context(
|
||||||
service_id=service_id,
|
generate_notifications_csv(
|
||||||
job_id=job_id,
|
service_id=service_id,
|
||||||
status=filter_args.get('status'),
|
job_id=job_id,
|
||||||
page=request.args.get('page', 1),
|
status=filter_args.get('status'),
|
||||||
page_size=5000
|
page=request.args.get('page', 1),
|
||||||
|
page_size=5000
|
||||||
|
)
|
||||||
),
|
),
|
||||||
mimetype='text/csv',
|
mimetype='text/csv',
|
||||||
headers={
|
headers={
|
||||||
'Content-Disposition': 'inline; filename="{} - {}.csv"'.format(
|
'Content-Disposition': 'inline; filename="{} - {}.csv"'.format(
|
||||||
template['name'],
|
template['name'],
|
||||||
format_datetime_short(job['created_at'])
|
format_datetime_short(job['created_at'])
|
||||||
)}
|
)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class JobApiClient(NotifyAdminAPIClient):
|
|||||||
def get_job(self, service_id, job_id):
|
def get_job(self, service_id, job_id):
|
||||||
params = {}
|
params = {}
|
||||||
job = self.get(url='/service/{}/job/{}'.format(service_id, job_id), params=params)
|
job = self.get(url='/service/{}/job/{}'.format(service_id, job_id), params=params)
|
||||||
|
|
||||||
stats = self.__convert_statistics(job['data'])
|
stats = self.__convert_statistics(job['data'])
|
||||||
job['data']['notifications_sent'] = stats['delivered'] + stats['failed']
|
job['data']['notifications_sent'] = stats['delivered'] + stats['failed']
|
||||||
job['data']['notifications_delivered'] = stats['delivered']
|
job['data']['notifications_delivered'] = stats['delivered']
|
||||||
|
|||||||
@@ -155,6 +155,8 @@ def generate_notifications_csv(**kwargs):
|
|||||||
|
|
||||||
while kwargs['page']:
|
while kwargs['page']:
|
||||||
notifications_resp = notification_api_client.get_notifications_for_service(**kwargs)
|
notifications_resp = notification_api_client.get_notifications_for_service(**kwargs)
|
||||||
|
current_app.logger.info('Total notifications for csv job: {}'.format(notifications_resp['total']))
|
||||||
|
current_app.logger.info('Notification response links: {}'.format(notifications_resp['links']))
|
||||||
notifications_list = notifications_resp['notifications']
|
notifications_list = notifications_resp['notifications']
|
||||||
for x in notifications_list:
|
for x in notifications_list:
|
||||||
csvwriter.writerow(format_notification_for_csv(x))
|
csvwriter.writerow(format_notification_for_csv(x))
|
||||||
@@ -174,6 +176,7 @@ def format_notification_for_csv(notification):
|
|||||||
# row_number can be 0 so we need to check for it
|
# row_number can be 0 so we need to check for it
|
||||||
row_num = notification.get('job_row_number')
|
row_num = notification.get('job_row_number')
|
||||||
row_num = '' if row_num is None else row_num + 1
|
row_num = '' if row_num is None else row_num + 1
|
||||||
|
current_app.logger.info('Row number for job: {}'.format(row_num))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'Row number': row_num,
|
'Row number': row_num,
|
||||||
|
|||||||
Reference in New Issue
Block a user