summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pykolab/xml/event.py7
-rw-r--r--pykolab/xml/recurrence_rule.py16
-rw-r--r--tests/unit/test-003-event.py17
3 files changed, 37 insertions, 3 deletions
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index 5633d0d..31ea476 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -644,6 +644,13 @@ class Event(object):
return None
+ def get_ical_rrule(self):
+ result = []
+ rrule = self.get_recurrence()
+ if rrule.isValid():
+ result.append(rrule.to_ical())
+ return result
+
def get_location(self):
return self.event.location()
diff --git a/pykolab/xml/recurrence_rule.py b/pykolab/xml/recurrence_rule.py
index a82fec7..30ab10a 100644
--- a/pykolab/xml/recurrence_rule.py
+++ b/pykolab/xml/recurrence_rule.py
@@ -142,6 +142,9 @@ class RecurrenceRule(kolabformat.RecurrenceRule):
def set_byday(self, bdays):
daypos = kolabformat.vectordaypos()
for wday in bdays:
+ if isinstance(wday, str):
+ wday = icalendar.vWeekday(wday)
+
weekday = str(wday)[-2:]
occurrence = int(wday.relative)
if str(wday)[0] == '-':
@@ -177,7 +180,11 @@ class RecurrenceRule(kolabformat.RecurrenceRule):
name_map = dict([(v, k) for (k, v) in map.iteritems()])
return name_map[val] if name_map.has_key(val) else 'UNKNOWN'
- def to_dict(self):
+ def to_ical(self):
+ rrule = icalendar.vRecur(dict((k,v) for k,v in self.to_dict(True).items() if not (type(v) == str and v == '' or type(v) == list and len(v) == 0)))
+ return rrule
+
+ def to_dict(self, raw=False):
if not self.isValid() or self.frequency() == kolabformat.RecurrenceRule.FreqNone:
return None
@@ -194,9 +201,12 @@ class RecurrenceRule(kolabformat.RecurrenceRule):
if isinstance(val, kolabformat.cDateTime):
val = xmlutils.from_cdatetime(val, True)
elif isinstance(val, kolabformat.vectori):
- val = ",".join([int(v) for x in val])
+ val = [int(x) for x in val]
elif isinstance(val, kolabformat.vectordaypos):
- val = ",".join(["%s%s" % (str(x.occurence()) if x.occurence() != 0 else '', self._translate_value(x.weekday(), self.weekday_map)) for x in val])
+ val = ["%s%s" % (str(x.occurence()) if x.occurence() != 0 else '', self._translate_value(x.weekday(), self.weekday_map)) for x in val]
+
+ if not raw and isinstance(val, list):
+ val = ",".join(val)
if val is not None:
data[p] = val
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index c3172f9..cc27e58 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -9,6 +9,7 @@ import pykolab
from pykolab.xml import Attendee
from pykolab.xml import Event
+from pykolab.xml import RecurrenceRule
from pykolab.xml import EventIntegrityError
from pykolab.xml import InvalidAttendeeParticipantStatusError
from pykolab.xml import InvalidEventDateError
@@ -536,6 +537,14 @@ END:VEVENT
self.event.add_custom_property('X-Custom', 'check')
self.event.set_recurrence_id(datetime.datetime(2014, 05, 23, 11, 0, 0), True)
+ rrule = RecurrenceRule()
+ rrule.set_frequency(kolabformat.RecurrenceRule.Weekly)
+ rrule.set_byday(['2WE','-1SU'])
+ rrule.setBymonth([2])
+ rrule.set_count(10)
+ rrule.set_until(datetime.datetime(2014,7,23, 11,0,0, tzinfo=pytz.utc))
+ self.event.set_recurrence(rrule);
+
ical = icalendar.Calendar.from_ical(self.event.as_string_itip())
event = ical.walk('VEVENT')[0]
@@ -548,6 +557,14 @@ END:VEVENT
self.assertIsInstance(event['recurrence-id'].dt, datetime.datetime)
self.assertEqual(event['recurrence-id'].params.get('RANGE'), 'THISANDFUTURE')
+ self.assertTrue(event.has_key('rrule'))
+ self.assertEqual(event['rrule']['FREQ'][0], 'WEEKLY')
+ self.assertEqual(event['rrule']['INTERVAL'][0], 1)
+ self.assertEqual(event['rrule']['COUNT'][0], 10)
+ self.assertEqual(event['rrule']['BYMONTH'][0], 2)
+ self.assertEqual(event['rrule']['BYDAY'], ['2WE','-1SU'])
+ self.assertIsInstance(event['rrule']['UNTIL'][0], datetime.datetime)
+
def test_019_to_message_itip(self):
self.event = Event()
self.event.set_summary("test")