Display the template folders nested on the move template/folder form

Before, all the folders were displayed in a list which was ordered but
not nested. This changes the move form to nest the template folders.
This commit is contained in:
Tom Byers
2018-12-18 14:40:53 +00:00
committed by Katie Smith
parent 36656fd6ba
commit 3c4a186a25
5 changed files with 86 additions and 17 deletions

View File

@@ -742,6 +742,26 @@ class RadioFieldWithNoneOption(FieldWithNoneOption, RadioField):
pass
class NestedRadioField(RadioFieldWithNoneOption):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def children(self):
child_map = {}
child_ids = [
folder['id'] for folder in self.all_template_folders
if folder['parent_id'] is None]
child_map[None] = [option for idx, option in enumerate(self) if option.data in child_ids or idx == 0]
for option in self:
child_ids = [
folder['id'] for folder in self.all_template_folders
if folder['parent_id'] == option.data]
child_map[option.data] = [option for option in self if option.data in child_ids]
return child_map
class HiddenFieldWithNoneOption(FieldWithNoneOption, HiddenField):
pass
@@ -1207,7 +1227,6 @@ class TemplateAndFoldersSelectionForm(Form):
self,
all_template_folders,
template_list,
current_folder_id,
allow_adding_letter_template,
allow_adding_copy_of_template,
*args,
@@ -1221,13 +1240,10 @@ class TemplateAndFoldersSelectionForm(Form):
self.op = None
self.is_move_op = self.is_add_folder_op = self.is_add_template_op = False
if current_folder_id is None:
current_folder_id = RadioFieldWithNoneOption.NONE_OPTION_VALUE
self.move_to.all_template_folders = all_template_folders
self.move_to.choices = [
(item['id'], item['name'])
for item in ([self.ALL_TEMPLATES_FOLDER] + all_template_folders)
if item['id'] != current_folder_id
]
self.add_template_by_template_type.choices = list(filter(None, [
@@ -1262,10 +1278,12 @@ class TemplateAndFoldersSelectionForm(Form):
templates_and_folders = MultiCheckboxField('Choose templates or folders', validators=[
required_for_ops('move-to-new-folder', 'move-to-existing-folder')
])
move_to = RadioFieldWithNoneOption('Choose a folder', validators=[
Optional(),
required_for_ops('move-to-new-folder', 'move-to-existing-folder')
])
move_to = NestedRadioField(
'Choose a folder',
validators=[
Optional(),
required_for_ops('move-to-new-folder', 'move-to-existing-folder')
])
add_new_folder_name = StringField('Folder name', validators=[required_for_ops('add-new-folder')])
move_to_new_folder_name = StringField('Folder name', validators=[required_for_ops('move-to-new-folder')])