[Calypso] [PATCH] Add support for per calendar colors.

Jelmer Vernooij jelmer at jelmer.uk
Tue Jan 12 18:34:44 PST 2016


From: Jelmer Vernooij <jelmer at jelmer.uk>

---
 calypso/webdav.py   | 7 +++++++
 calypso/xmlutils.py | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/calypso/webdav.py b/calypso/webdav.py
index 238067a..4db8575 100644
--- a/calypso/webdav.py
+++ b/calypso/webdav.py
@@ -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.
diff --git a/calypso/xmlutils.py b/calypso/xmlutils.py
index f9d73d7..e94a5e9 100644
--- a/calypso/xmlutils.py
+++ b/calypso/xmlutils.py
@@ -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"))
-- 
2.7.0.rc3



More information about the Calypso mailing list