1.1 --- a/imiptools/data.py Thu Aug 06 20:02:14 2015 +0200
1.2 +++ b/imiptools/data.py Thu Aug 06 22:00:11 2015 +0200
1.3 @@ -28,7 +28,7 @@
1.4 get_duration, get_period, get_period_item, \
1.5 get_recurrence_start_point, \
1.6 get_tzid, to_datetime, to_timezone, to_utc_datetime
1.7 -from imiptools.period import Period, RecurringPeriod, period_overlaps
1.8 +from imiptools.period import FreeBusyPeriod, Period, RecurringPeriod, period_overlaps
1.9 from vCalendar import iterwrite, parse, ParseError, to_dict, to_node
1.10 from vRecurrence import get_parameters, get_rule
1.11 import email.utils
1.12 @@ -213,11 +213,62 @@
1.13 # Subtract any recurrences from the free/busy details of a
1.14 # parent object.
1.15
1.16 - if not is_replaced(p, recurrenceids, tzid):
1.17 + if not p.is_replaced(recurrenceids):
1.18 active.append(p)
1.19
1.20 return active
1.21
1.22 + def get_freebusy_period(self, period, only_organiser=False):
1.23 +
1.24 + """
1.25 + Return a free/busy period for the given 'period' provided by this
1.26 + object, using the 'only_organiser' status to produce a suitable
1.27 + transparency value.
1.28 + """
1.29 +
1.30 + return FreeBusyPeriod(
1.31 + period.get_start_point(),
1.32 + period.get_end_point(),
1.33 + self.get_value("UID"),
1.34 + only_organiser and "ORG" or self.get_value("TRANSP") or "OPAQUE",
1.35 + self.get_recurrenceid(),
1.36 + self.get_value("SUMMARY"),
1.37 + self.get_value("ORGANIZER")
1.38 + )
1.39 +
1.40 + def get_participation_status(self, participant):
1.41 +
1.42 + """
1.43 + Return the participation status of the given 'participant', with the
1.44 + special value "ORG" indicating organiser-only participation.
1.45 + """
1.46 +
1.47 + attendees = self.get_value_map("ATTENDEE")
1.48 + organiser = self.get_value("ORGANIZER")
1.49 +
1.50 + for attendee, attendee_attr in attendees.items():
1.51 + if attendee == participant:
1.52 + return attendee_attr.get("PARTSTAT", "NEEDS-ACTION")
1.53 +
1.54 + else:
1.55 + if organiser == participant:
1.56 + return "ORG"
1.57 +
1.58 + return None
1.59 +
1.60 + def get_participation(self, partstat, include_needs_action=False):
1.61 +
1.62 + """
1.63 + Return whether 'partstat' indicates some kind of participation in an
1.64 + event. If 'include_needs_action' is specified as a true value, events
1.65 + not yet responded to will be treated as events with tentative
1.66 + participation.
1.67 + """
1.68 +
1.69 + return not partstat in ("DECLINED", "DELEGATED", "NEEDS-ACTION") or \
1.70 + include_needs_action and partstat == "NEEDS-ACTION" or \
1.71 + partstat == "ORG"
1.72 +
1.73 def get_tzid(self):
1.74
1.75 """