From 824085ead8a16eabebfe9d41999610b8be44bec2 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 5 Jul 2016 16:21:31 +0100 Subject: [PATCH] Bring in changes to template and CSV processing Functional changes: - adds the blue bar Performance changes - faster CSV processing Depends on: - [ ] https://github.com/alphagov/notifications-utils/pull/47 - [ ] https://github.com/alphagov/notifications-utils/pull/48 Also brings in some breaking changes, which do not affect utils (apart from a weird import). --- app/celery/provider_tasks.py | 28 ++++++++++++++++++---------- app/notifications/rest.py | 6 +++++- requirements.txt | 2 +- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/celery/provider_tasks.py b/app/celery/provider_tasks.py index 8e6e4cb85..6e8654c5b 100644 --- a/app/celery/provider_tasks.py +++ b/app/celery/provider_tasks.py @@ -20,9 +20,8 @@ from notifications_utils.recipients import ( ) from app.dao.templates_dao import dao_get_template_by_id -from notifications_utils.template import ( - Template -) +from notifications_utils.template import Template +from notifications_utils.renderers import HTMLEmail, PlainTextEmail, SMSMessage from app.models import SMS_TYPE, EMAIL_TYPE, KEY_TYPE_TEST @@ -62,7 +61,7 @@ def send_sms_to_provider(self, service_id, notification_id): template = Template( template_model.__dict__, values={} if not notification.personalisation else notification.personalisation, - prefix=service.name + renderer=SMSMessage(prefix=service.name) ) try: if service.research_mode or notification.key_type == KEY_TYPE_TEST: @@ -129,9 +128,18 @@ def send_email_to_provider(self, service_id, notification_id): notification = get_notification_by_id(notification_id) if notification.status == 'created': try: - template = Template( - dao_get_template_by_id(notification.template_id, notification.template_version).__dict__, - values=notification.personalisation + template_dict = dao_get_template_by_id(notification.template_id, notification.template_version).__dict__ + + html_email = Template( + template_dict, + values=notification.personalisation, + renderer=HTMLEmail() + ) + + plain_text_email = Template( + template_dict, + values=notification.personalisation, + renderer=PlainTextEmail() ) if service.research_mode or notification.key_type == KEY_TYPE_TEST: @@ -145,9 +153,9 @@ def send_email_to_provider(self, service_id, notification_id): reference = provider.send_email( from_address, notification.to, - template.replaced_subject, - body=template.replaced_govuk_escaped, - html_body=template.as_HTML_email, + plain_text_email.replaced_subject, + body=plain_text_email.replaced, + html_body=html_email.replaced, reply_to_address=service.reply_to_email_address, ) diff --git a/app/notifications/rest.py b/app/notifications/rest.py index 5e549eb57..ed1e1ee92 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -240,7 +240,11 @@ def send_notification(notification_type): if errors: raise InvalidRequest(errors, status_code=400) - template_object = Template(template.__dict__, notification.get('personalisation', {})) + template_object = Template( + template.__dict__, + notification.get('personalisation', {}), + renderer=lambda content: content + ) if template_object.missing_data: message = 'Missing personalisation: {}'.format(", ".join(template_object.missing_data)) errors = {'template': [message]} diff --git a/requirements.txt b/requirements.txt index 13d504b91..442efe262 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,4 +23,4 @@ statsd==3.2.1 git+https://github.com/alphagov/notifications-python-client.git@1.0.0#egg=notifications-python-client==1.0.0 -git+https://github.com/alphagov/notifications-utils.git@6.3.2#egg=notifications-utils==6.3.2 +git+https://github.com/alphagov/notifications-utils.git@8.1.0#egg=notifications-utils==8.1.0