# HG changeset patch # User Paul Boddie # Date 1428438606 -7200 # Node ID e2704746829869adbea80e3d2d7dfc2b371501c8 # Parent c77e0aa41eb0dc5d9308d6676305036fbd6bb4ff Fixed date-based recurrence identifier conversion for free/busy period matching. diff -r c77e0aa41eb0 -r e27047468298 imiptools/handlers/__init__.py --- a/imiptools/handlers/__init__.py Tue Apr 07 22:28:52 2015 +0200 +++ b/imiptools/handlers/__init__.py Tue Apr 07 22:30:06 2015 +0200 @@ -26,7 +26,7 @@ from imiptools.data import Object, \ get_address, get_uri, get_value, \ is_new_object, uri_dict, uri_item, uri_values -from imiptools.dates import format_datetime, to_timezone +from imiptools.dates import format_datetime, to_recurrence_start, to_timezone from imiptools.period import can_schedule, remove_period, \ remove_additional_periods, remove_affected_period, \ update_freebusy @@ -120,6 +120,12 @@ # Convenience methods for modifying free/busy collections. + def to_recurrence_start(self, recurrenceid): + + "Get 'recurrenceid' in a form suitable for matching free/busy entries." + + return to_recurrence_start(recurrenceid, self.get_tzid()) + def remove_from_freebusy(self, freebusy): "Remove this event from the given 'freebusy' collection." @@ -137,7 +143,8 @@ """ if self.recurrenceid: - remove_affected_period(freebusy, self.uid, self.recurrenceid) + recurrenceid = self.to_recurrence_start(self.recurrenceid) + remove_affected_period(freebusy, self.uid, recurrenceid) else: # Remove obsolete recurrence periods. @@ -147,6 +154,7 @@ if recurrenceids: for recurrenceid in recurrenceids: + recurrenceid = self.to_recurrence_start(recurrenceid) remove_affected_period(freebusy, self.uid, recurrenceid) def _update_freebusy(self, freebusy, periods, recurrenceid, transp=None): @@ -480,8 +488,6 @@ # Set the complete event if not an additional occurrence. event = obj.to_node() - recurrenceid = format_datetime(obj.get_utc_datetime("RECURRENCE-ID")) - self.store.set_event(self.user, self.uid, self.recurrenceid, event) return True diff -r c77e0aa41eb0 -r e27047468298 imiptools/period.py --- a/imiptools/period.py Tue Apr 07 22:28:52 2015 +0200 +++ b/imiptools/period.py Tue Apr 07 22:30:06 2015 +0200 @@ -157,22 +157,23 @@ else: i += 1 -def remove_affected_period(freebusy, uid, recurrenceid): +def remove_affected_period(freebusy, uid, start): """ Remove from 'freebusy' a period associated with 'uid' that provides an - occurrence starting at the given 'recurrenceid', where the recurrence - identifier is used to provide an alternative time period whilst also acting - as a reference to the originally-defined occurrence. + occurrence starting at the given 'start' (provided by a recurrence + identifier, converted to a datetime). A recurrence identifier is used to + provide an alternative time period whilst also acting as a reference to the + originally-defined occurrence. """ - found = bisect_left(freebusy, Period(recurrenceid)) + found = bisect_left(freebusy, Period(start)) while found < len(freebusy): fb = freebusy[found] # Stop looking if the start no longer matches the recurrence identifier. - if fb.start != recurrenceid: + if fb.start != start: return # If the period belongs to the parent object, remove it and return. diff -r c77e0aa41eb0 -r e27047468298 imipweb/resource.py --- a/imipweb/resource.py Tue Apr 07 22:28:52 2015 +0200 +++ b/imipweb/resource.py Tue Apr 07 22:30:06 2015 +0200 @@ -22,7 +22,7 @@ from datetime import datetime from imiptools.client import Client from imiptools.data import get_uri, get_window_end, Object, uri_values -from imiptools.dates import format_datetime, format_time +from imiptools.dates import format_datetime, format_time, to_recurrence_start from imiptools.period import FreeBusyPeriod, \ remove_period, remove_affected_period, update_freebusy from imipweb.env import CGIEnvironment @@ -202,7 +202,7 @@ # object. for recurrenceid in self._get_recurrences(uid): - remove_affected_period(freebusy, uid, recurrenceid) + remove_affected_period(freebusy, uid, to_recurrence_start(recurrenceid)) self.store.set_freebusy(self.user, freebusy) self.publish_freebusy(freebusy)