mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Use new properties of utils Templates
We’ve added some new properties to the templates in utils that we can use instead of doing weird things like `WithSubjectTemplate.__str__(another_instance)`
This commit is contained in:
@@ -7,7 +7,6 @@ from boto.exception import SQSError
|
||||
from flask import request, jsonify, current_app, abort
|
||||
from notifications_utils.postal_address import PostalAddress
|
||||
from notifications_utils.recipients import try_validate_and_format_phone_number
|
||||
from notifications_utils.template import WithSubjectTemplate
|
||||
|
||||
from app import (
|
||||
api_user,
|
||||
@@ -167,26 +166,24 @@ def post_notification(notification_type):
|
||||
create_resp_partial = functools.partial(
|
||||
create_post_sms_response_from_notification,
|
||||
from_number=reply_to,
|
||||
content=str(template_with_content),
|
||||
)
|
||||
elif notification_type == EMAIL_TYPE:
|
||||
create_resp_partial = functools.partial(
|
||||
create_post_email_response_from_notification,
|
||||
subject=template_with_content.subject,
|
||||
email_from='{}@{}'.format(authenticated_service.email_from, current_app.config['NOTIFY_EMAIL_DOMAIN']),
|
||||
content=WithSubjectTemplate.__str__(template_with_content),
|
||||
)
|
||||
elif notification_type == LETTER_TYPE:
|
||||
create_resp_partial = functools.partial(
|
||||
create_post_letter_response_from_notification,
|
||||
subject=template_with_content.subject,
|
||||
content=WithSubjectTemplate.__str__(template_with_content),
|
||||
)
|
||||
|
||||
resp = create_resp_partial(
|
||||
notification=notification,
|
||||
url_root=request.url_root,
|
||||
scheduled_for=scheduled_for
|
||||
scheduled_for=scheduled_for,
|
||||
content=template_with_content.content_with_placeholders_filled_in,
|
||||
)
|
||||
return jsonify(resp), 201
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
from notifications_utils.template import WithSubjectTemplate
|
||||
|
||||
from app.models import SMS_TYPE, TEMPLATE_TYPES
|
||||
from app.models import TEMPLATE_TYPES
|
||||
from app.schema_validation.definitions import uuid, personalisation
|
||||
from app.utils import get_html_email_body_from_template
|
||||
|
||||
|
||||
get_template_by_id_request = {
|
||||
@@ -77,19 +74,12 @@ post_template_preview_response = {
|
||||
|
||||
|
||||
def create_post_template_preview_response(template, template_object):
|
||||
if template.template_type == SMS_TYPE:
|
||||
subject = None
|
||||
body = str(template_object)
|
||||
else:
|
||||
subject = template_object.subject
|
||||
body = WithSubjectTemplate.__str__(template_object)
|
||||
|
||||
return {
|
||||
"id": template.id,
|
||||
"type": template.template_type,
|
||||
"version": template.version,
|
||||
"body": body,
|
||||
"html": get_html_email_body_from_template(template_object),
|
||||
"subject": subject,
|
||||
"body": template_object.content_with_placeholders_filled_in,
|
||||
"html": getattr(template_object, 'html_body', None),
|
||||
"subject": getattr(template_object, 'subject', None),
|
||||
"postage": template.postage
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user