1.1 --- a/imiptools/data.py Fri Mar 23 15:46:51 2018 +0100
1.2 +++ b/imiptools/data.py Thu Mar 29 17:30:13 2018 +0200
1.3 @@ -770,14 +770,14 @@
1.4 nodes
1.5 )
1.6
1.7 -def make_freebusy(freebusy, uid, organiser, organiser_attr=None, attendee=None,
1.8 - attendee_attr=None, period=None):
1.9 +def make_freebusy(freebusy, uid, organiser, organiser_attr=None, attendees=None,
1.10 + period=None):
1.11
1.12 """
1.13 Return a calendar node defining the free/busy details described in the given
1.14 'freebusy' list, employing the given 'uid', for the given 'organiser' and
1.15 - optional 'organiser_attr', with the optional 'attendee' providing recipient
1.16 - details together with the optional 'attendee_attr'.
1.17 + optional 'organiser_attr', with the optional 'attendees' providing a
1.18 + collection of (address, attribute) items.
1.19
1.20 The result will be constrained to the 'period' if specified.
1.21 """
1.22 @@ -787,12 +787,17 @@
1.23
1.24 rwrite(("ORGANIZER", organiser_attr or {}, organiser))
1.25
1.26 - if attendee:
1.27 - rwrite(("ATTENDEE", attendee_attr or {}, attendee))
1.28 + # A request can have many attendees; a response will have just one.
1.29 +
1.30 + if attendees:
1.31 + for attendee, attendee_attr in attendees:
1.32 + rwrite(("ATTENDEE", attendee_attr or {}, attendee))
1.33
1.34 rwrite(("UID", {}, uid))
1.35
1.36 - if freebusy:
1.37 + # Obtain free/busy periods if publishing or replying.
1.38 +
1.39 + if freebusy is not None:
1.40
1.41 # Get a constrained view if start and end limits are specified.
1.42
1.43 @@ -801,20 +806,23 @@
1.44 else:
1.45 periods = freebusy
1.46
1.47 - # Write the limits of the resource.
1.48 + else:
1.49 + periods = []
1.50 +
1.51 + # Write the limits of the resource.
1.52
1.53 - if periods:
1.54 - rwrite(("DTSTART", {"VALUE" : "DATE-TIME"}, format_datetime(periods[0].get_start_point())))
1.55 - rwrite(("DTEND", {"VALUE" : "DATE-TIME"}, format_datetime(periods[-1].get_end_point())))
1.56 - else:
1.57 - rwrite(("DTSTART", {"VALUE" : "DATE-TIME"}, format_datetime(period.get_start_point())))
1.58 - rwrite(("DTEND", {"VALUE" : "DATE-TIME"}, format_datetime(period.get_end_point())))
1.59 + if periods:
1.60 + rwrite(("DTSTART", {"VALUE" : "DATE-TIME"}, format_datetime(periods[0].get_start_point())))
1.61 + rwrite(("DTEND", {"VALUE" : "DATE-TIME"}, format_datetime(periods[-1].get_end_point())))
1.62 + elif period:
1.63 + rwrite(("DTSTART", {"VALUE" : "DATE-TIME"}, format_datetime(period.get_start_point())))
1.64 + rwrite(("DTEND", {"VALUE" : "DATE-TIME"}, format_datetime(period.get_end_point())))
1.65
1.66 - for p in periods:
1.67 - if p.transp == "OPAQUE":
1.68 - rwrite(("FREEBUSY", {"FBTYPE" : "BUSY"}, "/".join(
1.69 - map(format_datetime, [p.get_start_point(), p.get_end_point()])
1.70 - )))
1.71 + for p in periods:
1.72 + if p.transp == "OPAQUE":
1.73 + rwrite(("FREEBUSY", {"FBTYPE" : "BUSY"}, "/".join(
1.74 + map(format_datetime, [p.get_start_point(), p.get_end_point()])
1.75 + )))
1.76
1.77 return ("VFREEBUSY", {}, record)
1.78