# HG changeset patch # User Paul Boddie # Date 1509489934 -3600 # Node ID 8978b422905b3c3e7dd7f6d69373fde12a0ecce3 # Parent 418b856973df5d441044e878c018880908918ad1 Attempt to load existing recurrence instances when obtaining rescheduled period objects, employing a new method to return objects for encoding into parts for message generation. diff -r 418b856973df -r 8978b422905b imiptools/client.py --- a/imiptools/client.py Mon Oct 30 23:15:51 2017 +0100 +++ b/imiptools/client.py Tue Oct 31 23:45:34 2017 +0100 @@ -852,6 +852,49 @@ # Specific message generation methods. + def get_rescheduled_objects(self, periods): + + "Return objects describing rescheduled 'periods'." + + objects = [] + + if periods: + + # For new recurrences, duplicate the core of the object without any + # period information. + + template = self.obj.copy() + template.remove_all(["RRULE", "RDATE", "DTSTART", "DTEND", "DURATION"]) + + # Process each period, attempting to update existing recurrences or + # creating new ones. + + for p in periods: + if not p.origin: + continue + + # Attempt to find an existing recurrence. + + obj = self.get_stored_object(self.uid, p.get_recurrenceid()) + if not obj: + obj = template.copy() + + # Acquire the original recurrence identifier associated with + # this period. This may differ where the start of the period + # has changed. + + dt, attr = p.get_recurrenceid_item() + obj["RECURRENCE-ID"] = [(format_datetime(dt), attr)] + + # Set specific recurrence information. + + obj.set_datetime("DTSTART", p.get_start()) + obj.set_datetime("DTEND", p.get_end()) + + objects.append(obj) + + return objects + def get_rescheduled_parts(self, periods, method): """ @@ -860,30 +903,8 @@ rescheduled_parts = [] - if periods: - - # Duplicate the core of the object without any period information. - - obj = self.obj.copy() - obj.remove_all(["RRULE", "RDATE", "DTSTART", "DTEND", "DURATION"]) - - for p in periods: - if not p.origin: - continue - - # Set specific recurrence information. - - obj.set_datetime("DTSTART", p.get_start()) - obj.set_datetime("DTEND", p.get_end()) - - # Acquire the original recurrence identifier associated with - # this period. This may differ where the start of the period has - # changed. - - dt, attr = p.get_recurrenceid_item() - obj["RECURRENCE-ID"] = [(format_datetime(dt), attr)] - - rescheduled_parts.append(self.object_to_part(method, obj)) + for obj in self.get_rescheduled_objects(periods): + rescheduled_parts.append(self.object_to_part(method, obj)) return rescheduled_parts