Add is-addressbook and is-calendar settings.
authorJelmer Vernooij <jelmer@jelmer.uk>
Sat, 9 Apr 2016 18:04:12 +0000 (18:04 +0000)
committerJelmer Vernooij <jelmer@jelmer.uk>
Sat, 9 Apr 2016 22:48:00 +0000 (22:48 +0000)
This is necessary acal (for which every collection is either an address
book or a calendar).

Both settings default to True (current behaviour).

Based on patches by chrysn.

README
calypso/webdav.py
calypso/xmlutils.py
collection-config

diff --git a/README b/README
index f79d693fbd2c9765ea933ca34539fbadfea2745b..398e00065c4104b465d9e00f42cc24ccc6ac2e75 100644 (file)
--- a/README
+++ b/README
@@ -47,13 +47,21 @@ To add a new database:
 $ mkdir -p ~/.config/calypso/calendars/private/test
 $ cd ~/.config/calypso/calendars/private/test
 $ git init
-$ git commit --allow-empty -m'initialize new calendar'
+$ cat > .calypso-collection << EOF
+[collection]
+is-calendar = 1
+EOF
+$ git add .calypso-collection
+$ git commit -m'initialize new calendar'
 
 The new calendar should now be visible as https://USER:PASSWORD@localhost:5233/private/test.
 
 You can add files to the directory at any time; calypso will check the
 directory mtime at each operation and update its internal state from
-that on disk automatically when the directory changes.  Importing files
+that on disk automatically when the directory changes.
+
+Importing files
+---------------
 
 Given a set of files with VCALENDAR or VCARD entries, you can import them with:
 
index 34aacce4e812f05a4c3ec60b410bdcb9bb2fe83f..c6f9a0d18e44906ee385ebebbdc1d1f826aa34b4 100644 (file)
@@ -616,3 +616,17 @@ class Collection(object):
     @property
     def length(self):
         return "%d" % len(self.text)
+
+    @property
+    def is_addressbook(self):
+        try:
+            return self.metadata.getboolean('collection', 'is-addressbook')
+        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError):
+            return True
+
+    @property
+    def is_calendar(self):
+        try:
+            return self.metadata.getboolean('collection', 'is-calendar')
+        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError):
+            return True
index 7f9c67427ee1b984842e83f1918dd21bce5a5d4b..be8b5562656bcd8d9cd8b6ff985c62771191281c 100644 (file)
@@ -159,10 +159,12 @@ def propfind(path, xml_request, collection, depth, context):
         for tag in props:
             element = ET.Element(tag)
             if tag == _tag("D", "resourcetype") and is_collection:
-                tag = ET.Element(_tag("C", "calendar"))
-                element.append(tag)
-                tag = ET.Element(_tag("A", "addressbook"))
-                element.append(tag)
+                if collection.is_calendar:
+                    tag = ET.Element(_tag("C", "calendar"))
+                    element.append(tag)
+                if collection.is_addressbook:
+                    tag = ET.Element(_tag("A", "addressbook"))
+                    element.append(tag)
                 tag = ET.Element(_tag("D", "collection"))
                 element.append(tag)
             elif tag == _tag("D", "owner"):
index 4ce34a4f880736da48b419414e490accd2769800..c1a2e24220f05d928b28974687f144b0d1a8e3a6 100644 (file)
@@ -11,4 +11,11 @@ displayname = My Calendar
 # WebDAV properties. Defaults to the collection's path.
 description = Collection of all my personal dates.
 
+# Advertise this collection as a calendar. If this setting is absent,
+# it defaults to True.
+is-calendar = 1
+# Advertise this collection as an address book. Behaves in analogy to
+# is-calendar.
+is-addressbook = 0
+
 # vim:ft=cfg