1.1 --- a/imiptools/handlers/resource.py Sat Sep 12 19:58:59 2015 +0200
1.2 +++ b/imiptools/handlers/resource.py Sat Sep 12 20:16:38 2015 +0200
1.3 @@ -103,58 +103,54 @@
1.4
1.5 periods = self.obj.get_periods(tzid, self.get_window_end())
1.6
1.7 - freebusy = self.store.get_freebusy_for_update(self.user)
1.8 - try:
1.9 - offers = self.store.get_freebusy_offers(self.user)
1.10 + freebusy = self.store.get_freebusy(self.user)
1.11 + offers = self.store.get_freebusy_offers(self.user)
1.12 +
1.13 + # Check the periods against any scheduled events and against
1.14 + # any outstanding offers.
1.15
1.16 - # Check the periods against any scheduled events and against
1.17 - # any outstanding offers.
1.18 + scheduled = self.can_schedule(freebusy, periods)
1.19 + scheduled = scheduled and self.can_schedule(offers, periods)
1.20
1.21 - scheduled = self.can_schedule(freebusy, periods)
1.22 - scheduled = scheduled and self.can_schedule(offers, periods)
1.23 + # Where the corrected object can be scheduled, issue a counter
1.24 + # request.
1.25
1.26 - # Where the corrected object can be scheduled, issue a counter
1.27 - # request.
1.28 + if scheduled and corrected:
1.29 + method = "COUNTER"
1.30
1.31 - if scheduled and corrected:
1.32 - method = "COUNTER"
1.33 + # Find the next available slot if the event cannot be scheduled.
1.34
1.35 - # Find the next available slot if the event cannot be scheduled.
1.36 -
1.37 - #elif not scheduled and len(periods) == 1:
1.38 + #elif not scheduled and len(periods) == 1:
1.39
1.40 - # # Find a free period, update the object with the details.
1.41 + # # Find a free period, update the object with the details.
1.42
1.43 - # duration = periods[0].get_duration()
1.44 - # free = invert_freebusy(freebusy)
1.45 + # duration = periods[0].get_duration()
1.46 + # free = invert_freebusy(freebusy)
1.47
1.48 - # for found in periods_from(free, periods[0]):
1.49 - # # NOTE: Correct the found period first.
1.50 - # if found.get_duration() >= duration
1.51 - # scheduled = True
1.52 - # method = "COUNTER"
1.53 - # # NOTE: Set the period using the original duration.
1.54 - # break
1.55 + # for found in periods_from(free, periods[0]):
1.56 + # # NOTE: Correct the found period first.
1.57 + # if found.get_duration() >= duration
1.58 + # scheduled = True
1.59 + # method = "COUNTER"
1.60 + # # NOTE: Set the period using the original duration.
1.61 + # break
1.62
1.63 - # Update the participation of the resource in the object.
1.64 -
1.65 - attendee_attr = self.update_participation(self.obj,
1.66 - scheduled and "ACCEPTED" or "DECLINED")
1.67 + # Update the participation of the resource in the object.
1.68
1.69 - # Update free/busy information.
1.70 + attendee_attr = self.update_participation(self.obj,
1.71 + scheduled and "ACCEPTED" or "DECLINED")
1.72
1.73 - if method == "REPLY":
1.74 - self.update_event_in_freebusy(for_organiser=False)
1.75 - self.remove_event_from_freebusy_offers()
1.76 + # Update free/busy information.
1.77
1.78 - # For countered proposals, record the offer in the resource's
1.79 - # free/busy collection.
1.80 + if method == "REPLY":
1.81 + self.update_event_in_freebusy(for_organiser=False)
1.82 + self.remove_event_from_freebusy_offers()
1.83
1.84 - elif method == "COUNTER":
1.85 - self.update_event_in_freebusy_offers()
1.86 + # For countered proposals, record the offer in the resource's
1.87 + # free/busy collection.
1.88
1.89 - finally:
1.90 - self.store.release_freebusy(self.user)
1.91 + elif method == "COUNTER":
1.92 + self.update_event_in_freebusy_offers()
1.93
1.94 # Set the complete event or an additional occurrence.
1.95