update schema to use template_history for accurate template details

only in the public notification endpoint so far for fear of breaking
things - in an ideal world i'd remove the template relationship
from models entirely and replace that with actual_template
This commit is contained in:
Leo Hemsted
2016-08-09 16:53:09 +01:00
parent 46c0728b12
commit 4ba3745159
4 changed files with 35 additions and 16 deletions

View File

@@ -282,12 +282,21 @@ class NotificationWithTemplateSchema(BaseSchema):
strict = True
exclude = ('_personalisation',)
template = fields.Nested(TemplateSchema, only=["id", "name", "template_type", "content", "subject"], dump_only=True)
template = fields.Nested(
TemplateSchema,
only=['id', 'version', 'name', 'template_type', 'content', 'subject'],
dump_only=True
)
job = fields.Nested(JobSchema, only=["id", "original_file_name"], dump_only=True)
personalisation = fields.Dict(required=False)
class NotificationWithPersonalisationSchema(NotificationWithTemplateSchema):
template = None
actual_template = fields.Nested(TemplateHistorySchema,
only=['id', 'name', 'template_type', 'content', 'subject', 'version'],
dump_only=True)
@pre_dump
def handle_personalisation_property(self, in_data):
self.personalisation = in_data.personalisation
@@ -295,6 +304,7 @@ class NotificationWithPersonalisationSchema(NotificationWithTemplateSchema):
@post_dump
def handle_template_merge(self, in_data):
in_data['template'] = in_data.pop('actual_template')
from notifications_utils.template import Template
template = Template(
in_data['template'],