Add model properties for template and folder IDs

We’re going to need a way to find out if, for a given ID:
1. its a template or a folder
2. if it belongs to a given service

To do 2., we can make a set of all the IDs, to see if a given ID is a
member of that set.

To do 1. we can make two sets, one for templates and one for folders.

The natural home for these sets is on the service model.
This commit is contained in:
Chris Hill-Scott
2018-11-08 11:42:01 +00:00
parent d98ec79a9d
commit 4df96f3682

View File

@@ -100,6 +100,10 @@ class Service():
if template['template_type'] in self.available_template_types
]
@cached_property
def all_template_ids(self):
return {template['id'] for template in self.all_templates}
def get_templates(self, template_type='all', template_folder_id=None):
if isinstance(template_type, str):
template_type = [template_type]
@@ -284,6 +288,10 @@ class Service():
def all_template_folders(self):
return template_folder_api_client.get_template_folders(self.id)
@cached_property
def all_template_folder_ids(self):
return {folder['id'] for folder in self.all_template_folders}
def get_template_folders(self, parent_folder_id=None):
return [
folder for folder in self.all_template_folders