mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-12 00:02:36 -05:00
Add new schema, TemplateSchemaNested
When we nest the `TemplateSchema` as a field on the `NotificationWithTemplateSchema`, we want to include the `is_precompiled_letter` field. However, we don't want the `is_precompiled_letter` in any of the other places that we use the `TemplateSchema`. The way we had the code was giving errors in version 3 of Marshmallow since `is_precompiled_letter` was not defined on the `TemplateSchema`. Instead of writing complicated logic around when the field should be included or excluded, this adds a new schema which we can use in the one place where we do want to include `is_precompiled_letter`.
This commit is contained in:
@@ -359,6 +359,16 @@ class TemplateSchema(BaseTemplateSchema, UUIDsAsStringsMixin):
|
|||||||
raise ValidationError('Invalid template subject', 'subject')
|
raise ValidationError('Invalid template subject', 'subject')
|
||||||
|
|
||||||
|
|
||||||
|
class TemplateSchemaNested(TemplateSchema):
|
||||||
|
"""
|
||||||
|
Contains extra 'is_precompiled_letter' field for use with NotificationWithTemplateSchema
|
||||||
|
"""
|
||||||
|
is_precompiled_letter = fields.Method('get_is_precompiled_letter')
|
||||||
|
|
||||||
|
def get_is_precompiled_letter(self, template):
|
||||||
|
return template.is_precompiled_letter
|
||||||
|
|
||||||
|
|
||||||
class TemplateSchemaNoDetail(TemplateSchema):
|
class TemplateSchemaNoDetail(TemplateSchema):
|
||||||
class Meta(TemplateSchema.Meta):
|
class Meta(TemplateSchema.Meta):
|
||||||
exclude = TemplateSchema.Meta.exclude + (
|
exclude = TemplateSchema.Meta.exclude + (
|
||||||
@@ -502,7 +512,7 @@ class NotificationWithTemplateSchema(BaseSchema):
|
|||||||
exclude = ('_personalisation',)
|
exclude = ('_personalisation',)
|
||||||
|
|
||||||
template = fields.Nested(
|
template = fields.Nested(
|
||||||
TemplateSchema,
|
TemplateSchemaNested,
|
||||||
only=[
|
only=[
|
||||||
'id',
|
'id',
|
||||||
'version',
|
'version',
|
||||||
|
|||||||
Reference in New Issue
Block a user