[CalendarServer-changes] [9940] CalendarServer/trunk/txdav
source_changes at macosforge.org
source_changes at macosforge.org
Mon Oct 15 14:25:32 PDT 2012
Revision: 9940
http://trac.calendarserver.org//changeset/9940
Author: wsanchez at apple.com
Date: 2012-10-15 14:25:32 -0700 (Mon, 15 Oct 2012)
Log Message:
-----------
Add displayName() and setDisplayName() methods to ICalendar.
Modified Paths:
--------------
CalendarServer/trunk/txdav/caldav/datastore/test/common.py
CalendarServer/trunk/txdav/caldav/icalendarstore.py
CalendarServer/trunk/txdav/common/datastore/file.py
CalendarServer/trunk/txdav/common/datastore/sql.py
Added Paths:
-----------
CalendarServer/trunk/txdav/common/datastore/common.py
Modified: CalendarServer/trunk/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/common.py 2012-10-15 21:22:35 UTC (rev 9939)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/common.py 2012-10-15 21:25:32 UTC (rev 9940)
@@ -574,12 +574,14 @@
self.assertEquals(calendar.notifierID(), "CalDAV|home1")
self.assertEquals(calendar.notifierID(label="collection"), "CalDAV|home1/calendar_1")
+
@inlineCallbacks
def test_nodeNameSuccess(self):
home = yield self.homeUnderTest()
name = yield home.nodeName()
self.assertEquals(name, "/CalDAV/example.com/home1/")
+
@inlineCallbacks
def test_nodeNameFailure(self):
# The StubNodeCacher is set up to fail when the node name has the
@@ -589,7 +591,49 @@
name = yield home.nodeName()
self.assertEquals(name, None)
+
@inlineCallbacks
+ def test_displayNameNone(self):
+ """
+ L{ICalendarHome.calendarWithName} returns C{None} for calendars which
+ do not exist.
+ """
+ home = (yield self.homeUnderTest())
+ calendar = (yield home.calendarWithName("calendar_1"))
+ name = (yield calendar.displayName())
+ self.assertEquals(name, None)
+
+
+ @inlineCallbacks
+ def test_setDisplayName(self):
+ """
+ L{ICalendarHome.calendarWithName} returns C{None} for calendars which
+ do not exist.
+ """
+ home = (yield self.homeUnderTest())
+ calendar = (yield home.calendarWithName("calendar_1"))
+
+ calendar.setDisplayName(u"quux")
+ name = calendar.displayName()
+ self.assertEquals(name, u"quux")
+
+ calendar.setDisplayName(None)
+ name = calendar.displayName()
+ self.assertEquals(name, None)
+
+
+ @inlineCallbacks
+ def test_setDisplayNameBytes(self):
+ """
+ L{ICalendarHome.calendarWithName} returns C{None} for calendars which
+ do not exist.
+ """
+ home = (yield self.homeUnderTest())
+ calendar = (yield home.calendarWithName("calendar_1"))
+ self.assertRaises(ValueError, calendar.setDisplayName, "quux")
+
+
+ @inlineCallbacks
def test_calendarHomeWithUID_exists(self):
"""
Finding an existing calendar home by UID results in an object that
Modified: CalendarServer/trunk/txdav/caldav/icalendarstore.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/icalendarstore.py 2012-10-15 21:22:35 UTC (rev 9939)
+++ CalendarServer/trunk/txdav/caldav/icalendarstore.py 2012-10-15 21:25:32 UTC (rev 9940)
@@ -260,7 +260,20 @@
Change the name of this calendar.
"""
+ def displayName():
+ """
+ Get the display name of this calendar.
+ @return: a unicode string.
+ """
+
+ def setDisplayName(name):
+ """
+ Set the display name of this calendar.
+
+ @param name: a C{unicode}.
+ """
+
def ownerCalendarHome():
"""
Retrieve the calendar home for the owner of this calendar. Calendars
Added: CalendarServer/trunk/txdav/common/datastore/common.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/common.py (rev 0)
+++ CalendarServer/trunk/txdav/common/datastore/common.py 2012-10-15 21:25:32 UTC (rev 9940)
@@ -0,0 +1,55 @@
+# -*- test-case-name: txdav -*-
+##
+# Copyright (c) 2012 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+"""
+Common functionality that is the same for different data store
+implementations.
+"""
+
+__all__ = [
+]
+
+
+from txdav.xml.element import DisplayName
+from txdav.base.propertystore.base import PropertyName
+
+
+class HomeChildBase(object):
+ """
+ Home child (address book or calendar) common functionality.
+ """
+
+ def displayName(self):
+ name = self.properties().get(PropertyName.fromElement(DisplayName), None)
+ if name is None:
+ return None
+ else:
+ return name.toString()
+
+
+ def setDisplayName(self, name):
+ if name is None:
+ del self.properties()[PropertyName.fromElement(DisplayName)]
+ else:
+ if not isinstance(name, unicode):
+ raise ValueError("Display name must be unicode: %r" % (name,))
+
+ self.properties()[
+ PropertyName.fromElement(DisplayName)
+ ] = DisplayName.fromString(name)
+
+ return None
Modified: CalendarServer/trunk/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/file.py 2012-10-15 21:22:35 UTC (rev 9939)
+++ CalendarServer/trunk/txdav/common/datastore/file.py 2012-10-15 21:25:32 UTC (rev 9940)
@@ -38,6 +38,7 @@
from twistedcaldav.sharing import SharedCollectionsDatabase
from txdav.caldav.icalendarstore import ICalendarStore, BIND_OWN
+from txdav.common.datastore.common import HomeChildBase
from txdav.common.icommondatastore import HomeChildNameNotAllowedError, \
HomeChildNameAlreadyExistsError, NoSuchHomeChildError, \
InternalDataStoreError, ObjectResourceNameNotAllowedError, \
@@ -632,7 +633,7 @@
self._transaction.notificationAddedForObject(self)
-class CommonHomeChild(FileMetaDataMixin, LoggingMixIn, FancyEqMixin):
+class CommonHomeChild(FileMetaDataMixin, LoggingMixIn, FancyEqMixin, HomeChildBase):
"""
Common ancestor class of AddressBooks and Calendars.
"""
Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py 2012-10-15 21:22:35 UTC (rev 9939)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py 2012-10-15 21:25:32 UTC (rev 9940)
@@ -31,7 +31,8 @@
from twext.python.log import Logger, LoggingMixIn
from twisted.python.log import msg as log_msg, err as log_err
-from txdav.xml.rfc2518 import ResourceType
+
+from txdav.xml.element import ResourceType
from txdav.xml.parser import WebDAVDocument
from twext.web2.http_headers import MimeType
@@ -53,6 +54,7 @@
from txdav.carddav.iaddressbookstore import IAddressBookTransaction
+from txdav.common.datastore.common import HomeChildBase
from txdav.common.datastore.sql_tables import schema
from txdav.common.datastore.sql_tables import _BIND_MODE_OWN, \
_BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, \
@@ -1982,7 +1984,7 @@
-class CommonHomeChild(LoggingMixIn, FancyEqMixin, _SharedSyncLogic):
+class CommonHomeChild(LoggingMixIn, FancyEqMixin, _SharedSyncLogic, HomeChildBase):
"""
Common ancestor class of AddressBooks and Calendars.
"""
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20121015/c063ded8/attachment-0001.html>
More information about the calendarserver-changes
mailing list