summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2015-02-17 07:16:37 +0100
committerThomas Bruederli <bruederli@kolabsys.com>2015-02-17 07:16:37 +0100
commit28cff75a01981c596051129e7b7f5f3a14781d62 (patch)
tree7287b7df69d12b58eba310fb86c9e52213888699
parent967d68a6f672b7321d2f08c30792c73300f93d1d (diff)
downloadpykolab-28cff75a01981c596051129e7b7f5f3a14781d62.tar.gz
Take recurrence exceptions into accout when checking for conflicts
-rw-r--r--pykolab/itip/__init__.py16
-rw-r--r--tests/unit/test-011-itip.py17
2 files changed, 32 insertions, 1 deletions
diff --git a/pykolab/itip/__init__.py b/pykolab/itip/__init__.py
index cae8075..848b2d7 100644
--- a/pykolab/itip/__init__.py
+++ b/pykolab/itip/__init__.py
@@ -166,12 +166,26 @@ def check_event_conflict(kolab_event, itip_event):
while not conflict and _is is not None:
# log.debug("* Comparing event dates at %s/%s with %s/%s" % (_es, _ee, _is, _ie), level=9)
conflict = check_date_conflict(_es, _ee, _is, _ie)
- _is = to_dt(itip_event['xml'].get_next_occurence(_is)) if kolab_event.is_recurring() else None
+ _is = to_dt(itip_event['xml'].get_next_occurence(_is)) if itip_event['xml'].is_recurring() else None
_ie = to_dt(itip_event['xml'].get_occurence_end_date(_is))
+ # get full occurrence to compare the dates from a possible exception
+ if _is is not None and len(itip_event['xml'].get_exceptions()):
+ _ix = itip_event['xml'].get_instance(_is)
+ if _ix is not None:
+ _is = to_dt(_ix.get_start())
+ _ie = to_dt(_ix.get_end())
+
_es = to_dt(kolab_event.get_next_occurence(_es)) if kolab_event.is_recurring() else None
_ee = to_dt(kolab_event.get_occurence_end_date(_es))
+ # get full instance to compare the dates from a possible exception
+ if _es is not None and len(kolab_event.get_exceptions()):
+ _ex = kolab_event.get_instance(_es)
+ if _ex is not None:
+ _es = to_dt(_ex.get_start())
+ _ee = to_dt(_ex.get_end())
+
return conflict
diff --git a/tests/unit/test-011-itip.py b/tests/unit/test-011-itip.py
index e5edee5..dafa645 100644
--- a/tests/unit/test-011-itip.py
+++ b/tests/unit/test-011-itip.py
@@ -451,6 +451,23 @@ class TestITip(unittest.TestCase):
event4.set_end(datetime.datetime(2012,7,1, 10,30,0, tzinfo=pytz.utc))
self.assertFalse(itip.check_event_conflict(event4, itip_event), "No conflict in two recurring events")
+ itip_event = itip.events_from_message(message_from_string(itip_non_multipart))[0]
+
+ rrule.setFrequency(kolabformat.RecurrenceRule.Daily)
+ rrule.setCount(10)
+
+ event5 = Event()
+ event5.set_recurrence(rrule);
+ event5.set_start(datetime.datetime(2012,7,9, 10,0,0, tzinfo=pytz.timezone("Europe/London")))
+ event5.set_end(datetime.datetime(2012,7,9, 11,0,0, tzinfo=pytz.timezone("Europe/London")))
+
+ exception = Event(from_string=str(event5))
+ exception.set_start(datetime.datetime(2012,7,13, 14,0,0, tzinfo=pytz.timezone("Europe/London")))
+ exception.set_end(datetime.datetime(2012,7,13, 16,0,0, tzinfo=pytz.timezone("Europe/London")))
+ exception.set_recurrence_id(datetime.datetime(2012,7,13, 10,0,0, tzinfo=pytz.timezone("Europe/London")), False)
+ event5.add_exception(exception)
+ self.assertFalse(itip.check_event_conflict(event5, itip_event), "No conflict with exception date")
+
def test_003_send_reply(self):
itip_events = itip.events_from_message(message_from_string(itip_non_multipart))