Prefill placeholders for test message

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.
This commit is contained in:
Chris Hill-Scott
2016-02-18 17:25:04 +00:00
parent cfef82bfaa
commit 8123359eb2

View File

@@ -104,10 +104,12 @@ def get_example_csv(service_id, template_id):
@main.route("/services/<service_id>/sms/send/<template_id>/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()