1.1 --- a/imiptools/handlers/common.py Sun Feb 01 21:05:55 2015 +0100
1.2 +++ b/imiptools/handlers/common.py Mon Feb 02 00:12:53 2015 +0100
1.3 @@ -19,38 +19,17 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -from imiptools.data import get_address, to_part
1.8 +from imiptools.data import get_address, make_freebusy, to_part
1.9
1.10 -class SupportFreebusy:
1.11 +class CommonFreebusy:
1.12
1.13 - "Support for free/busy publishing and sharing."
1.14 + "Common free/busy mix-in."
1.15
1.16 - def make_freebusy_to_publish(self, from_organiser=True):
1.17 + def request(self):
1.18
1.19 """
1.20 - Make a freebusy object for publication for a user, providing either an
1.21 - organiser's details if 'from_organiser' is set to a true value, or an
1.22 - attendee's details otherwise.
1.23 - """
1.24 -
1.25 - calendar = self.make_freebusy(from_organiser, publish=True)
1.26 -
1.27 - # Return a published object.
1.28 -
1.29 - if calendar:
1.30 - return [(
1.31 - map(get_address,
1.32 - from_organiser and self.obj.get_values("ATTENDEE") or
1.33 - self.obj.get_values("ORGANIZER")),
1.34 - to_part("PUBLISH", calendar)
1.35 - )]
1.36 -
1.37 - def make_freebusy(self, from_organiser=True, publish=False):
1.38 -
1.39 - """
1.40 - Make a freebusy object, providing either an organiser's details if
1.41 - 'from_organiser' is set to a true value, or an attendee's details
1.42 - otherwise.
1.43 + Respond to a request by preparing a reply containing free/busy
1.44 + information for each indicated attendee.
1.45 """
1.46
1.47 oa = self.require_organiser_and_attendees()
1.48 @@ -61,63 +40,17 @@
1.49
1.50 # Get the details for each attendee.
1.51
1.52 - calendar = []
1.53 - cwrite = calendar.append
1.54 + responses = []
1.55 + rwrite = responses.append
1.56 +
1.57 + # For replies, the organiser and attendee are preserved.
1.58
1.59 for attendee, attendee_attr in attendees.items():
1.60 -
1.61 - # Construct an appropriate fragment.
1.62 -
1.63 - freebusy = self.store.get_freebusy(from_organiser and organiser or attendee)
1.64 -
1.65 - record = []
1.66 - rwrite = record.append
1.67 -
1.68 - # For replies, the organiser is preserved.
1.69 -
1.70 - if not publish or from_organiser:
1.71 - rwrite(("ORGANIZER", organiser_attr, organiser))
1.72 -
1.73 - # For published objects, the organiser is actually the user whose
1.74 - # information is being provided.
1.75 -
1.76 - else:
1.77 - rwrite(("ORGANIZER", attendee_attr, attendee))
1.78 -
1.79 - # For replies, the attendee is preserved.
1.80 - # (Published objects do not employ the attendee property.)
1.81 -
1.82 - if not publish:
1.83 - rwrite(("ATTENDEE", attendee_attr, attendee))
1.84 -
1.85 - rwrite(("UID", {}, self.uid))
1.86 -
1.87 - if freebusy:
1.88 - for start, end, uid, transp in freebusy:
1.89 - if transp == "OPAQUE":
1.90 - rwrite(("FREEBUSY", {"FBTYPE" : "BUSY"}, "/".join([start, end])))
1.91 -
1.92 - cwrite(("VFREEBUSY", {}, record))
1.93 -
1.94 - # Return the object.
1.95 -
1.96 - return calendar
1.97 -
1.98 -class CommonFreebusy(SupportFreebusy):
1.99 -
1.100 - "Common free/busy mix-in."
1.101 -
1.102 - def request(self):
1.103 -
1.104 - """
1.105 - Respond to a request by preparing a reply containing free/busy
1.106 - information for each indicated attendee.
1.107 - """
1.108 -
1.109 - calendar = self.make_freebusy(from_organiser=False)
1.110 + freebusy = self.store.get_freebusy(attendee)
1.111 + rwrite(make_freebusy(freebusy, self.uid, organiser, attendee))
1.112
1.113 # Return the reply.
1.114
1.115 - return [(map(get_address, self.obj.get_values("ORGANIZER")), to_part("REPLY", calendar))]
1.116 + return [([get_address(organiser)], to_part("REPLY", responses))]
1.117
1.118 # vim: tabstop=4 expandtab shiftwidth=4