From b5a2dbb24e8c18d1aad641e4c3469ae90d706f4c Mon Sep 17 00:00:00 2001 From: Ken Tsang Date: Mon, 5 Mar 2018 18:47:45 +0000 Subject: [PATCH] Update schema to dump precompiled_letter - to be a precompiled letter, the template must be a letter, be hidden, and have a matching template name to the one expected in config['PRECOMPILED_TEMPLATE_NAME'] --- app/schemas.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/schemas.py b/app/schemas.py index b36de4871..9b4ae055c 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -2,6 +2,7 @@ from datetime import ( datetime, date, timedelta) +from flask import current_app from flask_marshmallow.fields import fields from marshmallow import ( post_load, @@ -305,6 +306,7 @@ class NotificationModelSchema(BaseSchema): class BaseTemplateSchema(BaseSchema): reply_to = fields.Method("get_reply_to", allow_none=True) reply_to_text = fields.Method("get_reply_to_text", allow_none=True) + precompiled_letter = fields.Method("get_precompiled_letter") def get_reply_to(self, template): return template.reply_to @@ -312,6 +314,13 @@ class BaseTemplateSchema(BaseSchema): def get_reply_to_text(self, template): return template.get_reply_to_text() + def get_precompiled_letter(self, template): + return ( + template.template_type == 'letter' and + template.hidden and + template.name == current_app.config['PRECOMPILED_TEMPLATE_NAME'] + ) + class Meta: model = models.Template exclude = ("service_id", "jobs", "service_letter_contact_id") @@ -454,7 +463,16 @@ class NotificationWithTemplateSchema(BaseSchema): template = fields.Nested( TemplateSchema, - only=['id', 'version', 'name', 'template_type', 'content', 'subject', 'redact_personalisation', 'hidden'], + only=[ + 'id', + 'version', + 'name', + 'template_type', + 'content', + 'subject', + 'redact_personalisation', + 'precompiled_letter' + ], dump_only=True ) job = fields.Nested(JobSchema, only=["id", "original_file_name"], dump_only=True)