Link template folders to their contents

Clicking on template folder navigates to a page that displays that
folder's contents.

This reuses the existing choose template view by adding a filter
based on optional `template_folder_id` argument.

Service model methods are rewritten to match `all_templates` and
`get_template`. New `get_template_folder_path` method returns a
list of folders (from root to the current one) that the selected
folder is nested inside.
This commit is contained in:
Alexey Bezhan
2018-11-05 16:25:19 +00:00
parent 29bed8ba55
commit 20abe96fc9
4 changed files with 32 additions and 11 deletions

View File

@@ -259,5 +259,26 @@ class Service():
return bool(self.inbound_number)
@cached_property
def template_folders(self):
def all_template_folders(self):
return template_folder_api_client.get_template_folders(self.id)
def get_template_folders(self, parent_folder_id=None):
return [
folder for folder in self.all_template_folders
if folder['parent_id'] == parent_folder_id
]
def get_template_folder_path(self, template_folder_id):
if template_folder_id is None:
return []
id_to_folder = {folder['id']: folder for folder in self.all_template_folders}
folder = id_to_folder[template_folder_id]
path = [folder]
while folder['parent_id']:
folder = id_to_folder[folder['parent_id']]
path.append(folder)
return list(reversed(path))