mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 17:45:32 -04:00
refactored live_services_csv
with the aim of making the link between api return values and csv column headers more apparent
This commit is contained in:
@@ -203,33 +203,33 @@ def platform_admin_reports():
|
|||||||
@user_is_platform_admin
|
@user_is_platform_admin
|
||||||
def live_services_csv():
|
def live_services_csv():
|
||||||
results = service_api_client.get_live_services_data()["data"]
|
results = service_api_client.get_live_services_data()["data"]
|
||||||
live_services_columns = [
|
|
||||||
"Service ID", "Organisation", "Organisation type", "Service name", "Consent to research", "Main contact",
|
column_names = OrderedDict([
|
||||||
"Contact email", "Contact mobile", "Live date", "SMS volume intent", "Email volume intent",
|
('service_id', 'Service ID'),
|
||||||
"Letter volume intent", "SMS sent this year", "Emails sent this year", "Letters sent this year"
|
('organisation_name', 'Organisation'),
|
||||||
]
|
('organisation_type', 'Organisation type'),
|
||||||
live_services_data = []
|
('service_name', 'Service name'),
|
||||||
live_services_data.append(live_services_columns)
|
('consent_to_research', 'Consent to research'),
|
||||||
|
('contact_name', 'Main contact'),
|
||||||
|
('contact_email', 'Contact email'),
|
||||||
|
('contact_mobile', 'Contact mobile'),
|
||||||
|
('live_date', 'Live date'),
|
||||||
|
('sms_volume_intent', 'SMS volume intent'),
|
||||||
|
('email_volume_intent', 'Email volume intent'),
|
||||||
|
('letter_volume_intent', 'Letter volume intent'),
|
||||||
|
('sms_totals', 'SMS sent this year'),
|
||||||
|
('email_totals', 'Emails sent this year'),
|
||||||
|
('letter_totals', 'Letters sent this year'),
|
||||||
|
])
|
||||||
|
|
||||||
|
# initialise with header row
|
||||||
|
live_services_data = [[x for x in column_names.values()]]
|
||||||
|
|
||||||
for row in results:
|
for row in results:
|
||||||
live_services_data.append([
|
if row['live_date']:
|
||||||
row["service_id"],
|
row['live_date'] = datetime.strptime(row["live_date"], '%a, %d %b %Y %X %Z').strftime("%d-%m-%Y")
|
||||||
row["organisation_name"],
|
|
||||||
row["organisation_type"],
|
live_services_data.append([row[api_key] for api_key in column_names.keys()])
|
||||||
row["service_name"],
|
|
||||||
row["consent_to_research"],
|
|
||||||
row["contact_name"],
|
|
||||||
row["contact_email"],
|
|
||||||
row["contact_mobile"],
|
|
||||||
datetime.strptime(
|
|
||||||
row["live_date"], '%a, %d %b %Y %X %Z'
|
|
||||||
).strftime("%d-%m-%Y") if row["live_date"] else None,
|
|
||||||
row["sms_volume_intent"],
|
|
||||||
row["email_volume_intent"],
|
|
||||||
row["letter_volume_intent"],
|
|
||||||
row["sms_totals"],
|
|
||||||
row["email_totals"],
|
|
||||||
row["letter_totals"],
|
|
||||||
])
|
|
||||||
|
|
||||||
return Spreadsheet.from_rows(live_services_data).as_csv_data, 200, {
|
return Spreadsheet.from_rows(live_services_data).as_csv_data, 200, {
|
||||||
'Content-Type': 'text/csv; charset=utf-8',
|
'Content-Type': 'text/csv; charset=utf-8',
|
||||||
|
|||||||
Reference in New Issue
Block a user