Add a page to view a single contact list

This commit is contained in:
Chris Hill-Scott
2020-03-13 16:58:43 +00:00
parent f15b9b8d38
commit aa85870ee1
6 changed files with 152 additions and 3 deletions

View File

@@ -1,5 +1,7 @@
from flask import abort, current_app
from notifications_utils.formatters import strip_whitespace
from notifications_utils.recipients import RecipientCSV
from werkzeug.utils import cached_property
from app.models import JSONModel
from app.notify_client.contact_list_api_client import contact_list_api_client
@@ -13,6 +15,24 @@ from app.s3_client.s3_csv_client import (
class ContactList(JSONModel):
ALLOWED_PROPERTIES = {
'id',
'created_at',
'created_by',
'service_id',
'original_file_name',
'row_count',
'template_type',
}
@classmethod
def from_id(cls, contact_list_id, *, service_id):
# This is temporary until we have a get single list endpoint
for contact_list in contact_list_api_client.get_contact_lists(service_id):
if contact_list['id'] == contact_list_id:
return cls(contact_list)
abort(404)
@staticmethod
def get_bucket_name():
return current_app.config['CONTACT_LIST_UPLOAD_BUCKET_NAME']
@@ -82,3 +102,12 @@ class ContactList(JSONModel):
row_count=int(metadata['row_count']),
template_type=metadata['template_type'],
))
@cached_property
def recipients(self):
return RecipientCSV(
self.download(self.service_id, self.id),
template_type=self.template_type,
international_sms=True,
max_initial_rows_shown=50,
)