From 584fac9683f82e93838e60c65819bf16310c0b94 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Thu, 3 Mar 2016 11:14:43 +0000 Subject: [PATCH] If the file was invalid and Upload a CSV file was clicked, the job was created, then the send would fail when sending the file, trying to replace a placeholder that didn't exist. This commit calls send_messages again if the files exist on the request. --- app/main/views/send.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index f656c20e4..71349ae8c 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -197,21 +197,25 @@ def check_messages(service_id, upload_id): form=CsvUploadForm() ) elif request.method == 'POST': - original_file_name = upload_data.get('original_file_name') - notification_count = upload_data.get('notification_count') - session.pop('upload_data') - try: - job_api_client.create_job(upload_id, service_id, template_id, original_file_name, notification_count) - except HTTPError as e: - if e.status_code == 404: - abort(404) - else: - raise e + if request.files: + # The csv was invalid, validate the csv again + return send_messages(service_id, template_id) + else: + original_file_name = upload_data.get('original_file_name') + notification_count = upload_data.get('notification_count') + session.pop('upload_data') + try: + job_api_client.create_job(upload_id, service_id, template_id, original_file_name, notification_count) + except HTTPError as e: + if e.status_code == 404: + abort(404) + else: + raise e - flash('We’ve started sending your messages', 'default_with_tick') - return redirect( - url_for('main.view_job', service_id=service_id, job_id=upload_id) - ) + flash('We’ve started sending your messages', 'default_with_tick') + return redirect( + url_for('main.view_job', service_id=service_id, job_id=upload_id) + ) def _get_filedata(file):