summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-08-04 16:49:51 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2014-08-04 16:49:51 (GMT)
commit5a171ddd85f7f8e57685a469d3de3fc3bb6a99ab (patch)
tree491c67102e8e3b8c32089aaa20597cc3924e73a8
parent0813c350ed72c595bdee53e9c78490d8eccf7e98 (diff)
downloadpykolab-5a171ddd85f7f8e57685a469d3de3fc3bb6a99ab.tar.gz
Allow to set custom event properties and add them in iCal export
-rw-r--r--pykolab/xml/event.py12
-rw-r--r--tests/unit/test-003-event.py2
2 files changed, 14 insertions, 0 deletions
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index 213e43e..534134f 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -197,6 +197,10 @@ class Event(object):
for _retval in retval:
event.add(attr.lower(), _retval, encode=0)
+ # copy custom properties to iCal
+ for cs in self.event.customProperties():
+ event.add(cs.identifier, cs.value)
+
cal.add_component(event)
if hasattr(cal, 'to_ical'):
@@ -635,6 +639,14 @@ class Event(object):
for _datetime in _datetimes:
self.add_exception_date(_datetime)
+ def add_custom_property(self, name, value):
+ if not name.upper().startswith('X-'):
+ raise ValueError, _("Invalid custom property name %r") % (name)
+
+ props = self.event.customProperties()
+ props.append(kolabformat.CustomProperty(name, value))
+ self.event.setCustomProperties(props)
+
def set_from_ical(self, attr, value):
ical_setter = 'set_ical_' + attr
default_setter = 'set_' + attr
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index f069be3..45a817c 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -417,6 +417,7 @@ END:VEVENT
self.event.set_start(datetime.datetime(2014, 05, 23, 11, 00, 00, tzinfo=pytz.timezone("Europe/London")))
self.event.set_end(datetime.datetime(2014, 05, 23, 12, 30, 00, tzinfo=pytz.timezone("Europe/London")))
self.event.set_sequence(3)
+ self.event.add_custom_property('X-CUSTOM', 'check')
ical = icalendar.Calendar.from_ical(self.event.as_string_itip())
event = ical.walk('VEVENT')[0]
@@ -424,6 +425,7 @@ END:VEVENT
self.assertEqual(event['uid'], self.event.get_uid())
self.assertEqual(event['summary'], "test")
self.assertEqual(event['sequence'], 3)
+ self.assertEqual(event['X-CUSTOM'], "check")
self.assertIsInstance(event['dtstamp'].dt, datetime.datetime)
def test_020_calendaring_recurrence(self):