Post to the API when moving folders and templates

This commit adds logic to:
- take the list of selected folders and templates
- split it into two lists (of folders and templates)
- `POST` that data to the API, to effect the movement of said folders
  and templates

I’ve tried to architect it in such a way that we can easily add more
template ‘operations’ in the future, as we add more forms to the choose
template page.
This commit is contained in:
Chris Hill-Scott
2018-11-08 14:46:18 +00:00
parent 980d66bdaa
commit cdb5b47c4d
10 changed files with 322 additions and 25 deletions

View File

@@ -702,7 +702,7 @@ class ServicePostageForm(StripWhitespaceForm):
)
class BrandingStyle(RadioField):
class RadioFieldWithNoneOption(RadioField):
def post_validate(self, form, validation_stopped):
if self.data == 'None':
@@ -711,7 +711,7 @@ class BrandingStyle(RadioField):
class ServiceSetBranding(StripWhitespaceForm):
branding_style = BrandingStyle(
branding_style = RadioFieldWithNoneOption(
'Branding style',
validators=[
DataRequired()
@@ -1124,7 +1124,7 @@ class TemplateAndFoldersSelectionForm(Form):
ALL_TEMPLATES_FOLDER = {
'name': 'All templates',
'id': None,
'id': 'None',
}
def __init__(
@@ -1151,8 +1151,8 @@ class TemplateAndFoldersSelectionForm(Form):
def ids_and_names(items, exclude=None):
return [
(item['id'], item['name']) for item in items
if item['id'] != exclude
if item['id'] != str(exclude)
]
templates_and_folders = MultiCheckboxField('Choose templates or folders')
move_to = RadioField('Choose a folder')
move_to = RadioFieldWithNoneOption('Choose a folder')