1.1 --- a/imiptools/handlers/resource.py Mon Feb 08 00:14:53 2016 +0100
1.2 +++ b/imiptools/handlers/resource.py Mon Feb 08 00:47:00 2016 +0100
1.3 @@ -23,7 +23,9 @@
1.4 from imiptools.handlers import Handler
1.5 from imiptools.handlers.common import CommonFreebusy, CommonEvent
1.6 from imiptools.handlers.scheduling import apply_scheduling_functions, \
1.7 - confirm_scheduling, retract_scheduling
1.8 + confirm_scheduling, \
1.9 + finish_scheduling, \
1.10 + retract_scheduling
1.11
1.12 class ResourceHandler(CommonEvent, Handler):
1.13
1.14 @@ -87,49 +89,56 @@
1.15 "Attempt to schedule the current object for the current user."
1.16
1.17 attendee_attr = uri_dict(self.obj.get_value_map("ATTENDEE"))[self.user]
1.18 +
1.19 + # Attempt to schedule the event.
1.20 +
1.21 scheduled = self.schedule()
1.22
1.23 - # Update the participation of the resource in the object.
1.24 - # Update free/busy information.
1.25 + try:
1.26 + # Update the participation of the resource in the object.
1.27 + # Update free/busy information.
1.28
1.29 - if scheduled in ("ACCEPTED", "DECLINED"):
1.30 - method = "REPLY"
1.31 - attendee_attr = self.update_participation(scheduled)
1.32 + if scheduled in ("ACCEPTED", "DECLINED"):
1.33 + method = "REPLY"
1.34 + attendee_attr = self.update_participation(scheduled)
1.35
1.36 - self.update_event_in_freebusy(for_organiser=False)
1.37 - self.remove_event_from_freebusy_offers()
1.38 + self.update_event_in_freebusy(for_organiser=False)
1.39 + self.remove_event_from_freebusy_offers()
1.40
1.41 - # Set the complete event or an additional occurrence.
1.42 + # Set the complete event or an additional occurrence.
1.43
1.44 - event = self.obj.to_node()
1.45 - self.store.set_event(self.user, self.uid, self.recurrenceid, event)
1.46 + event = self.obj.to_node()
1.47 + self.store.set_event(self.user, self.uid, self.recurrenceid, event)
1.48
1.49 - # Remove additional recurrences if handling a complete event.
1.50 - # Also remove any previous cancellations involving this event.
1.51 + # Remove additional recurrences if handling a complete event.
1.52 + # Also remove any previous cancellations involving this event.
1.53
1.54 - if not self.recurrenceid:
1.55 - self.store.remove_recurrences(self.user, self.uid)
1.56 - self.store.remove_cancellations(self.user, self.uid)
1.57 - else:
1.58 - self.store.remove_cancellation(self.user, self.uid, self.recurrenceid)
1.59 + if not self.recurrenceid:
1.60 + self.store.remove_recurrences(self.user, self.uid)
1.61 + self.store.remove_cancellations(self.user, self.uid)
1.62 + else:
1.63 + self.store.remove_cancellation(self.user, self.uid, self.recurrenceid)
1.64
1.65 - # Confirm any scheduling.
1.66 + if scheduled == "ACCEPTED":
1.67 + self.confirm_scheduling()
1.68
1.69 - if scheduled == "ACCEPTED":
1.70 - self.confirm_scheduling()
1.71 + # For countered proposals, record the offer in the resource's
1.72 + # free/busy collection.
1.73
1.74 - # For countered proposals, record the offer in the resource's
1.75 - # free/busy collection.
1.76 + elif scheduled == "COUNTER":
1.77 + method = "COUNTER"
1.78 + self.update_event_in_freebusy_offers()
1.79 +
1.80 + # For inappropriate periods, reply declining participation.
1.81
1.82 - elif scheduled == "COUNTER":
1.83 - method = "COUNTER"
1.84 - self.update_event_in_freebusy_offers()
1.85 + else:
1.86 + method = "REPLY"
1.87 + attendee_attr = self.update_participation("DECLINED")
1.88
1.89 - # For inappropriate periods, reply declining participation.
1.90 + # Confirm any scheduling.
1.91
1.92 - else:
1.93 - method = "REPLY"
1.94 - attendee_attr = self.update_participation("DECLINED")
1.95 + finally:
1.96 + self.finish_scheduling()
1.97
1.98 # Make a version of the object with just this attendee, update the
1.99 # DTSTAMP in the response, and return the object for sending.
1.100 @@ -192,6 +201,15 @@
1.101 if functions:
1.102 confirm_scheduling(functions.split("\n"), self)
1.103
1.104 + def finish_scheduling(self):
1.105 +
1.106 + "Finish the scheduling, unlocking resources where appropriate."
1.107 +
1.108 + functions = self.get_preferences().get("scheduling_function",
1.109 + "schedule_in_freebusy").split("\n")
1.110 +
1.111 + finish_scheduling(functions, self)
1.112 +
1.113 def retract_scheduling(self):
1.114
1.115 "Retract this event from scheduling records."