mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
Show an example of a CSV on the ‘send’ page
This should help: - understanding of what the CSV should contain - understanding what ‘download example’ will do
This commit is contained in:
@@ -49,15 +49,17 @@ def get_page_headings(template_type):
|
|||||||
}[template_type]
|
}[template_type]
|
||||||
|
|
||||||
|
|
||||||
def get_example_csv_rows(template):
|
def get_example_csv_rows(template, number_of_rows=2):
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
'email': current_user.email_address,
|
'email': current_user.email_address,
|
||||||
'sms': current_user.mobile_number
|
'sms': current_user.mobile_number
|
||||||
}[template.template_type]
|
}[template.template_type]
|
||||||
] + _get_fake_personalisation(template.placeholders, i)
|
] + [
|
||||||
for i in range(1, 3)
|
"{} {}".format(header, i) for header in template.placeholders
|
||||||
|
]
|
||||||
|
for i in range(1, number_of_rows + 1)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -135,6 +137,7 @@ def send_messages(service_id, template_id):
|
|||||||
'views/send.html',
|
'views/send.html',
|
||||||
template=template,
|
template=template,
|
||||||
recipient_column=first_column_heading[template.template_type],
|
recipient_column=first_column_heading[template.template_type],
|
||||||
|
example=get_example_csv_rows(template),
|
||||||
form=form,
|
form=form,
|
||||||
service=service,
|
service=service,
|
||||||
service_id=service_id
|
service_id=service_id
|
||||||
@@ -144,7 +147,7 @@ def send_messages(service_id, template_id):
|
|||||||
@main.route("/services/<service_id>/send/<template_id>.csv", methods=['GET'])
|
@main.route("/services/<service_id>/send/<template_id>.csv", methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
@user_has_permissions('send_texts', 'send_emails', 'send_letters', 'manage_templates', any_=True)
|
@user_has_permissions('send_texts', 'send_emails', 'send_letters', 'manage_templates', any_=True)
|
||||||
def get_example_csv(service_id, template_id):
|
def get_example_csv(service_id, template_id, number_of_rows=2):
|
||||||
template = Template(service_api_client.get_service_template(service_id, template_id)['data'])
|
template = Template(service_api_client.get_service_template(service_id, template_id)['data'])
|
||||||
with io.StringIO() as output:
|
with io.StringIO() as output:
|
||||||
writer = csv.writer(output)
|
writer = csv.writer(output)
|
||||||
@@ -153,7 +156,7 @@ def get_example_csv(service_id, template_id):
|
|||||||
[first_column_heading[template.template_type]] +
|
[first_column_heading[template.template_type]] +
|
||||||
list(template.placeholders)
|
list(template.placeholders)
|
||||||
] +
|
] +
|
||||||
get_example_csv_rows(template)
|
get_example_csv_rows(template, number_of_rows=number_of_rows)
|
||||||
)
|
)
|
||||||
return output.getvalue(), 200, {'Content-Type': 'text/csv; charset=utf-8'}
|
return output.getvalue(), 200, {'Content-Type': 'text/csv; charset=utf-8'}
|
||||||
|
|
||||||
@@ -164,25 +167,10 @@ def get_example_csv(service_id, template_id):
|
|||||||
def send_message_to_self(service_id, template_id):
|
def send_message_to_self(service_id, template_id):
|
||||||
template = Template(service_api_client.get_service_template(service_id, template_id)['data'])
|
template = Template(service_api_client.get_service_template(service_id, template_id)['data'])
|
||||||
|
|
||||||
with io.StringIO() as output:
|
filedata = {
|
||||||
writer = csv.writer(output)
|
'file_name': 'Test run',
|
||||||
writer.writerow(
|
'data': get_example_csv(service_id, template_id, number_of_rows=1)[0]
|
||||||
[first_column_heading[template.template_type]] +
|
}
|
||||||
list(template.placeholders)
|
|
||||||
)
|
|
||||||
if template.template_type == 'sms':
|
|
||||||
writer.writerow(
|
|
||||||
[current_user.mobile_number] + _get_fake_personalisation(template.placeholders, 1)
|
|
||||||
)
|
|
||||||
if template.template_type == 'email':
|
|
||||||
writer.writerow(
|
|
||||||
[current_user.email_address] + _get_fake_personalisation(template.placeholders, 1)
|
|
||||||
)
|
|
||||||
|
|
||||||
filedata = {
|
|
||||||
'file_name': 'Test run',
|
|
||||||
'data': output.getvalue()
|
|
||||||
}
|
|
||||||
|
|
||||||
upload_id = str(uuid.uuid4())
|
upload_id = str(uuid.uuid4())
|
||||||
|
|
||||||
@@ -302,9 +290,3 @@ def start_job(service_id, upload_id):
|
|||||||
return redirect(
|
return redirect(
|
||||||
url_for('main.view_job', service_id=service_id, job_id=upload_id)
|
url_for('main.view_job', service_id=service_id, job_id=upload_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _get_fake_personalisation(placeholders, index):
|
|
||||||
return [
|
|
||||||
"{} {}".format(header, index) for header in placeholders
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
{% from "components/email-message.html" import email_message %}
|
{% from "components/email-message.html" import email_message %}
|
||||||
{% from "components/page-footer.html" import page_footer %}
|
{% from "components/page-footer.html" import page_footer %}
|
||||||
{% from "components/file-upload.html" import file_upload %}
|
{% from "components/file-upload.html" import file_upload %}
|
||||||
{% from "components/table.html" import list_table, field %}
|
{% from "components/table.html" import list_table, text_field %}
|
||||||
|
|
||||||
{% block page_title %}
|
{% block page_title %}
|
||||||
Send text messages – GOV.UK Notify
|
Send text messages – GOV.UK Notify
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
{% block maincolumn_content %}
|
{% block maincolumn_content %}
|
||||||
|
|
||||||
<h1 class="heading-large">Send from a CSV file</h1>
|
<h1 class="heading-large">Send a batch</h1>
|
||||||
|
|
||||||
{% if 'sms' == template.template_type %}
|
{% if 'sms' == template.template_type %}
|
||||||
<div class="grid-row">
|
<div class="grid-row">
|
||||||
@@ -28,27 +28,32 @@
|
|||||||
) }}
|
) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="grid-row">
|
<p>
|
||||||
<div class="column-two-thirds">
|
You need
|
||||||
<p>
|
{{ template.placeholders|length + 1 }}
|
||||||
You need
|
{% if template.placeholders %}
|
||||||
{{ template.placeholders|length + 1 }}
|
columns
|
||||||
{% if template.placeholders %}
|
{% else %}
|
||||||
columns
|
column
|
||||||
{% else %}
|
{% endif %}
|
||||||
column
|
in your file, like this:
|
||||||
{% endif %}
|
</p>
|
||||||
in your file:
|
|
||||||
</p>
|
{% call(item) list_table(
|
||||||
<p class="bottom-gutter-2-3">
|
example,
|
||||||
<span class='placeholder'>{{ recipient_column }}</span>
|
caption="Example",
|
||||||
{{ template.placeholders_as_markup|join(" ") }}
|
caption_visible=False,
|
||||||
</p>
|
field_headings=[recipient_column] + template.placeholders|list
|
||||||
<p>
|
) %}
|
||||||
<a href="{{ url_for('.get_example_csv', service_id=service_id, template_id=template.id) }}">Download an example</a>
|
{% for column in item %}
|
||||||
</p>
|
{{ text_field(column) }}
|
||||||
</div>
|
{% endfor %}
|
||||||
</div>
|
{% endcall %}
|
||||||
|
|
||||||
|
<p class="bottom-gutter">
|
||||||
|
<a href="{{ url_for('.get_example_csv', service_id=service_id, template_id=template.id) }}">Download this example</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
{{file_upload(form.file, button_text='Upload your CSV file')}}
|
{{file_upload(form.file, button_text='Upload your CSV file')}}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user