diff --git a/caldav/collection.py b/caldav/collection.py index 61880c04..1b48a7d7 100644 --- a/caldav/collection.py +++ b/caldav/collection.py @@ -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 @@ -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 diff --git a/caldav/davobject.py b/caldav/davobject.py index 222cac70..ae49f28d 100644 --- a/caldav/davobject.py +++ b/caldav/davobject.py @@ -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 @@ -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, @@ -63,6 +63,7 @@ def __init__( parent: Optional["DAVObject"] = None, id: str | None = None, props=None, + name: str | None = None, **extra, ) -> None: """ @@ -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: @@ -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) @@ -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