Allow any sub-items to be moved from a folder

Since you can now see them when searching you should also be able to
select and move them. Which means that they needed to be included in
the `Form`’s list of possible choices of things to move.
This commit is contained in:
Chris Hill-Scott
2018-11-23 16:29:21 +00:00
parent cdb03d1eeb
commit ee991d0142
5 changed files with 54 additions and 17 deletions

View File

@@ -1143,8 +1143,8 @@ class TemplateAndFoldersSelectionForm(Form):
def __init__(
self,
service,
template_type,
all_template_folders,
template_list,
current_folder_id,
*args,
**kwargs
@@ -1152,20 +1152,12 @@ class TemplateAndFoldersSelectionForm(Form):
super().__init__(*args, **kwargs)
self.templates_and_folders.choices = self.ids_and_names(
service.get_template_folders_and_templates(template_type, current_folder_id)
)
self.templates_and_folders.choices = template_list.as_id_and_name
self.move_to.choices = self.ids_and_names(
[self.ALL_TEMPLATES_FOLDER] + service.all_template_folders,
exclude=current_folder_id,
)
@staticmethod
def ids_and_names(items, exclude=None):
return [
(item['id'], item['name']) for item in items
if item['id'] != str(exclude)
self.move_to.choices = [
(item['id'], item['name'])
for item in ([self.ALL_TEMPLATES_FOLDER] + all_template_folders)
if item['id'] != str(current_folder_id)
]
templates_and_folders = MultiCheckboxField('Choose templates or folders')

View File

@@ -109,8 +109,11 @@ def start_tour(service_id, template_id):
@user_has_permissions()
def choose_template(service_id, template_type='all', template_folder_id=None):
template_list = TemplateList(current_service, template_type, template_folder_id)
templates_and_folders_form = TemplateAndFoldersSelectionForm(
service=current_service,
all_template_folders=current_service.all_template_folders,
template_list=template_list,
template_type=template_type,
current_folder_id=template_folder_id,
)
@@ -127,7 +130,7 @@ def choose_template(service_id, template_type='all', template_folder_id=None):
current_template_folder_id=template_folder_id,
can_manage_folders=can_manage_folders(),
template_folder_path=current_service.get_template_folder_path(template_folder_id),
template_list=TemplateList(current_service, template_type, template_folder_id),
template_list=template_list,
show_search_box=current_service.count_of_templates_and_folders > 7,
show_template_nav=(
current_service.has_multiple_template_types

View File

@@ -44,6 +44,10 @@ class TemplateList():
ancestors=ancestors,
)
@property
def as_id_and_name(self):
return [(item.id, item.name) for item in self]
@property
def templates_to_show(self):
return any(self)