Add an endpoint to download a contact list

In case you need to download it, modify it, and re-upload it when you
don’t have access to the existing list.
This commit is contained in:
Chris Hill-Scott
2020-03-15 19:13:07 +00:00
parent ec2f36d054
commit b598af1eca
5 changed files with 66 additions and 3 deletions

View File

@@ -1,3 +1,5 @@
from os import path
from flask import abort, current_app
from notifications_utils.formatters import strip_whitespace
from notifications_utils.recipients import RecipientCSV
@@ -103,15 +105,24 @@ class ContactList(JSONModel):
template_type=metadata['template_type'],
))
@property
def contents(self):
return self.download(self.service_id, self.id)
@cached_property
def recipients(self):
return RecipientCSV(
self.download(self.service_id, self.id),
self.contents,
template_type=self.template_type,
international_sms=True,
max_initial_rows_shown=50,
)
@property
def saved_file_name(self):
file_name, extention = path.splitext(self.original_file_name)
return f'{file_name}.csv'
class ContactLists(ModelList):
client_method = contact_list_api_client.get_contact_lists