1.1 --- a/imiptools/period.py Fri May 13 16:20:29 2016 +0200
1.2 +++ b/imiptools/period.py Fri May 13 22:41:17 2016 +0200
1.3 @@ -519,6 +519,19 @@
1.4 return FreeBusyPeriod.as_tuple(self, strings_only, string_datetimes) + (
1.5 self.attendee or null(self.attendee),)
1.6
1.7 + def __cmp__(self, other):
1.8 +
1.9 + """
1.10 + Compare this object to 'other', employing the uid if the periods
1.11 + involved are the same.
1.12 + """
1.13 +
1.14 + result = FreeBusyPeriod.__cmp__(self, other)
1.15 + if isinstance(other, FreeBusyGroupPeriod) and result == 0:
1.16 + return cmp(self.attendee, other.attendee)
1.17 + else:
1.18 + return result
1.19 +
1.20 def __repr__(self):
1.21 return "FreeBusyGroupPeriod%r" % (self.as_tuple(),)
1.22
1.23 @@ -770,6 +783,20 @@
1.24 period_columns = FreeBusyCollectionBase.period_columns + ["attendee"]
1.25 period_class = FreeBusyGroupPeriod
1.26
1.27 + def _update_freebusy(self, periods, uid, recurrenceid, attendee=None):
1.28 +
1.29 + """
1.30 + Update the free/busy details with the given 'periods', using the given
1.31 + 'uid' plus 'recurrenceid' and 'attendee' to remove existing periods.
1.32 + """
1.33 +
1.34 + self._check_mutable()
1.35 +
1.36 + self.remove_event_periods(uid, recurrenceid, attendee)
1.37 +
1.38 + for p in periods:
1.39 + self.insert_period(p)
1.40 +
1.41 def update_freebusy(self, periods, transp, uid, recurrenceid, summary, organiser, attendee=None):
1.42
1.43 """
1.44 @@ -786,7 +813,7 @@
1.45 self.period_class(p.get_start_point(), p.get_end_point(), uid, transp, recurrenceid, summary, organiser, attendee)
1.46 )
1.47
1.48 - self._update_freebusy(new_periods, uid, recurrenceid)
1.49 + self._update_freebusy(new_periods, uid, recurrenceid, attendee)
1.50
1.51 class SupportExpires:
1.52
1.53 @@ -1021,7 +1048,29 @@
1.54
1.55 "A collection of quota group free/busy objects."
1.56
1.57 - pass
1.58 + def remove_event_periods(self, uid, recurrenceid=None, attendee=None):
1.59 +
1.60 + """
1.61 + Remove from the collection all periods associated with 'uid' and
1.62 + 'recurrenceid' (which if omitted causes the "parent" object's periods to
1.63 + be referenced) and any 'attendee'.
1.64 +
1.65 + Return the removed periods.
1.66 + """
1.67 +
1.68 + self._check_mutable()
1.69 +
1.70 + removed = []
1.71 + i = 0
1.72 + while i < len(self.periods):
1.73 + fb = self.periods[i]
1.74 + if fb.uid == uid and fb.recurrenceid == recurrenceid and fb.attendee == attendee:
1.75 + removed.append(self.periods[i])
1.76 + del self.periods[i]
1.77 + else:
1.78 + i += 1
1.79 +
1.80 + return removed
1.81
1.82 class FreeBusyOffersCollection(SupportExpires, FreeBusyCollection):
1.83
1.84 @@ -1328,7 +1377,51 @@
1.85
1.86 "A collection of quota group free/busy objects."
1.87
1.88 - pass
1.89 + def remove_event_periods(self, uid, recurrenceid=None, attendee=None):
1.90 +
1.91 + """
1.92 + Remove from the collection all periods associated with 'uid' and
1.93 + 'recurrenceid' (which if omitted causes the "parent" object's periods to
1.94 + be referenced) and any 'attendee'.
1.95 +
1.96 + Return the removed periods.
1.97 + """
1.98 +
1.99 + self._check_mutable()
1.100 +
1.101 + columns, values = ["object_uid"], [uid]
1.102 +
1.103 + if recurrenceid:
1.104 + columns.append("object_recurrenceid")
1.105 + values.append(recurrenceid)
1.106 + else:
1.107 + columns.append("object_recurrenceid is null")
1.108 +
1.109 + if attendee:
1.110 + columns.append("attendee")
1.111 + values.append(attendee)
1.112 + else:
1.113 + columns.append("attendee is null")
1.114 +
1.115 + query, _values = self.get_query(
1.116 + "select %(columns)s from %(table)s :condition" % {
1.117 + "columns" : self.columnlist(self.period_columns),
1.118 + "table" : self.table_name
1.119 + },
1.120 + columns, values)
1.121 +
1.122 + self.cursor.execute(query, _values)
1.123 + removed = self.cursor.fetchall()
1.124 +
1.125 + query, values = self.get_query(
1.126 + "delete from %(table)s :condition" % {
1.127 + "table" : self.table_name
1.128 + },
1.129 + columns, values)
1.130 +
1.131 + self.cursor.execute(query, values)
1.132 +
1.133 + return map(lambda t: self.make_period(t), removed)
1.134
1.135 class FreeBusyOffersDatabaseCollection(SupportExpires, FreeBusyDatabaseCollection):
1.136