mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-24 20:31:19 -05: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,
|
||||
current_app,
|
||||
redirect,
|
||||
Response
|
||||
Response,
|
||||
stream_with_context
|
||||
)
|
||||
from flask_login import login_required
|
||||
from werkzeug.datastructures import MultiDict
|
||||
@@ -96,7 +97,6 @@ def view_jobs(service_id):
|
||||
@user_has_permissions('view_activity', admin_override=True)
|
||||
def view_job(service_id, job_id):
|
||||
job = job_api_client.get_job(service_id, job_id)['data']
|
||||
|
||||
if job['job_status'] == 'cancelled':
|
||||
abort(404)
|
||||
|
||||
@@ -144,19 +144,22 @@ def view_job_csv(service_id, job_id):
|
||||
filter_args['status'] = _set_status_filters(filter_args)
|
||||
|
||||
return Response(
|
||||
generate_notifications_csv(
|
||||
service_id=service_id,
|
||||
job_id=job_id,
|
||||
status=filter_args.get('status'),
|
||||
page=request.args.get('page', 1),
|
||||
page_size=5000
|
||||
stream_with_context(
|
||||
generate_notifications_csv(
|
||||
service_id=service_id,
|
||||
job_id=job_id,
|
||||
status=filter_args.get('status'),
|
||||
page=request.args.get('page', 1),
|
||||
page_size=5000
|
||||
)
|
||||
),
|
||||
mimetype='text/csv',
|
||||
headers={
|
||||
'Content-Disposition': 'inline; filename="{} - {}.csv"'.format(
|
||||
template['name'],
|
||||
format_datetime_short(job['created_at'])
|
||||
)}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ class JobApiClient(NotifyAdminAPIClient):
|
||||
def get_job(self, service_id, job_id):
|
||||
params = {}
|
||||
job = self.get(url='/service/{}/job/{}'.format(service_id, job_id), params=params)
|
||||
|
||||
stats = self.__convert_statistics(job['data'])
|
||||
job['data']['notifications_sent'] = stats['delivered'] + stats['failed']
|
||||
job['data']['notifications_delivered'] = stats['delivered']
|
||||
|
||||
@@ -155,6 +155,8 @@ def generate_notifications_csv(**kwargs):
|
||||
|
||||
while kwargs['page']:
|
||||
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']
|
||||
for x in notifications_list:
|
||||
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_num = notification.get('job_row_number')
|
||||
row_num = '' if row_num is None else row_num + 1
|
||||
current_app.logger.info('Row number for job: {}'.format(row_num))
|
||||
|
||||
return {
|
||||
'Row number': row_num,
|
||||
|
||||
Reference in New Issue
Block a user