# HG changeset patch # User Paul Boddie # Date 1463172077 -7200 # Node ID 9870d5d67a50bf5d41ce409898c3ede8bbac3172 # Parent e8de5c7483076d00668775fccc08b4436cd9c4bf Fixed free/busy updates for quota group free/busy collections, adding a special comparison method to group-related free/busy periods. diff -r e8de5c748307 -r 9870d5d67a50 imiptools/period.py --- a/imiptools/period.py Fri May 13 16:20:29 2016 +0200 +++ b/imiptools/period.py Fri May 13 22:41:17 2016 +0200 @@ -519,6 +519,19 @@ return FreeBusyPeriod.as_tuple(self, strings_only, string_datetimes) + ( self.attendee or null(self.attendee),) + def __cmp__(self, other): + + """ + Compare this object to 'other', employing the uid if the periods + involved are the same. + """ + + result = FreeBusyPeriod.__cmp__(self, other) + if isinstance(other, FreeBusyGroupPeriod) and result == 0: + return cmp(self.attendee, other.attendee) + else: + return result + def __repr__(self): return "FreeBusyGroupPeriod%r" % (self.as_tuple(),) @@ -770,6 +783,20 @@ period_columns = FreeBusyCollectionBase.period_columns + ["attendee"] period_class = FreeBusyGroupPeriod + def _update_freebusy(self, periods, uid, recurrenceid, attendee=None): + + """ + Update the free/busy details with the given 'periods', using the given + 'uid' plus 'recurrenceid' and 'attendee' to remove existing periods. + """ + + self._check_mutable() + + self.remove_event_periods(uid, recurrenceid, attendee) + + for p in periods: + self.insert_period(p) + def update_freebusy(self, periods, transp, uid, recurrenceid, summary, organiser, attendee=None): """ @@ -786,7 +813,7 @@ self.period_class(p.get_start_point(), p.get_end_point(), uid, transp, recurrenceid, summary, organiser, attendee) ) - self._update_freebusy(new_periods, uid, recurrenceid) + self._update_freebusy(new_periods, uid, recurrenceid, attendee) class SupportExpires: @@ -1021,7 +1048,29 @@ "A collection of quota group free/busy objects." - pass + def remove_event_periods(self, uid, recurrenceid=None, attendee=None): + + """ + Remove from the collection all periods associated with 'uid' and + 'recurrenceid' (which if omitted causes the "parent" object's periods to + be referenced) and any 'attendee'. + + Return the removed periods. + """ + + self._check_mutable() + + removed = [] + i = 0 + while i < len(self.periods): + fb = self.periods[i] + if fb.uid == uid and fb.recurrenceid == recurrenceid and fb.attendee == attendee: + removed.append(self.periods[i]) + del self.periods[i] + else: + i += 1 + + return removed class FreeBusyOffersCollection(SupportExpires, FreeBusyCollection): @@ -1328,7 +1377,51 @@ "A collection of quota group free/busy objects." - pass + def remove_event_periods(self, uid, recurrenceid=None, attendee=None): + + """ + Remove from the collection all periods associated with 'uid' and + 'recurrenceid' (which if omitted causes the "parent" object's periods to + be referenced) and any 'attendee'. + + Return the removed periods. + """ + + self._check_mutable() + + columns, values = ["object_uid"], [uid] + + if recurrenceid: + columns.append("object_recurrenceid") + values.append(recurrenceid) + else: + columns.append("object_recurrenceid is null") + + if attendee: + columns.append("attendee") + values.append(attendee) + else: + columns.append("attendee is null") + + query, _values = self.get_query( + "select %(columns)s from %(table)s :condition" % { + "columns" : self.columnlist(self.period_columns), + "table" : self.table_name + }, + columns, values) + + self.cursor.execute(query, _values) + removed = self.cursor.fetchall() + + query, values = self.get_query( + "delete from %(table)s :condition" % { + "table" : self.table_name + }, + columns, values) + + self.cursor.execute(query, values) + + return map(lambda t: self.make_period(t), removed) class FreeBusyOffersDatabaseCollection(SupportExpires, FreeBusyDatabaseCollection):