mirror of
https://github.com/GSA/notifications-api.git
synced 2026-03-23 19:50:14 -04:00
Add reply_to fields to template schemas
We're hiding the `service_letter_contact_id` column since it should only be readable and writable using the `.reply_to` wrapper. Schemas are defined using `fields.Method` since the fields are represented by a property on the Template model that requires template type to be set. When creating a template, if `reply_to` is defined using `fields.String` it gets assigned at the same time as `template_type` (or the order of assignments is not defined), so the schema loader attempts to set `.reply_to` on a Template object with a `None` `template_type`, which raises an exception. Using `fields.Method` seems to delay `.reply_to` assignment until the Template object is created, which means it already has a valid type.
This commit is contained in:
@@ -314,9 +314,14 @@ class NotificationModelSchema(BaseSchema):
|
||||
|
||||
class BaseTemplateSchema(BaseSchema):
|
||||
|
||||
reply_to = fields.Method("get_reply_to", allow_none=True)
|
||||
|
||||
def get_reply_to(self, template):
|
||||
return template.reply_to
|
||||
|
||||
class Meta:
|
||||
model = models.Template
|
||||
exclude = ("service_id", "jobs")
|
||||
exclude = ("service_id", "jobs", "service_letter_contact_id")
|
||||
strict = True
|
||||
|
||||
|
||||
@@ -339,9 +344,14 @@ class TemplateSchema(BaseTemplateSchema):
|
||||
|
||||
class TemplateHistorySchema(BaseSchema):
|
||||
|
||||
reply_to = fields.Method("get_reply_to", allow_none=True)
|
||||
|
||||
created_by = fields.Nested(UserSchema, only=['id', 'name', 'email_address'], dump_only=True)
|
||||
created_at = field_for(models.Template, 'created_at', format='%Y-%m-%d %H:%M:%S.%f')
|
||||
|
||||
def get_reply_to(self, template):
|
||||
return template.reply_to
|
||||
|
||||
class Meta:
|
||||
model = models.TemplateHistory
|
||||
|
||||
|
||||
Reference in New Issue
Block a user