# HG changeset patch # User Paul Boddie # Date 1422401564 -3600 # Node ID c4630b004a309ee876e120c7f41032174503ca18 # Parent 27338cdf885fdc316e3bcd8304faa58d0f775711 Introduced a more general mechanism for producing free/busy objects. diff -r 27338cdf885f -r c4630b004a30 imiptools/handlers/common.py --- a/imiptools/handlers/common.py Tue Jan 27 19:03:20 2015 +0100 +++ b/imiptools/handlers/common.py Wed Jan 28 00:32:44 2015 +0100 @@ -32,27 +32,71 @@ information for each indicated attendee. """ + calendar = self.make_freebusy(from_organiser=False) + + # Return the reply. + + return "REPLY", to_part("REPLY", calendar) + + def make_freebusy_to_publish(self, from_organiser=True): + + """ + Make a freebusy object for publication for a user, providing either an + organiser's details if 'from_organiser' is set to a true value, or an + attendee's details otherwise. + """ + + calendar = self.make_freebusy(from_organiser, publish=True) + + # Return a published object. + + return "PUBLISH", to_part("PUBLISH", calendar) + + def make_freebusy(self, from_organiser=True, publish=False): + + """ + Make a freebusy object, providing either an organiser's details if + 'from_organiser' is set to a true value, or an attendee's details + otherwise. + """ + oa = self.require_organiser_and_attendees() if not oa: return None - (organiser, organiser_attr), attendees = organiser_item, attendees = oa + (organiser, organiser_attr), attendees = oa - # Construct an appropriate fragment. + # Get the details for each attendee. calendar = [] cwrite = calendar.append - # Get the details for each attendee. + for attendee, attendee_attr in attendees.items(): - for attendee, attendee_attr in attendees.items(): - freebusy = self.store.get_freebusy(attendee) + # Construct an appropriate fragment. + + freebusy = self.store.get_freebusy(from_organiser and organiser or attendee) record = [] rwrite = record.append - rwrite(("ORGANIZER", organiser_attr, organiser)) - rwrite(("ATTENDEE", attendee_attr, attendee)) + # For replies, the organiser is preserved. + + if not publish or from_organiser: + rwrite(("ORGANIZER", organiser_attr, organiser)) + + # For published objects, the organiser is actually the user whose + # information is being provided. + + else: + rwrite(("ORGANIZER", attendee_attr, attendee)) + + # For replies, the attendee is preserved. + # (Published objects do not employ the attendee property.) + + if not publish: + rwrite(("ATTENDEE", attendee_attr, attendee)) + rwrite(("UID", {}, self.uid)) if freebusy: @@ -62,8 +106,8 @@ cwrite(("VFREEBUSY", {}, record)) - # Return the reply. + # Return the object. - return "REPLY", to_part("REPLY", calendar) + return calendar # vim: tabstop=4 expandtab shiftwidth=4