plone.resourceeditor/master: Add the move API endpoint to the FileManagerActions class
Oshane Bailey <jenkins-z4DKO/[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.cvs |
|---|---|
| Message-ID | <[email protected]> |
Repository: plone.resourceeditor Branch: refs/heads/master Date: 2017-06-20T05:56:58-05:00 Author: Oshane Bailey (b4oshany) <[email protected]> Commit: https://github.com/plone/plone.resourceeditor/commit/eb2a01f6e6ea58e1cb6584bdc31aa599d4ae114b Add the move API endpoint to the FileManagerActions class Files changed: M CHANGES.rst M plone/resourceeditor/browser.py diff --git a/CHANGES.rst b/CHANGES.rst index 7f33584..283b009 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,6 +11,7 @@ Incompatibilities: New: - *add item here* +- Add the move API endpoint to the FileManagerActions class Fixes: diff --git a/plone/resourceeditor/browser.py b/plone/resourceeditor/browser.py index 112ab07..8d7f511 100644 --- a/plone/resourceeditor/browser.py +++ b/plone/resourceeditor/browser.py @@ -375,6 +375,54 @@ def renameFile(self, path, newName): 'code': code, }) + def move(self, path, directory): + """Move the item at the given path to a new directory + """ + + path = path.encode('utf-8') + directory = directory.encode('utf-8') + + npath = self.normalizePath(path) + newParentPath = self.normalizePath(directory) + + parentPath = self.parentPath(npath) + filename = npath.split('/')[-1] + + code = 0 + error = '' + + try: + parent = self.getObject(parentPath) + target = self.getObject(newParentPath) + except KeyError: + error = translate(_(u'filemanager_invalid_parent', + default=u'Parent folder not found.'), + context=self.request) + code = 1 + else: + if filename not in parent: + error = translate(_(u'filemanager_error_file_not_found', + default=u'File not found.'), + context=self.request) + code = 1 + elif filename in target: + error = translate(_(u'filemanager_error_file_exists', + default=u'File already exists.'), + context=self.request) + code = 1 + else: + obj = parent[filename] + del parent[filename] + target[filename] = obj + + newCanonicalPath = '{0}/{1}'.format(newParentPath, filename) + + return { + 'code': code, + 'error': error, + 'newPath': self.normalizeReturnPath(newCanonicalPath), + } + def __call__(self): action = self.request.get('action') if action == 'dataTree': @@ -429,6 +477,11 @@ def getDirectory(folder, relpath=''): path = self.request.get('path', '') return self.delete(path) + if action == 'move': + src_path = self.request.get('source', '') + des_path = self.request.get('destination', '') + return self.move(src_path, des_path) + class FileManager(BrowserView): """Render the file manager and support its AJAX requests. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot