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

@@ -24,5 +24,24 @@ class TemplateFolderAPIClient(NotifyAdminAPIClient):
def get_template_folders(self, service_id):
return self.get('/service/{}/template-folder'.format(service_id))['template_folders']
@cache.delete('service-{service_id}-template-folders')
@cache.delete('service-{service_id}-templates')
def move_to_folder(self, service_id, folder_id, template_ids, folder_ids):
if folder_id:
url = '/service/{}/template-folder/move-to-folder/{}'.format(service_id, folder_id)
else:
url = '/service/{}/template-folder/move-to-folder'.format(service_id)
self.post(url, {
'templates': list(template_ids),
'folders': list(folder_ids),
})
self.redis_client.delete(*map(
'template-{}-version-None'.format,
template_ids,
))
template_folder_api_client = TemplateFolderAPIClient()