From 032ce6960b7f50a6f9fc21083bdf1258679ca5ef Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 16 Feb 2018 12:34:59 +0000 Subject: [PATCH] Refactor to not repeat loop and variables This commit just cleans up the code a bit to: - have less duplication - do less assignment of single-use variables --- app/utils.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/app/utils.py b/app/utils.py index 761b2f608..9568aea23 100644 --- a/app/utils.py +++ b/app/utils.py @@ -141,27 +141,21 @@ def generate_notifications_csv(**kwargs): while kwargs['page']: notifications_resp = notification_api_client.get_notifications_for_service(**kwargs) - notifications = notifications_resp['notifications'] - - if kwargs.get('job_id'): - for notification in notifications: - original_row = original_upload[notification['row_number'] - 1] + for notification in notifications_resp['notifications']: + if kwargs.get('job_id'): values = [ notification['row_number'], ] + [ - original_row.get(header) + original_upload[notification['row_number'] - 1].get(header) for header in original_column_headers ] + [ notification['template_name'], notification['template_type'], notification['job_name'], notification['status'], - notification['created_at'] + notification['created_at'], ] - yield ','.join(map(str, values)) + '\n' - else: - # Change here - for notification in notifications: + else: values = [ notification['to'], notification['template']['name'], @@ -171,8 +165,8 @@ def generate_notifications_csv(**kwargs): notification['created_at'], notification['updated_at'] ] - line = ','.join(str(i) for i in values) + '\n' - yield line + yield ','.join(map(str, values)) + '\n' + if notifications_resp['links'].get('next'): kwargs['page'] += 1 else: