From 8123359eb26c89877bfa2fd29393f4c884e3f341 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 18 Feb 2016 17:25:04 +0000 Subject: [PATCH 1/2] Prefill placeholders for test message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you want to send yourself a test message from a template that has placeholders you can’t, at the moment. Rather than forcing you to upload a CSV, we should prefil the data, and then you only need to upload a CSV if you want to customise it. --- app/main/views/sms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/main/views/sms.py b/app/main/views/sms.py index 61a6f62cc..2889b62a1 100644 --- a/app/main/views/sms.py +++ b/app/main/views/sms.py @@ -104,10 +104,12 @@ def get_example_csv(service_id, template_id): @main.route("/services//sms/send//to-self", methods=['GET']) @login_required def send_sms_to_self(service_id, template_id): + template = templates_dao.get_service_template_or_404(service_id, template_id)['data'] + placeholders = list(Template(template).placeholders) output = io.StringIO() writer = csv.writer(output) - writer.writerow(['phone']) - writer.writerow([current_user.mobile_number]) + writer.writerow(['phone'] + placeholders) + writer.writerow([current_user.mobile_number] + ["test {}".format(header) for header in placeholders]) filedata = { 'file_name': 'Test run', 'data': output.getvalue().splitlines() From 5af03b28f33392f02e1547f213418c87f6f105a5 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 18 Feb 2016 17:29:16 +0000 Subject: [PATCH 2/2] Remove the weird table from the send SMS page It was weird. --- app/main/views/sms.py | 9 --------- app/templates/views/send-sms.html | 26 ++++---------------------- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/app/main/views/sms.py b/app/main/views/sms.py index 2889b62a1..0b4815d26 100644 --- a/app/main/views/sms.py +++ b/app/main/views/sms.py @@ -70,19 +70,10 @@ def send_sms(service_id, template_id): templates_dao.get_service_template_or_404(service_id, template_id)['data'] ) - example_data = [dict( - phone=current_user.mobile_number, - **{ - header: "test {}".format(header) for header in template.placeholders - } - )] - return render_template( 'views/send-sms.html', template=template, column_headers=['phone'] + template.placeholders_as_markup, - placeholders=template.placeholders, - example_data=example_data, form=form, service_id=service_id ) diff --git a/app/templates/views/send-sms.html b/app/templates/views/send-sms.html index 097fe142e..351115c7f 100644 --- a/app/templates/views/send-sms.html +++ b/app/templates/views/send-sms.html @@ -22,32 +22,14 @@ {{file_upload(form.file, button_text='Choose a CSV file')}} +

+ Download an example CSV file +

+ {{ page_footer( "Continue to preview" ) }} - {% if column_headers %} - {% call(item) list_table( - example_data, - caption='Example', - field_headings=column_headers, - field_headings_visible=True, - caption_visible=True, - empty_message="Your data here" - ) %} - {% call field() %} - {{ item.phone }} - {% endcall %} - {% for column in template.placeholders %} - {% call field() %} - {{ item.get(column) }} - {% endcall %} - {% endfor %} - {% endcall %} - {% endif %} - {% endblock %}