1.1 --- a/imiptools/handlers/common.py Tue Jan 27 19:03:20 2015 +0100
1.2 +++ b/imiptools/handlers/common.py Wed Jan 28 00:32:44 2015 +0100
1.3 @@ -32,27 +32,71 @@
1.4 information for each indicated attendee.
1.5 """
1.6
1.7 + calendar = self.make_freebusy(from_organiser=False)
1.8 +
1.9 + # Return the reply.
1.10 +
1.11 + return "REPLY", to_part("REPLY", calendar)
1.12 +
1.13 + def make_freebusy_to_publish(self, from_organiser=True):
1.14 +
1.15 + """
1.16 + Make a freebusy object for publication for a user, providing either an
1.17 + organiser's details if 'from_organiser' is set to a true value, or an
1.18 + attendee's details otherwise.
1.19 + """
1.20 +
1.21 + calendar = self.make_freebusy(from_organiser, publish=True)
1.22 +
1.23 + # Return a published object.
1.24 +
1.25 + return "PUBLISH", to_part("PUBLISH", calendar)
1.26 +
1.27 + def make_freebusy(self, from_organiser=True, publish=False):
1.28 +
1.29 + """
1.30 + Make a freebusy object, providing either an organiser's details if
1.31 + 'from_organiser' is set to a true value, or an attendee's details
1.32 + otherwise.
1.33 + """
1.34 +
1.35 oa = self.require_organiser_and_attendees()
1.36 if not oa:
1.37 return None
1.38
1.39 - (organiser, organiser_attr), attendees = organiser_item, attendees = oa
1.40 + (organiser, organiser_attr), attendees = oa
1.41
1.42 - # Construct an appropriate fragment.
1.43 + # Get the details for each attendee.
1.44
1.45 calendar = []
1.46 cwrite = calendar.append
1.47
1.48 - # Get the details for each attendee.
1.49 + for attendee, attendee_attr in attendees.items():
1.50
1.51 - for attendee, attendee_attr in attendees.items():
1.52 - freebusy = self.store.get_freebusy(attendee)
1.53 + # Construct an appropriate fragment.
1.54 +
1.55 + freebusy = self.store.get_freebusy(from_organiser and organiser or attendee)
1.56
1.57 record = []
1.58 rwrite = record.append
1.59
1.60 - rwrite(("ORGANIZER", organiser_attr, organiser))
1.61 - rwrite(("ATTENDEE", attendee_attr, attendee))
1.62 + # For replies, the organiser is preserved.
1.63 +
1.64 + if not publish or from_organiser:
1.65 + rwrite(("ORGANIZER", organiser_attr, organiser))
1.66 +
1.67 + # For published objects, the organiser is actually the user whose
1.68 + # information is being provided.
1.69 +
1.70 + else:
1.71 + rwrite(("ORGANIZER", attendee_attr, attendee))
1.72 +
1.73 + # For replies, the attendee is preserved.
1.74 + # (Published objects do not employ the attendee property.)
1.75 +
1.76 + if not publish:
1.77 + rwrite(("ATTENDEE", attendee_attr, attendee))
1.78 +
1.79 rwrite(("UID", {}, self.uid))
1.80
1.81 if freebusy:
1.82 @@ -62,8 +106,8 @@
1.83
1.84 cwrite(("VFREEBUSY", {}, record))
1.85
1.86 - # Return the reply.
1.87 + # Return the object.
1.88
1.89 - return "REPLY", to_part("REPLY", calendar)
1.90 + return calendar
1.91
1.92 # vim: tabstop=4 expandtab shiftwidth=4