Update model and controller to handle parent_folder_id when creating a template.

If the parent_folder_id then check if the folder exists and is for the same service. If it is add the folder to the template model object, the relationship will be persisted when the template is saved. If the folder does not exist or is for a different service, then return a ResultNotFound error.
This commit is contained in:
Rebecca Law
2018-11-07 12:48:56 +00:00
committed by Rebecca Law
parent 4849ecdf63
commit 1b0b16fa74
3 changed files with 40 additions and 8 deletions

View File

@@ -888,15 +888,13 @@ class Template(TemplateBase):
def from_json(cls, data, folder):
"""
Assumption: data has been validated appropriately.
Returns a Template object based on the provided data.
"""
fields = data.copy()
fields['created_by_id'] = fields.pop('created_by')
fields['service_id'] = fields.pop('service')
if fields.pop("parent_folder_id"):
fields['folder'] = folder
fields['folder'] = folder
return cls(**fields)