Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions caldav/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,13 @@ def __init__(
client: A DAVClient instance
url: The url for this calendar. May be a full URL or a relative URL.
parent: The parent object (typically a CalendarSet or Principal)
name: The display name for the calendar
name: The display name for the calendar (stored in props cache)
id: The calendar id (used when creating new calendars)
props: A dict with known properties for this calendar
"""
super().__init__(client=client, url=url, parent=parent, id=id, props=props, **extra)
self.name = name
super().__init__(
client=client, url=url, parent=parent, id=id, props=props, name=name, **extra
)

def _create(
self, name=None, id=None, supported_calendar_component_set=None, method=None
Expand Down Expand Up @@ -986,14 +987,18 @@ def save(self, method=None):
return self._async_save(method)

if self.url is None:
self._create(id=self.id, name=self.name, method=method, **self.extra_init_options)
# Get display name from props cache
display_name = self.props.get("{DAV:}displayname")
self._create(id=self.id, name=display_name, method=method, **self.extra_init_options)
return self

async def _async_save(self, method=None):
"""Async implementation of save."""
if self.url is None:
# Get display name from props cache
display_name = self.props.get("{DAV:}displayname")
await self._async_create(
name=self.name, id=self.id, method=method, **self.extra_init_options
name=display_name, id=self.id, method=method, **self.extra_init_options
)
return self

Expand Down
23 changes: 22 additions & 1 deletion caldav/davobject.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import sys
import warnings
from typing import TYPE_CHECKING, Any, Optional, TypeVar
from urllib.parse import ParseResult, SplitResult, quote, unquote

Expand Down Expand Up @@ -54,7 +55,6 @@ class DAVObject:
url: URL | None = None
client: Optional["DAVClient"] = None
parent: Optional["DAVObject"] = None
name: str | None = None

def __init__(
self,
Expand All @@ -63,6 +63,7 @@ def __init__(
parent: Optional["DAVObject"] = None,
id: str | None = None,
props=None,
name: str | None = None,
**extra,
) -> None:
"""
Expand All @@ -74,6 +75,7 @@ def __init__(
parent: The parent object - used when creating objects
id: The resource id (UID for an Event)
props: a dict with known properties for this object
name: Display name (deprecated, use props={'{DAV:}displayname': name})
"""

if client is None and parent is not None:
Expand All @@ -83,6 +85,10 @@ def __init__(
self.id = id
self.props = props or {}
self.extra_init_options = extra

# Store name in props cache as displayname
if name is not None:
self.props["{DAV:}displayname"] = name
# url may be a path relative to the caldav root
if client and url:
self.url = client.url.join(url)
Expand Down Expand Up @@ -584,6 +590,21 @@ def get_display_name(self):
"""
return self.get_property(dav.DisplayName(), use_cached=True)

@property
def name(self) -> str | None:
"""
Display name of this DAV object.

.. deprecated:: 3.0
Use :meth:`get_display_name` instead.
"""
warnings.warn(
"The 'name' attribute is deprecated. Use get_display_name() instead.",
DeprecationWarning,
stacklevel=2,
)
return self.get_display_name()

def __str__(self) -> str:
try:
return str(self.get_property(dav.DisplayName(), use_cached=True)) or self.url
Expand Down