Using jsonschema for create_template.

Updated jsonschema to Draft7, this allowed a conditional validation on subject, if template_type == 'email' or 'letter' then subject is required.
This version is backward compatible with Draft4.
When creating TempalteRedacted, I've built the dict depending on if the created_by or created_by_id exists.
This commit is contained in:
Rebecca Law
2018-11-02 16:00:22 +00:00
parent 1230495e88
commit 39198ed67e
8 changed files with 69 additions and 17 deletions

View File

@@ -21,11 +21,16 @@ def dao_create_template(template):
template.id = uuid.uuid4() # must be set now so version history model can use same id
template.archived = False
template.template_redacted = TemplateRedacted(
template=template,
redact_personalisation=False,
updated_by=template.created_by
)
redacted_dict = {
"template": template,
"redact_personalisation": False,
}
if template.created_by:
redacted_dict.update({"updated_by": template.created_by})
else:
redacted_dict.update({"updated_by_id": template.created_by_id})
template.template_redacted = TemplateRedacted(**redacted_dict)
db.session.add(template)