1.1 --- a/imiptools/freebusy.py Tue May 23 16:34:09 2017 +0200
1.2 +++ b/imiptools/freebusy.py Tue May 23 22:15:05 2017 +0200
1.3 @@ -21,6 +21,7 @@
1.4
1.5 from bisect import bisect_left, bisect_right
1.6 from imiptools.dates import format_datetime
1.7 +from imiptools.period import get_overlapping, Period, PeriodBase
1.8 from imiptools.sql import DatabaseOperations
1.9
1.10 def from_string(s, encoding):
1.11 @@ -35,8 +36,6 @@
1.12 else:
1.13 return s
1.14
1.15 -from imiptools.period import get_overlapping, Period, PeriodBase
1.16 -
1.17 class FreeBusyPeriod(PeriodBase):
1.18
1.19 "A free/busy record abstraction."
1.20 @@ -548,13 +547,16 @@
1.21 if i < len(self.periods) and self.periods[i] == period:
1.22 del self.periods[i]
1.23
1.24 - def remove_event_periods(self, uid, recurrenceid=None):
1.25 + def remove_event_periods(self, uid, recurrenceid=None, participant=None):
1.26
1.27 """
1.28 Remove from the collection all periods associated with 'uid' and
1.29 'recurrenceid' (which if omitted causes the "parent" object's periods to
1.30 be referenced).
1.31
1.32 + If 'participant' is specified, only remove periods for which the
1.33 + participant is given as attending.
1.34 +
1.35 Return the removed periods.
1.36 """
1.37
1.38 @@ -564,7 +566,10 @@
1.39 i = 0
1.40 while i < len(self.periods):
1.41 fb = self.periods[i]
1.42 - if fb.uid == uid and fb.recurrenceid == recurrenceid:
1.43 +
1.44 + if fb.uid == uid and fb.recurrenceid == recurrenceid and \
1.45 + (not participant or participant == fb.attendee):
1.46 +
1.47 removed.append(self.periods[i])
1.48 del self.periods[i]
1.49 else:
1.50 @@ -605,7 +610,7 @@
1.51
1.52 return removed
1.53
1.54 - def remove_affected_period(self, uid, start):
1.55 + def remove_affected_period(self, uid, start, participant=None):
1.56
1.57 """
1.58 Remove from the collection the period associated with 'uid' that
1.59 @@ -614,6 +619,9 @@
1.60 is used to provide an alternative time period whilst also acting as a
1.61 reference to the originally-defined occurrence.
1.62
1.63 + If 'participant' is specified, only remove periods for which the
1.64 + participant is given as attending.
1.65 +
1.66 Return any removed period in a list.
1.67 """
1.68
1.69 @@ -634,7 +642,9 @@
1.70
1.71 # If the period belongs to the parent object, remove it and return.
1.72
1.73 - if not fb.recurrenceid and uid == fb.uid:
1.74 + if not fb.recurrenceid and uid == fb.uid and \
1.75 + (not participant or participant == fb.attendee):
1.76 +
1.77 removed.append(self.periods[found])
1.78 del self.periods[found]
1.79 break
1.80 @@ -797,22 +807,32 @@
1.81
1.82 self.cursor.execute(query, values)
1.83
1.84 - def remove_event_periods(self, uid, recurrenceid=None):
1.85 + def remove_event_periods(self, uid, recurrenceid=None, participant=None):
1.86
1.87 """
1.88 Remove from the collection all periods associated with 'uid' and
1.89 'recurrenceid' (which if omitted causes the "parent" object's periods to
1.90 be referenced).
1.91
1.92 + If 'participant' is specified, only remove periods for which the
1.93 + participant is given as attending.
1.94 +
1.95 Return the removed periods.
1.96 """
1.97
1.98 self._check_mutable()
1.99
1.100 + columns, values = ["object_uid"], [uid]
1.101 +
1.102 if recurrenceid:
1.103 - columns, values = ["object_uid", "object_recurrenceid"], [uid, recurrenceid]
1.104 + columns.append("object_recurrenceid")
1.105 + values.append(recurrenceid)
1.106 else:
1.107 - columns, values = ["object_uid", "object_recurrenceid is null"], [uid]
1.108 + columns.append("object_recurrenceid is null")
1.109 +
1.110 + if participant:
1.111 + columns.append("attendee")
1.112 + values.append(participant)
1.113
1.114 query, _values = self.get_query(
1.115 "select %(columns)s from %(table)s :condition" % {
1.116 @@ -877,7 +897,7 @@
1.117
1.118 return map(lambda t: self.make_period(t), removed)
1.119
1.120 - def remove_affected_period(self, uid, start):
1.121 + def remove_affected_period(self, uid, start, participant=None):
1.122
1.123 """
1.124 Remove from the collection the period associated with 'uid' that
1.125 @@ -886,6 +906,9 @@
1.126 is used to provide an alternative time period whilst also acting as a
1.127 reference to the originally-defined occurrence.
1.128
1.129 + If 'participant' is specified, only remove periods for which the
1.130 + participant is given as attending.
1.131 +
1.132 Return any removed period in a list.
1.133 """
1.134
1.135 @@ -895,6 +918,10 @@
1.136
1.137 columns, values = ["object_uid", "start", "object_recurrenceid is null"], [uid, start]
1.138
1.139 + if participant:
1.140 + columns.append("attendee")
1.141 + values.append(participant)
1.142 +
1.143 query, _values = self.get_query(
1.144 "select %(columns)s from %(table)s :condition" % {
1.145 "columns" : self.columnlist(self.period_columns),