mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 13:39:41 -04:00
Add a page to view a single contact list
This commit is contained in:
@@ -433,4 +433,7 @@ def save_contact_list(service_id, upload_id):
|
||||
@main.route("/services/<uuid:service_id>/contact-list/<uuid:contact_list_id>", methods=['GET'])
|
||||
@user_has_permissions('send_messages')
|
||||
def contact_list(service_id, contact_list_id):
|
||||
return 'page for contact list {}'.format(contact_list_id)
|
||||
return render_template(
|
||||
'views/uploads/contact-list/contact-list.html',
|
||||
contact_list=ContactList.from_id(contact_list_id, service_id=service_id),
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -24,5 +24,8 @@ class ContactListApiClient(NotifyAdminAPIClient):
|
||||
|
||||
return job
|
||||
|
||||
def get_contact_lists(self, service_id):
|
||||
return self.get('/service/{}/contact-list'.format(service_id))
|
||||
|
||||
|
||||
contact_list_api_client = ContactListApiClient()
|
||||
|
||||
47
app/templates/views/uploads/contact-list/contact-list.html
Normal file
47
app/templates/views/uploads/contact-list/contact-list.html
Normal file
@@ -0,0 +1,47 @@
|
||||
{% extends "withnav_template.html" %}
|
||||
{% from "components/banner.html" import banner_wrapper %}
|
||||
{% from "components/radios.html" import radio_select %}
|
||||
{% from "components/table.html" import list_table, field, text_field, index_field, hidden_field_heading %}
|
||||
{% from "components/page-header.html" import page_header %}
|
||||
{% from "components/message-count-label.html" import message_count_label, recipient_count_label %}
|
||||
{% from "components/button/macro.njk" import govukButton %}
|
||||
|
||||
{% block service_page_title %}
|
||||
{{ contact_list.original_file_name }}
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
{{ page_header(
|
||||
contact_list.original_file_name,
|
||||
back_link=url_for('main.uploads', service_id=current_service.id)
|
||||
) }}
|
||||
|
||||
<p class="govuk-body">
|
||||
Uploaded by {{ contact_list.created_by }} {{ contact_list.created_at|format_datetime_human }}
|
||||
</p>
|
||||
|
||||
<p class="govuk-body">
|
||||
{{ contact_list.recipients|length|format_thousands }}
|
||||
{{ recipient_count_label(contact_list.recipients|length, contact_list.recipients.template_type) }}
|
||||
</p>
|
||||
|
||||
{% set recipient_column = contact_list.recipients.column_headers[0] %}
|
||||
|
||||
{% call(item, row_number) list_table(
|
||||
contact_list.recipients.displayed_rows,
|
||||
caption=recipient_count_label(contact_list.recipients|length, contact_list.template_type)|capitalize,
|
||||
caption_visible=False,
|
||||
field_headings=['1', recipient_column],
|
||||
) %}
|
||||
{{ index_field(row_number) }}
|
||||
{{ text_field(item[recipient_column].data) }}
|
||||
{% endcall %}
|
||||
|
||||
{% if contact_list.recipients.displayed_rows|list|length < contact_list.recipients|length %}
|
||||
<p class="table-show-more-link">
|
||||
Only showing the first {{ contact_list.recipients.displayed_rows|list|length }} rows
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user