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>
Thu, 14 Jan 2016 01:38:56 +0000 (01:38 +0000)
calypso/webdav.py
calypso/xmlutils.py

index 238067a33f91346b88b75d4523f6a6467aa32739..4db857536f2e79f2daf8376ffda5d912770a8a43 100644 (file)
@@ -563,6 +563,13 @@ class Collection(object):
         self.scan_dir(False)
         return self.my_items
 
+    def get_color(self):
+        """Color."""
+        try:
+            return "#%s" % self.metadata.get('collection', 'color')
+        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, ValueError):
+            return None
+
     @property
     def last_modified(self):
         """Get the last time the collection has been modified.
index f9d73d754f2093d91d197696d8bb0ef67d1c8896..e94a5e928848c0c925ba8b716e6171787d2c0128 100644 (file)
@@ -48,6 +48,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__)
@@ -179,6 +180,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 = item.get_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"))