# HG changeset patch # User Paul Boddie # Date 1423509062 -3600 # Node ID ee744ec3aaab0476c2a1dd8a57357dc33ac0293f # Parent 140714dec0eed81847754aca9531666a408ff76e Consolidated free/busy updates for other participants. diff -r 140714dec0ee -r ee744ec3aaab imiptools/content.py --- a/imiptools/content.py Mon Feb 09 16:34:24 2015 +0100 +++ b/imiptools/content.py Mon Feb 09 20:11:02 2015 +0100 @@ -175,6 +175,27 @@ def update_freebusy(self, freebusy, attendee, periods): return update_freebusy(freebusy, attendee, periods, self.obj.get_value("TRANSP"), self.uid, self.store) + def update_freebusy_from_participant(self, user, participant_item, tzid): + + """ + For the given 'user', record the free/busy information for the + 'participant_item' (a value plus attributes), using the 'tzid' to define + period information. + """ + + participant, participant_attr = participant_item + + if participant != user: + freebusy = self.store.get_freebusy_for_other(user, participant) + + if participant_attr.get("PARTSTAT") != "DECLINED": + update_freebusy_for_other(freebusy, user, participant, + self.obj.get_periods_for_freebusy(tzid), + self.obj.get_value("TRANSP"), + self.uid, self.store) + else: + self.remove_from_freebusy_for_other(freebusy, user, participant) + def update_freebusy_from_organiser(self, attendee, organiser_item, tzid=None): """ @@ -182,34 +203,14 @@ 'organiser_item' (a value plus attributes). """ - organiser, organiser_attr = organiser_item - - if organiser != attendee: - freebusy = self.store.get_freebusy_for_other(attendee, organiser) - - if organiser_attr.get("PARTSTAT") != "DECLINED": - update_freebusy_for_other(freebusy, attendee, organiser, - self.obj.get_periods_for_freebusy(tzid), - self.obj.get_value("TRANSP"), - self.uid, self.store) - else: - self.remove_from_freebusy_for_other(freebusy, attendee, organiser) + self.update_freebusy_from_participant(attendee, organiser_item, tzid) def update_freebusy_from_attendees(self, organiser, attendees, tzid=None): "For the 'organiser', record free/busy information from 'attendees'." - for attendee, attendee_attr in attendees.items(): - if organiser != attendee: - freebusy = self.store.get_freebusy_for_other(organiser, attendee) - - if attendee_attr.get("PARTSTAT") != "DECLINED": - update_freebusy_for_other(freebusy, organiser, attendee, - self.obj.get_periods_for_freebusy(tzid), - self.obj.get_value("TRANSP"), - self.uid, self.store) - else: - self.remove_from_freebusy_for_other(freebusy, organiser, attendee) + for attendee_item in attendees.items(): + self.update_freebusy_from_participant(organiser, attendee_item, tzid) def can_schedule(self, freebusy, periods): return can_schedule(freebusy, periods, self.uid)