From b93a1e89c8ddbfe938db26cd29c1c86394e9f363 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 9 Mar 2016 12:18:11 +0000 Subject: [PATCH 1/2] Fix bug which prevented viewing an email job MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The template for viewing a job was not getting all the variables it needed in order to display an email template. Hadn’t noticed this before, because email templates require more variables than SMS templates. This commit fixes that bug. --- app/assets/stylesheets/components/email-message.scss | 1 + app/main/views/jobs.py | 7 ++++--- app/main/views/send.py | 12 +++++++----- app/templates/views/jobs/job.html | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/components/email-message.scss b/app/assets/stylesheets/components/email-message.scss index 860b3d99e..c8b9bbee3 100644 --- a/app/assets/stylesheets/components/email-message.scss +++ b/app/assets/stylesheets/components/email-message.scss @@ -17,6 +17,7 @@ @include core-19; border-bottom: 0; border-top: 1px solid $border-colour; + vertical-align: top; } th { diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index 093c91163..24949756e 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -40,6 +40,7 @@ def view_job(service_id, job_id): service = services_dao.get_service_by_id_or_404(service_id) try: job = job_api_client.get_job(service_id, job_id)['data'] + template = templates_dao.get_service_template_or_404(service_id, job['template'])['data'] notifications = notification_api_client.get_notifications_for_service(service_id, job_id) finished = job['status'] == 'finished' return render_template( @@ -55,11 +56,11 @@ def view_job(service_id, job_id): finished_at=job['updated_at'] if finished else None, uploaded_file_name=job['original_file_name'], template=Template( - templates_dao.get_service_template_or_404(service_id, job['template'])['data'], - prefix=service['name'] + template, + prefix=service['name'] if template['template_type'] == 'sms' else '' ), service_id=service_id, - from_name=service['name'], + service=service, job_id=job_id ) except HTTPError as e: diff --git a/app/main/views/send.py b/app/main/views/send.py index 27d1ffe4d..f89e614ce 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -203,12 +203,14 @@ def check_messages(service_id, upload_id): if not contents: flash('There was a problem reading your upload file') + template = templates_dao.get_service_template_or_404( + service_id, + session['upload_data'].get('template_id') + )['data'] + template = Template( - templates_dao.get_service_template_or_404( - service_id, - session['upload_data'].get('template_id') - )['data'], - prefix=service['name'] + template, + prefix=service['name'] if template['template_type'] == 'sms' else '' ) recipients = RecipientCSV( diff --git a/app/templates/views/jobs/job.html b/app/templates/views/jobs/job.html index 3af945de8..ddec1812b 100644 --- a/app/templates/views/jobs/job.html +++ b/app/templates/views/jobs/job.html @@ -24,9 +24,9 @@ {% elif 'email' == template.template_type %} {{ email_message( template.subject, - template, + template.formatted_as_markup, from_address='{}@notifications.service.gov.uk'.format(service.email_from), - from_name=from_name + from_name=service.name )}} {% endif %} From 91e9cd37b1b3f686e1c10cd3c7ff178b4efdffe4 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 9 Mar 2016 12:22:12 +0000 Subject: [PATCH 2/2] =?UTF-8?q?Make=20text=20of=20=E2=80=98send=E2=80=99?= =?UTF-8?q?=20button=20say=20=E2=80=98email=E2=80=99=20or=20=E2=80=98text?= =?UTF-8?q?=E2=80=A6=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously the send button on the ‘Check and confirm’ page always said ‘Send x messages’, irrespective of whether you were sending emails or text messages. This commit makes it say one of - Send 1 email - Send 29 emails - Send 1 text message - Send 999 text messages --- app/main/views/send.py | 14 ++++++++++++++ app/templates/views/check.html | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/main/views/send.py b/app/main/views/send.py index f89e614ce..b7578afa5 100644 --- a/app/main/views/send.py +++ b/app/main/views/send.py @@ -43,6 +43,19 @@ manage_templates_page_headings = { } +def get_send_button_text(template_type, number_of_messages): + if 1 == number_of_messages: + return { + 'email': 'Send 1 email', + 'sms': 'Send 1 text message' + }[template_type] + else: + return { + 'email': 'Send {} emails', + 'sms': 'Send {} text messages' + }[template_type].format(number_of_messages) + + def get_page_headings(template_type): # User has manage_service role if current_user.has_permissions(['send_texts', 'send_emails', 'send_letters']): @@ -235,6 +248,7 @@ def check_messages(service_id, upload_id): count_of_recipients=session['upload_data']['notification_count'], count_of_displayed_recipients=len(list(recipients.rows_annotated_and_truncated)), original_file_name=session['upload_data'].get('original_file_name'), + send_button_text=get_send_button_text(template.template_type, session['upload_data']['notification_count']), service_id=service_id, service=service, form=CsvUploadForm() diff --git a/app/templates/views/check.html b/app/templates/views/check.html index e48229b55..13b9e86a3 100644 --- a/app/templates/views/check.html +++ b/app/templates/views/check.html @@ -66,7 +66,7 @@ {% else %}
- + Back
{% endif %}