mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Merge pull request #892 from alphagov/v2-preview-subject-personalisation
V2 preview subject personalisation
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from flask import jsonify, request
|
||||
from jsonschema.exceptions import ValidationError
|
||||
from werkzeug.exceptions import abort
|
||||
|
||||
from app import api_user
|
||||
from app.dao import templates_dao
|
||||
from app.models import SMS_TYPE
|
||||
from app.schema_validation import validate
|
||||
from app.utils import get_template_instance
|
||||
from app.v2.errors import BadRequestError
|
||||
@@ -16,6 +14,9 @@ from app.v2.template.template_schemas import post_template_preview_request, crea
|
||||
@v2_template_blueprint.route("/<template_id>/preview", methods=['POST'])
|
||||
def post_template_preview(template_id):
|
||||
_data = request.get_json()
|
||||
if _data is None:
|
||||
_data = {}
|
||||
|
||||
_data['id'] = template_id
|
||||
|
||||
data = validate(_data, post_template_preview_request)
|
||||
@@ -29,8 +30,7 @@ def post_template_preview(template_id):
|
||||
check_placeholders(template_object)
|
||||
|
||||
resp = create_post_template_preview_response(template=template,
|
||||
body=str(template_object),
|
||||
url_root=request.url_root)
|
||||
template_object=template_object)
|
||||
|
||||
return jsonify(resp), 200
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from app.models import TEMPLATE_TYPES
|
||||
from app.models import SMS_TYPE, TEMPLATE_TYPES
|
||||
from app.schema_validation.definitions import uuid, personalisation
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ post_template_preview_request = {
|
||||
"id": uuid,
|
||||
"personalisation": personalisation
|
||||
},
|
||||
"required": ["id", "personalisation"]
|
||||
"required": ["id"]
|
||||
}
|
||||
|
||||
post_template_preview_response = {
|
||||
@@ -68,12 +68,13 @@ post_template_preview_response = {
|
||||
}
|
||||
|
||||
|
||||
def create_post_template_preview_response(template, body, url_root):
|
||||
def create_post_template_preview_response(template, template_object):
|
||||
subject = template_object.subject if template.template_type != SMS_TYPE else None
|
||||
|
||||
return {
|
||||
"id": template.id,
|
||||
"type": template.template_type,
|
||||
"version": template.version,
|
||||
"body": body,
|
||||
"subject": template.subject,
|
||||
"uri": "{}v2/template/{}/preview".format(url_root, template.id)
|
||||
"body": str(template_object),
|
||||
"subject": subject
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user