Reuse TemplateList to display move-to options

This is slightly less efficient than getting the folder dicts from
"get_user_template_folders" directly, since:

- TemplateList returns both templates and folders.
- TemplateList encapsulates the dicts in model classes.

We'll compensate for this later on:

- We'll introduce a new caching approach to make the call fast.
- We'll expose a property to avoid the "if" in the comprehension.
This commit is contained in:
Ben Thorner
2022-05-26 16:46:17 +01:00
parent f500db44f1
commit ad4ef12251
2 changed files with 6 additions and 1 deletions

View File

@@ -104,8 +104,12 @@ def choose_template(service_id, template_type='all', template_folder_id=None):
template_list = TemplateList(current_service, template_type, template_folder_id, current_user)
all_template_folders = [
item.folder for item in TemplateList(service=current_service, user=current_user) if item.is_folder
]
templates_and_folders_form = TemplateAndFoldersSelectionForm(
all_template_folders=current_service.get_user_template_folders(current_user),
all_template_folders=all_template_folders,
template_list=template_list,
template_type=template_type,
available_template_types=current_service.available_template_types,

View File

@@ -157,6 +157,7 @@ class TemplateListFolder(TemplateListItem):
service_id,
):
super().__init__(folder, ancestors)
self.folder = folder
self.service_id = service_id
self.number_of_templates = len(templates)
self.number_of_folders = len(folders)