1.1 --- a/imiptools/handlers/scheduling.py Wed Oct 28 18:08:40 2015 +0100
1.2 +++ b/imiptools/handlers/scheduling.py Thu Oct 29 16:16:44 2015 +0100
1.3 @@ -21,16 +21,20 @@
1.4
1.5 from imiptools.data import uri_values
1.6 from imiptools.dates import ValidityError, to_timezone
1.7 -from imiptools.period import get_common_periods, invert_freebusy, \
1.8 +from imiptools.period import coalesce_freebusy, invert_freebusy, \
1.9 periods_from, remove_event_periods, \
1.10 remove_periods
1.11
1.12 -def schedule_in_freebusy(handler):
1.13 +def schedule_in_freebusy(handler, freebusy=None):
1.14
1.15 """
1.16 Attempt to schedule the current object of the given 'handler' in the
1.17 free/busy schedule of a resource, returning an indication of the kind of
1.18 response to be returned.
1.19 +
1.20 + If 'freebusy' is specified, the given collection of busy periods will be
1.21 + used to determine whether any conflicts occur. Otherwise, the current user's
1.22 + free/busy records will be used.
1.23 """
1.24
1.25 # If newer than any old version, discard old details from the
1.26 @@ -38,7 +42,7 @@
1.27
1.28 periods = handler.get_periods(handler.obj)
1.29
1.30 - freebusy = handler.store.get_freebusy(handler.user)
1.31 + freebusy = freebusy or handler.store.get_freebusy(handler.user)
1.32 offers = handler.store.get_freebusy_offers(handler.user)
1.33
1.34 # Check the periods against any scheduled events and against
1.35 @@ -102,7 +106,7 @@
1.36 # There should already be free/busy information for the user.
1.37
1.38 user_freebusy = handler.store.get_freebusy(handler.user)
1.39 - all_freebusy = [user_freebusy]
1.40 + busy = user_freebusy
1.41
1.42 # Subtract any periods from this event from the free/busy collections.
1.43
1.44 @@ -115,12 +119,16 @@
1.45 freebusy = handler.store.get_freebusy_for_other(handler.user, attendee)
1.46 if freebusy:
1.47 remove_periods(freebusy, event_periods)
1.48 - all_freebusy.append(freebusy)
1.49 + busy += freebusy
1.50 +
1.51 + # Obtain the combined busy periods.
1.52 +
1.53 + busy.sort()
1.54 + busy = coalesce_freebusy(busy)
1.55
1.56 # Obtain free periods.
1.57
1.58 - all_free = [invert_freebusy(fb) for fb in all_freebusy]
1.59 - free = get_common_periods(all_free)
1.60 + free = invert_freebusy(busy)
1.61 permitted_values = handler.get_permitted_values()
1.62 periods = []
1.63
1.64 @@ -194,7 +202,7 @@
1.65
1.66 # Check one last time, reverting the change if not scheduled.
1.67
1.68 - scheduled = schedule_in_freebusy(handler)
1.69 + scheduled = schedule_in_freebusy(handler, busy)
1.70
1.71 if scheduled == "DECLINED":
1.72 handler.set_object(obj)