mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-14 01:02:09 -05:00
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']
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user