Add support for per calendar colors.
authorJelmer Vernooij <jelmer@jelmer.uk>
Wed, 13 Jan 2016 02:33:10 +0000 (02:33 +0000)
committerJelmer Vernooij <jelmer@jelmer.uk>
Sat, 9 Apr 2016 22:37:34 +0000 (22:37 +0000)
calypso/webdav.py
calypso/xmlutils.py

index e059d19..34aacce 100644 (file)
@@ -584,6 +584,14 @@ class Collection(object):
             _text = _text + item.text
         return _text
 
+    @property
+    def color(self):
+        """Color."""
+        try:
+            return "#%s" % self.metadata.get('collection', 'color')
+        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError):
+            return None
+
     @property
     def headers(self):
         """Find headers items in collection."""
index af2ad86..7f9c674 100644 (file)
@@ -46,6 +46,7 @@ NAMESPACES = {
     "C": "urn:ietf:params:xml:ns:caldav",
     "A": "urn:ietf:params:xml:ns:carddav",
     "D": "DAV:",
+    "E": "http://apple.com/ns/ical/",
     "CS": "http://calendarserver.org/ns/"}
 
 log = logging.getLogger(__name__)
@@ -177,6 +178,8 @@ def propfind(path, xml_request, collection, depth, context):
                 element.text = item.etag
             elif tag == _tag("D", "displayname") and is_collection:
                 element.text = collection.name
+            elif tag == _tag("E", "calendar-color") and is_collection:
+                element.text = collection.color
             elif tag == _tag("D", "principal-URL"):
                 # TODO: use a real principal URL, read rfc3744-4.2 for info
                 tag = ET.Element(_tag("D", "href"))