1.1 --- a/imiptools/handlers/resource.py Sun Oct 26 23:10:12 2014 +0100
1.2 +++ b/imiptools/handlers/resource.py Sun Oct 26 23:39:11 2014 +0100
1.3 @@ -5,7 +5,6 @@
1.4 """
1.5
1.6 from imiptools.content import Handler, format_datetime, to_part
1.7 -from imiptools.period import have_conflict, insert_period, remove_period
1.8 from vCalendar import to_node
1.9
1.10 class Event(Handler):
1.11 @@ -75,44 +74,23 @@
1.12 # free/busy record and check for suitability.
1.13
1.14 periods = self.get_periods()
1.15 -
1.16 - conflict = False
1.17 - freebusy = self.store.get_freebusy(attendee) or []
1.18 + freebusy = self.update_freebusy(attendee, periods)
1.19 + scheduled = freebusy is not None
1.20
1.21 - if freebusy:
1.22 - remove_period(freebusy, self.uid)
1.23 - conflict = have_conflict(freebusy, periods)
1.24 + attendee_attr["PARTSTAT"] = scheduled and "ACCEPTED" or "DECLINED"
1.25
1.26 - # If the event can be scheduled, it is registered and a reply sent
1.27 - # accepting the event. (The attendee has PARTSTAT=ACCEPTED as an
1.28 - # attribute.)
1.29 + self.details["ATTENDEE"] = [(attendee, attendee_attr)]
1.30
1.31 - if not conflict:
1.32 - for start, end in periods:
1.33 - insert_period(freebusy, (start, end, self.uid))
1.34 + calendar.append(to_node(
1.35 + {"VEVENT" : [(self.details, {})]}
1.36 + ))
1.37
1.38 - if self.get_value("TRANSP") in (None, "OPAQUE"):
1.39 - self.store.set_freebusy(attendee, freebusy)
1.40 -
1.41 - if self.publisher:
1.42 - self.publisher.set_freebusy(attendee, freebusy)
1.43 -
1.44 + if scheduled:
1.45 self.store.set_event(attendee, self.uid, to_node(
1.46 {"VEVENT" : [(self.details, {})]}
1.47 ))
1.48 - attendee_attr["PARTSTAT"] = "ACCEPTED"
1.49 -
1.50 - # If the event cannot be scheduled, it is not registered and a reply
1.51 - # sent declining the event. (The attendee has PARTSTAT=DECLINED as an
1.52 - # attribute.)
1.53 -
1.54 - else:
1.55 - attendee_attr["PARTSTAT"] = "DECLINED"
1.56 -
1.57 - self.details["ATTENDEE"] = [(attendee, attendee_attr)]
1.58 - calendar.append(to_node(
1.59 - {"VEVENT" : [(self.details, {})]}
1.60 - ))
1.61 + if self.publisher:
1.62 + self.publisher.set_freebusy(attendee, freebusy)
1.63
1.64 return "REPLY", to_part("REPLY", calendar)
1.65