Small improvements for Collection
This commit is contained in:
parent
e09d33f3ee
commit
6b8de92c57
@ -541,8 +541,9 @@ class BaseCollection:
|
|||||||
class Collection(BaseCollection):
|
class Collection(BaseCollection):
|
||||||
"""Collection stored in several files per calendar."""
|
"""Collection stored in several files per calendar."""
|
||||||
|
|
||||||
def __init__(self, path, principal=False, folder=None):
|
def __init__(self, path, principal=None, folder=None):
|
||||||
if not folder:
|
# DEPRECATED: Remove useless principal attribute
|
||||||
|
if folder is None:
|
||||||
folder = self._get_collection_root_folder()
|
folder = self._get_collection_root_folder()
|
||||||
# Path should already be sanitized
|
# Path should already be sanitized
|
||||||
self.path = sanitize_path(path).strip("/")
|
self.path = sanitize_path(path).strip("/")
|
||||||
@ -550,8 +551,9 @@ class Collection(BaseCollection):
|
|||||||
self._filesystem_path = path_to_filesystem(folder, self.path)
|
self._filesystem_path = path_to_filesystem(folder, self.path)
|
||||||
self._props_path = os.path.join(
|
self._props_path = os.path.join(
|
||||||
self._filesystem_path, ".Radicale.props")
|
self._filesystem_path, ".Radicale.props")
|
||||||
split_path = self.path.split("/")
|
self.owner = self.path.split("/", maxsplit=1)[0]
|
||||||
self.owner = split_path[0] if len(split_path) > 1 else None
|
if principal is None:
|
||||||
|
principal = bool(self.path) and "/" not in self.path
|
||||||
self.is_principal = principal
|
self.is_principal = principal
|
||||||
self._meta_cache = None
|
self._meta_cache = None
|
||||||
self._etag_cache = None
|
self._etag_cache = None
|
||||||
@ -660,8 +662,7 @@ class Collection(BaseCollection):
|
|||||||
href = None
|
href = None
|
||||||
|
|
||||||
path = "/".join(attributes)
|
path = "/".join(attributes)
|
||||||
principal = len(attributes) == 1
|
collection = cls(path)
|
||||||
collection = cls(path, principal)
|
|
||||||
|
|
||||||
if href:
|
if href:
|
||||||
yield collection.get(href)
|
yield collection.get(href)
|
||||||
@ -682,8 +683,7 @@ class Collection(BaseCollection):
|
|||||||
path)
|
path)
|
||||||
continue
|
continue
|
||||||
child_path = posixpath.join(path, href)
|
child_path = posixpath.join(path, href)
|
||||||
child_principal = len(attributes) == 0
|
yield cls(child_path)
|
||||||
yield cls(child_path, child_principal)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_collection(cls, href, collection=None, props=None):
|
def create_collection(cls, href, collection=None, props=None):
|
||||||
@ -694,7 +694,6 @@ class Collection(BaseCollection):
|
|||||||
attributes = sane_path.split("/")
|
attributes = sane_path.split("/")
|
||||||
if not attributes[0]:
|
if not attributes[0]:
|
||||||
attributes.pop()
|
attributes.pop()
|
||||||
principal = len(attributes) == 1
|
|
||||||
filesystem_path = path_to_filesystem(folder, sane_path)
|
filesystem_path = path_to_filesystem(folder, sane_path)
|
||||||
|
|
||||||
if not props:
|
if not props:
|
||||||
@ -703,7 +702,7 @@ class Collection(BaseCollection):
|
|||||||
props["tag"] = collection[0].name
|
props["tag"] = collection[0].name
|
||||||
if not props:
|
if not props:
|
||||||
cls._makedirs_synced(filesystem_path)
|
cls._makedirs_synced(filesystem_path)
|
||||||
return cls(sane_path, principal=principal)
|
return cls(sane_path)
|
||||||
|
|
||||||
parent_dir = os.path.dirname(filesystem_path)
|
parent_dir = os.path.dirname(filesystem_path)
|
||||||
cls._makedirs_synced(parent_dir)
|
cls._makedirs_synced(parent_dir)
|
||||||
@ -714,7 +713,7 @@ class Collection(BaseCollection):
|
|||||||
# The temporary directory itself can't be renamed
|
# The temporary directory itself can't be renamed
|
||||||
tmp_filesystem_path = os.path.join(tmp_dir, "collection")
|
tmp_filesystem_path = os.path.join(tmp_dir, "collection")
|
||||||
os.makedirs(tmp_filesystem_path)
|
os.makedirs(tmp_filesystem_path)
|
||||||
self = cls("/", principal=principal, folder=tmp_filesystem_path)
|
self = cls("/", folder=tmp_filesystem_path)
|
||||||
self.set_meta(props)
|
self.set_meta(props)
|
||||||
|
|
||||||
if collection:
|
if collection:
|
||||||
@ -754,7 +753,7 @@ class Collection(BaseCollection):
|
|||||||
os.rename(tmp_filesystem_path, filesystem_path)
|
os.rename(tmp_filesystem_path, filesystem_path)
|
||||||
cls._sync_directory(parent_dir)
|
cls._sync_directory(parent_dir)
|
||||||
|
|
||||||
return cls(sane_path, principal=principal)
|
return cls(sane_path)
|
||||||
|
|
||||||
def upload_all_nonatomic(self, vobject_items):
|
def upload_all_nonatomic(self, vobject_items):
|
||||||
"""DEPRECATED: Use ``_upload_all_nonatomic``"""
|
"""DEPRECATED: Use ``_upload_all_nonatomic``"""
|
||||||
|
Loading…
Reference in New Issue
Block a user