mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-03-10 05:12:52 -04:00
Bump utils to bring in recent changes to Template classes
The main things we have to account for are: - `WithSubjectTemplate` has gone - every template dictionary must have `template_type` set
This commit is contained in:
@@ -117,6 +117,7 @@ def get_sms_thread(service_id, user_number):
|
||||
'inbound': is_inbound,
|
||||
'content': SMSPreviewTemplate(
|
||||
{
|
||||
'template_type': 'sms',
|
||||
'content': (
|
||||
notification['content'] if is_inbound else
|
||||
notification['template']['content']
|
||||
|
||||
@@ -128,6 +128,7 @@ def email_template():
|
||||
brand_name = email_branding['name']
|
||||
|
||||
template = {
|
||||
'template_type': 'email',
|
||||
'subject': 'foo',
|
||||
'content': (
|
||||
'Lorem Ipsum is simply dummy text of the printing and typesetting '
|
||||
@@ -198,7 +199,7 @@ def letter_template():
|
||||
else:
|
||||
filename = 'no-branding'
|
||||
|
||||
template = {'subject': '', 'content': ''}
|
||||
template = {'subject': '', 'content': '', 'template_type': 'letter'}
|
||||
image_url = url_for('no_cookie.letter_branding_preview_image', filename=filename)
|
||||
|
||||
template_image = str(LetterImageTemplate(
|
||||
|
||||
@@ -13,7 +13,11 @@ from flask import (
|
||||
)
|
||||
from flask_login import current_user
|
||||
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 (
|
||||
current_service,
|
||||
@@ -402,29 +406,37 @@ def get_job_partials(job):
|
||||
def add_preview_of_content_to_notifications(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':
|
||||
yield dict(
|
||||
preview_of_content=str(Template(
|
||||
notification['template'],
|
||||
notification['personalisation'],
|
||||
redact_missing_personalisation=True,
|
||||
)),
|
||||
**notification
|
||||
)
|
||||
else:
|
||||
if notification['template']['is_precompiled_letter']:
|
||||
notification['template']['subject'] = notification['client_reference']
|
||||
yield dict(
|
||||
preview_of_content=(
|
||||
WithSubjectTemplate(
|
||||
notification['template'],
|
||||
notification['personalisation'],
|
||||
redact_missing_personalisation=True,
|
||||
).subject
|
||||
),
|
||||
**notification
|
||||
)
|
||||
def get_preview_of_content(notification):
|
||||
|
||||
if notification['template'].get('redact_personalisation'):
|
||||
notification['personalisation'] = {}
|
||||
|
||||
if notification['template']['is_precompiled_letter']:
|
||||
return notification['client_reference']
|
||||
|
||||
if notification['template']['template_type'] == 'sms':
|
||||
return str(SMSPreviewTemplate(
|
||||
notification['template'],
|
||||
notification['personalisation'],
|
||||
redact_missing_personalisation=True,
|
||||
show_prefix=False,
|
||||
))
|
||||
|
||||
if notification['template']['template_type'] == 'email':
|
||||
return EmailPreviewTemplate(
|
||||
notification['template'],
|
||||
notification['personalisation'],
|
||||
redact_missing_personalisation=True,
|
||||
).subject
|
||||
|
||||
if notification['template']['template_type'] == 'letter':
|
||||
return LetterPreviewTemplate(
|
||||
notification['template'],
|
||||
notification['personalisation'],
|
||||
).subject
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from flask import abort, current_app, render_template
|
||||
from flask_wtf import FlaskForm as Form
|
||||
from notifications_utils.template import Template
|
||||
from notifications_utils.template import SMSPreviewTemplate
|
||||
from wtforms import (
|
||||
FileField,
|
||||
PasswordField,
|
||||
@@ -31,7 +31,7 @@ def styleguide():
|
||||
form.message.data = sms
|
||||
form.validate()
|
||||
|
||||
template = Template({'content': sms})
|
||||
template = SMSPreviewTemplate({'content': sms, 'template_type': 'sms'})
|
||||
|
||||
return render_template(
|
||||
'views/styleguide.html',
|
||||
|
||||
@@ -22,5 +22,5 @@ notifications-python-client==5.5.1
|
||||
awscli-cwlogs>=1.4,<1.5
|
||||
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
|
||||
|
||||
@@ -24,7 +24,7 @@ notifications-python-client==5.5.1
|
||||
awscli-cwlogs>=1.4,<1.5
|
||||
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
|
||||
|
||||
## The following requirements were added by pip freeze:
|
||||
|
||||
Reference in New Issue
Block a user