From 23582c8208ad74f7ca30c68b5d6b6bb42bee109f Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 6 Aug 2016 04:47:17 +0200 Subject: [PATCH] Expose low level MOVE operation in storage.BaseCollection --- radicale/__init__.py | 7 +------ radicale/storage.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index b7b70c7..ba49af5 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -496,12 +496,7 @@ class Application: if not to_collection: return client.CONFLICT, {}, None to_href = posixpath.basename(to_path.strip("/")) - if path.strip("/") != to_path.strip("/"): - if to_item: - to_collection.update(to_href, item.item) - else: - to_collection.upload(to_href, item.item) - item.collection.delete(item.href) + self.Collection.move(item, to_collection, to_href) return client.CREATED, {}, None def do_OPTIONS(self, environ, path, content, user): diff --git a/radicale/storage.py b/radicale/storage.py index d14797f..e8d84b1 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -265,6 +265,26 @@ class BaseCollection: """ raise NotImplementedError + @classmethod + def move(cls, item, to_collection, to_href): + """Move an object. + + ``item`` is the item to move. + + ``to_collection`` is the target collection. + + ``to_href`` is the target name in ``to_collection``. An item with the + same name might already exist. + + """ + if item.collection.path == to_collection.path and item.href == to_href: + return + if to_collection.has(to_href): + to_collection.update(to_href, item.item) + else: + to_collection.upload(to_href, item.item) + item.collection.delete(item.href) + @property def etag(self): return get_etag(self.serialize())