mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 10:28:41 -04:00
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
This commit is contained in:
+7
-13
@@ -141,27 +141,21 @@ 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)
|
||||||
notifications = notifications_resp['notifications']
|
for notification in notifications_resp['notifications']:
|
||||||
|
if kwargs.get('job_id'):
|
||||||
if kwargs.get('job_id'):
|
|
||||||
for notification in notifications:
|
|
||||||
original_row = original_upload[notification['row_number'] - 1]
|
|
||||||
values = [
|
values = [
|
||||||
notification['row_number'],
|
notification['row_number'],
|
||||||
] + [
|
] + [
|
||||||
original_row.get(header)
|
original_upload[notification['row_number'] - 1].get(header)
|
||||||
for header in original_column_headers
|
for header in original_column_headers
|
||||||
] + [
|
] + [
|
||||||
notification['template_name'],
|
notification['template_name'],
|
||||||
notification['template_type'],
|
notification['template_type'],
|
||||||
notification['job_name'],
|
notification['job_name'],
|
||||||
notification['status'],
|
notification['status'],
|
||||||
notification['created_at']
|
notification['created_at'],
|
||||||
]
|
]
|
||||||
yield ','.join(map(str, values)) + '\n'
|
else:
|
||||||
else:
|
|
||||||
# Change here
|
|
||||||
for notification in notifications:
|
|
||||||
values = [
|
values = [
|
||||||
notification['to'],
|
notification['to'],
|
||||||
notification['template']['name'],
|
notification['template']['name'],
|
||||||
@@ -171,8 +165,8 @@ def generate_notifications_csv(**kwargs):
|
|||||||
notification['created_at'],
|
notification['created_at'],
|
||||||
notification['updated_at']
|
notification['updated_at']
|
||||||
]
|
]
|
||||||
line = ','.join(str(i) for i in values) + '\n'
|
yield ','.join(map(str, values)) + '\n'
|
||||||
yield line
|
|
||||||
if notifications_resp['links'].get('next'):
|
if notifications_resp['links'].get('next'):
|
||||||
kwargs['page'] += 1
|
kwargs['page'] += 1
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user