Merge pull request #3412 from alphagov/bump-utils-template-classes

Bump utils to bring in recent changes to Template classes
This commit is contained in:
Chris Hill-Scott
2020-04-17 11:04:19 +01:00
committed by GitHub
6 changed files with 44 additions and 30 deletions

View File

@@ -117,6 +117,7 @@ def get_sms_thread(service_id, user_number):
'inbound': is_inbound, 'inbound': is_inbound,
'content': SMSPreviewTemplate( 'content': SMSPreviewTemplate(
{ {
'template_type': 'sms',
'content': ( 'content': (
notification['content'] if is_inbound else notification['content'] if is_inbound else
notification['template']['content'] notification['template']['content']

View File

@@ -128,6 +128,7 @@ def email_template():
brand_name = email_branding['name'] brand_name = email_branding['name']
template = { template = {
'template_type': 'email',
'subject': 'foo', 'subject': 'foo',
'content': ( 'content': (
'Lorem Ipsum is simply dummy text of the printing and typesetting ' 'Lorem Ipsum is simply dummy text of the printing and typesetting '
@@ -198,7 +199,7 @@ def letter_template():
else: else:
filename = 'no-branding' filename = 'no-branding'
template = {'subject': '', 'content': ''} template = {'subject': '', 'content': '', 'template_type': 'letter'}
image_url = url_for('no_cookie.letter_branding_preview_image', filename=filename) image_url = url_for('no_cookie.letter_branding_preview_image', filename=filename)
template_image = str(LetterImageTemplate( template_image = str(LetterImageTemplate(

View File

@@ -13,7 +13,11 @@ from flask import (
) )
from flask_login import current_user from flask_login import current_user
from notifications_python_client.errors import HTTPError from notifications_python_client.errors import HTTPError
from notifications_utils.template import Template, WithSubjectTemplate from notifications_utils.template import (
EmailPreviewTemplate,
LetterPreviewTemplate,
SMSPreviewTemplate,
)
from app import ( from app import (
current_service, current_service,
@@ -402,29 +406,37 @@ def get_job_partials(job):
def add_preview_of_content_to_notifications(notifications): def add_preview_of_content_to_notifications(notifications):
for notification in notifications: for notification in notifications:
yield(dict(
preview_of_content=get_preview_of_content(notification),
**notification
))
if notification['template'].get('redact_personalisation'):
notification['personalisation'] = {}
if notification['template']['template_type'] == 'sms': def get_preview_of_content(notification):
yield dict(
preview_of_content=str(Template( if notification['template'].get('redact_personalisation'):
notification['template'], notification['personalisation'] = {}
notification['personalisation'],
redact_missing_personalisation=True, if notification['template']['is_precompiled_letter']:
)), return notification['client_reference']
**notification
) if notification['template']['template_type'] == 'sms':
else: return str(SMSPreviewTemplate(
if notification['template']['is_precompiled_letter']: notification['template'],
notification['template']['subject'] = notification['client_reference'] notification['personalisation'],
yield dict( redact_missing_personalisation=True,
preview_of_content=( show_prefix=False,
WithSubjectTemplate( ))
notification['template'],
notification['personalisation'], if notification['template']['template_type'] == 'email':
redact_missing_personalisation=True, return EmailPreviewTemplate(
).subject notification['template'],
), notification['personalisation'],
**notification redact_missing_personalisation=True,
) ).subject
if notification['template']['template_type'] == 'letter':
return LetterPreviewTemplate(
notification['template'],
notification['personalisation'],
).subject

View File

@@ -1,6 +1,6 @@
from flask import abort, current_app, render_template from flask import abort, current_app, render_template
from flask_wtf import FlaskForm as Form from flask_wtf import FlaskForm as Form
from notifications_utils.template import Template from notifications_utils.template import SMSPreviewTemplate
from wtforms import ( from wtforms import (
FileField, FileField,
PasswordField, PasswordField,
@@ -31,7 +31,7 @@ def styleguide():
form.message.data = sms form.message.data = sms
form.validate() form.validate()
template = Template({'content': sms}) template = SMSPreviewTemplate({'content': sms, 'template_type': 'sms'})
return render_template( return render_template(
'views/styleguide.html', 'views/styleguide.html',

View File

@@ -22,5 +22,5 @@ notifications-python-client==5.5.1
awscli-cwlogs>=1.4,<1.5 awscli-cwlogs>=1.4,<1.5
itsdangerous==1.1.0 itsdangerous==1.1.0
git+https://github.com/alphagov/notifications-utils.git@36.12.2#egg=notifications-utils==36.12.2 git+https://github.com/alphagov/notifications-utils.git@37.0.0#egg=notifications-utils==37.0.0
git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha

View File

@@ -24,7 +24,7 @@ notifications-python-client==5.5.1
awscli-cwlogs>=1.4,<1.5 awscli-cwlogs>=1.4,<1.5
itsdangerous==1.1.0 itsdangerous==1.1.0
git+https://github.com/alphagov/notifications-utils.git@36.12.2#egg=notifications-utils==36.12.2 git+https://github.com/alphagov/notifications-utils.git@37.0.0#egg=notifications-utils==37.0.0
git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.5.1-alpha#egg=govuk-frontend-jinja==0.5.1-alpha
## The following requirements were added by pip freeze: ## The following requirements were added by pip freeze: