# HG changeset patch # User Paul Boddie # Date 1446131804 -3600 # Node ID ecd915425718b07ec930a059abd804095a23096a # Parent 0bf0e235f9e22414f57f8cd6f69e916460f42a98 Check corrected periods against the free/busy schedules of all attendees. Used the coalescing of busy periods from attendees followed by the inversion of the result to get the available free periods. diff -r 0bf0e235f9e2 -r ecd915425718 imiptools/handlers/scheduling.py --- a/imiptools/handlers/scheduling.py Wed Oct 28 18:08:40 2015 +0100 +++ b/imiptools/handlers/scheduling.py Thu Oct 29 16:16:44 2015 +0100 @@ -21,16 +21,20 @@ from imiptools.data import uri_values from imiptools.dates import ValidityError, to_timezone -from imiptools.period import get_common_periods, invert_freebusy, \ +from imiptools.period import coalesce_freebusy, invert_freebusy, \ periods_from, remove_event_periods, \ remove_periods -def schedule_in_freebusy(handler): +def schedule_in_freebusy(handler, freebusy=None): """ Attempt to schedule the current object of the given 'handler' in the free/busy schedule of a resource, returning an indication of the kind of response to be returned. + + If 'freebusy' is specified, the given collection of busy periods will be + used to determine whether any conflicts occur. Otherwise, the current user's + free/busy records will be used. """ # If newer than any old version, discard old details from the @@ -38,7 +42,7 @@ periods = handler.get_periods(handler.obj) - freebusy = handler.store.get_freebusy(handler.user) + freebusy = freebusy or handler.store.get_freebusy(handler.user) offers = handler.store.get_freebusy_offers(handler.user) # Check the periods against any scheduled events and against @@ -102,7 +106,7 @@ # There should already be free/busy information for the user. user_freebusy = handler.store.get_freebusy(handler.user) - all_freebusy = [user_freebusy] + busy = user_freebusy # Subtract any periods from this event from the free/busy collections. @@ -115,12 +119,16 @@ freebusy = handler.store.get_freebusy_for_other(handler.user, attendee) if freebusy: remove_periods(freebusy, event_periods) - all_freebusy.append(freebusy) + busy += freebusy + + # Obtain the combined busy periods. + + busy.sort() + busy = coalesce_freebusy(busy) # Obtain free periods. - all_free = [invert_freebusy(fb) for fb in all_freebusy] - free = get_common_periods(all_free) + free = invert_freebusy(busy) permitted_values = handler.get_permitted_values() periods = [] @@ -194,7 +202,7 @@ # Check one last time, reverting the change if not scheduled. - scheduled = schedule_in_freebusy(handler) + scheduled = schedule_in_freebusy(handler, busy) if scheduled == "DECLINED": handler.set_object(obj) diff -r 0bf0e235f9e2 -r ecd915425718 imiptools/period.py --- a/imiptools/period.py Wed Oct 28 18:08:40 2015 +0100 +++ b/imiptools/period.py Thu Oct 29 16:16:44 2015 +0100 @@ -716,33 +716,6 @@ return free -def get_common_periods(all_freebusy): - - "Return common periods to all collections in the 'all_freebusy' list." - - if not all_freebusy: - return None - - common = all_freebusy[0] - - # Intersect periods with the current common set. - - for freebusy in all_freebusy[1:]: - new_common = [] - - # Find the overlapping periods and then obtain the regions that - # are common to both sets. - - for period in freebusy: - for overlapping in get_overlapping(common, period): - p = period.common(overlapping) - if p: - new_common.append(p) - - common = new_common - - return common - # Period layout. def get_scale(periods, tzid, view_period=None):