1.1 --- a/imiptools/client.py Tue May 23 16:34:09 2017 +0200
1.2 +++ b/imiptools/client.py Tue May 23 22:15:05 2017 +0200
1.3 @@ -1036,13 +1036,16 @@
1.4
1.5 return self.obj.get_recurrence_start_point(recurrenceid, self.get_tzid())
1.6
1.7 - def remove_from_freebusy(self, freebusy):
1.8 -
1.9 - "Remove this event from the given 'freebusy' collection."
1.10 + def remove_from_freebusy(self, freebusy, participant=None):
1.11
1.12 - removed = freebusy.remove_event_periods(self.uid, self.recurrenceid)
1.13 + """
1.14 + Remove this event from the given 'freebusy' collection. If 'participant'
1.15 + is specified, only remove this event if the participant is attending.
1.16 + """
1.17 +
1.18 + removed = freebusy.remove_event_periods(self.uid, self.recurrenceid, participant)
1.19 if not removed and self.recurrenceid:
1.20 - return freebusy.remove_affected_period(self.uid, self.get_recurrence_start_point(self.recurrenceid))
1.21 + return freebusy.remove_affected_period(self.uid, self.get_recurrence_start_point(self.recurrenceid), participant)
1.22 else:
1.23 return removed
1.24
2.1 --- a/imiptools/freebusy.py Tue May 23 16:34:09 2017 +0200
2.2 +++ b/imiptools/freebusy.py Tue May 23 22:15:05 2017 +0200
2.3 @@ -21,6 +21,7 @@
2.4
2.5 from bisect import bisect_left, bisect_right
2.6 from imiptools.dates import format_datetime
2.7 +from imiptools.period import get_overlapping, Period, PeriodBase
2.8 from imiptools.sql import DatabaseOperations
2.9
2.10 def from_string(s, encoding):
2.11 @@ -35,8 +36,6 @@
2.12 else:
2.13 return s
2.14
2.15 -from imiptools.period import get_overlapping, Period, PeriodBase
2.16 -
2.17 class FreeBusyPeriod(PeriodBase):
2.18
2.19 "A free/busy record abstraction."
2.20 @@ -548,13 +547,16 @@
2.21 if i < len(self.periods) and self.periods[i] == period:
2.22 del self.periods[i]
2.23
2.24 - def remove_event_periods(self, uid, recurrenceid=None):
2.25 + def remove_event_periods(self, uid, recurrenceid=None, participant=None):
2.26
2.27 """
2.28 Remove from the collection all periods associated with 'uid' and
2.29 'recurrenceid' (which if omitted causes the "parent" object's periods to
2.30 be referenced).
2.31
2.32 + If 'participant' is specified, only remove periods for which the
2.33 + participant is given as attending.
2.34 +
2.35 Return the removed periods.
2.36 """
2.37
2.38 @@ -564,7 +566,10 @@
2.39 i = 0
2.40 while i < len(self.periods):
2.41 fb = self.periods[i]
2.42 - if fb.uid == uid and fb.recurrenceid == recurrenceid:
2.43 +
2.44 + if fb.uid == uid and fb.recurrenceid == recurrenceid and \
2.45 + (not participant or participant == fb.attendee):
2.46 +
2.47 removed.append(self.periods[i])
2.48 del self.periods[i]
2.49 else:
2.50 @@ -605,7 +610,7 @@
2.51
2.52 return removed
2.53
2.54 - def remove_affected_period(self, uid, start):
2.55 + def remove_affected_period(self, uid, start, participant=None):
2.56
2.57 """
2.58 Remove from the collection the period associated with 'uid' that
2.59 @@ -614,6 +619,9 @@
2.60 is used to provide an alternative time period whilst also acting as a
2.61 reference to the originally-defined occurrence.
2.62
2.63 + If 'participant' is specified, only remove periods for which the
2.64 + participant is given as attending.
2.65 +
2.66 Return any removed period in a list.
2.67 """
2.68
2.69 @@ -634,7 +642,9 @@
2.70
2.71 # If the period belongs to the parent object, remove it and return.
2.72
2.73 - if not fb.recurrenceid and uid == fb.uid:
2.74 + if not fb.recurrenceid and uid == fb.uid and \
2.75 + (not participant or participant == fb.attendee):
2.76 +
2.77 removed.append(self.periods[found])
2.78 del self.periods[found]
2.79 break
2.80 @@ -797,22 +807,32 @@
2.81
2.82 self.cursor.execute(query, values)
2.83
2.84 - def remove_event_periods(self, uid, recurrenceid=None):
2.85 + def remove_event_periods(self, uid, recurrenceid=None, participant=None):
2.86
2.87 """
2.88 Remove from the collection all periods associated with 'uid' and
2.89 'recurrenceid' (which if omitted causes the "parent" object's periods to
2.90 be referenced).
2.91
2.92 + If 'participant' is specified, only remove periods for which the
2.93 + participant is given as attending.
2.94 +
2.95 Return the removed periods.
2.96 """
2.97
2.98 self._check_mutable()
2.99
2.100 + columns, values = ["object_uid"], [uid]
2.101 +
2.102 if recurrenceid:
2.103 - columns, values = ["object_uid", "object_recurrenceid"], [uid, recurrenceid]
2.104 + columns.append("object_recurrenceid")
2.105 + values.append(recurrenceid)
2.106 else:
2.107 - columns, values = ["object_uid", "object_recurrenceid is null"], [uid]
2.108 + columns.append("object_recurrenceid is null")
2.109 +
2.110 + if participant:
2.111 + columns.append("attendee")
2.112 + values.append(participant)
2.113
2.114 query, _values = self.get_query(
2.115 "select %(columns)s from %(table)s :condition" % {
2.116 @@ -877,7 +897,7 @@
2.117
2.118 return map(lambda t: self.make_period(t), removed)
2.119
2.120 - def remove_affected_period(self, uid, start):
2.121 + def remove_affected_period(self, uid, start, participant=None):
2.122
2.123 """
2.124 Remove from the collection the period associated with 'uid' that
2.125 @@ -886,6 +906,9 @@
2.126 is used to provide an alternative time period whilst also acting as a
2.127 reference to the originally-defined occurrence.
2.128
2.129 + If 'participant' is specified, only remove periods for which the
2.130 + participant is given as attending.
2.131 +
2.132 Return any removed period in a list.
2.133 """
2.134
2.135 @@ -895,6 +918,10 @@
2.136
2.137 columns, values = ["object_uid", "start", "object_recurrenceid is null"], [uid, start]
2.138
2.139 + if participant:
2.140 + columns.append("attendee")
2.141 + values.append(participant)
2.142 +
2.143 query, _values = self.get_query(
2.144 "select %(columns)s from %(table)s :condition" % {
2.145 "columns" : self.columnlist(self.period_columns),