1.1 --- a/imiptools/content.py Sun Oct 26 23:10:12 2014 +0100
1.2 +++ b/imiptools/content.py Sun Oct 26 23:39:11 2014 +0100
1.3 @@ -7,6 +7,7 @@
1.4
1.5 from datetime import date, datetime, timedelta
1.6 from email.mime.text import MIMEText
1.7 +from imiptools.period import have_conflict, insert_period, remove_period
1.8 from pytz import timezone, UnknownTimeZoneError
1.9 from vCalendar import parse, ParseError, to_dict
1.10 from vRecurrence import get_parameters, get_rule
1.11 @@ -155,6 +156,11 @@
1.12
1.13 def get_periods(obj, window_size=100):
1.14
1.15 + """
1.16 + Return periods for the given object 'obj', confining materialised periods
1.17 + to the given 'window_size' in days starting from the present moment.
1.18 + """
1.19 +
1.20 dtstart = get_utc_datetime(obj, "DTSTART")
1.21 dtend = get_utc_datetime(obj, "DTEND")
1.22
1.23 @@ -186,6 +192,35 @@
1.24
1.25 return periods
1.26
1.27 +def update_freebusy(attendee, periods, transp, uid, store):
1.28 +
1.29 + """
1.30 + For the given 'attendee', update the free/busy details with the given
1.31 + 'periods', 'transp' setting and 'uid' in the 'store'. Where no conflict
1.32 + occurs, return the updated free/busy details; otherwise return None.
1.33 + """
1.34 +
1.35 + conflict = False
1.36 + freebusy = store.get_freebusy(attendee) or []
1.37 +
1.38 + if freebusy:
1.39 + remove_period(freebusy, uid)
1.40 + conflict = have_conflict(freebusy, periods)
1.41 +
1.42 + # If the event can be scheduled, it is registered in the free/busy list.
1.43 +
1.44 + if not conflict:
1.45 +
1.46 + for start, end in periods:
1.47 + insert_period(freebusy, (start, end, uid))
1.48 +
1.49 + if transp in (None, "OPAQUE"):
1.50 + store.set_freebusy(attendee, freebusy)
1.51 +
1.52 + return freebusy
1.53 +
1.54 + return None
1.55 +
1.56 # Handler mechanism objects.
1.57
1.58 def handle_itip_part(part, recipients, handlers):
1.59 @@ -325,6 +360,9 @@
1.60 def get_periods(self):
1.61 return get_periods(self.details)
1.62
1.63 + def update_freebusy(self, attendee, periods):
1.64 + return update_freebusy(attendee, periods, self.get_value("TRANSP"), self.uid, self.store)
1.65 +
1.66 def filter_by_recipients(self, values):
1.67 return self.recipients.intersection(map(get_address, values))
1.68