1.1 --- a/imiptools/client.py Mon Oct 30 23:15:51 2017 +0100
1.2 +++ b/imiptools/client.py Tue Oct 31 23:45:34 2017 +0100
1.3 @@ -852,6 +852,49 @@
1.4
1.5 # Specific message generation methods.
1.6
1.7 + def get_rescheduled_objects(self, periods):
1.8 +
1.9 + "Return objects describing rescheduled 'periods'."
1.10 +
1.11 + objects = []
1.12 +
1.13 + if periods:
1.14 +
1.15 + # For new recurrences, duplicate the core of the object without any
1.16 + # period information.
1.17 +
1.18 + template = self.obj.copy()
1.19 + template.remove_all(["RRULE", "RDATE", "DTSTART", "DTEND", "DURATION"])
1.20 +
1.21 + # Process each period, attempting to update existing recurrences or
1.22 + # creating new ones.
1.23 +
1.24 + for p in periods:
1.25 + if not p.origin:
1.26 + continue
1.27 +
1.28 + # Attempt to find an existing recurrence.
1.29 +
1.30 + obj = self.get_stored_object(self.uid, p.get_recurrenceid())
1.31 + if not obj:
1.32 + obj = template.copy()
1.33 +
1.34 + # Acquire the original recurrence identifier associated with
1.35 + # this period. This may differ where the start of the period
1.36 + # has changed.
1.37 +
1.38 + dt, attr = p.get_recurrenceid_item()
1.39 + obj["RECURRENCE-ID"] = [(format_datetime(dt), attr)]
1.40 +
1.41 + # Set specific recurrence information.
1.42 +
1.43 + obj.set_datetime("DTSTART", p.get_start())
1.44 + obj.set_datetime("DTEND", p.get_end())
1.45 +
1.46 + objects.append(obj)
1.47 +
1.48 + return objects
1.49 +
1.50 def get_rescheduled_parts(self, periods, method):
1.51
1.52 """
1.53 @@ -860,30 +903,8 @@
1.54
1.55 rescheduled_parts = []
1.56
1.57 - if periods:
1.58 -
1.59 - # Duplicate the core of the object without any period information.
1.60 -
1.61 - obj = self.obj.copy()
1.62 - obj.remove_all(["RRULE", "RDATE", "DTSTART", "DTEND", "DURATION"])
1.63 -
1.64 - for p in periods:
1.65 - if not p.origin:
1.66 - continue
1.67 -
1.68 - # Set specific recurrence information.
1.69 -
1.70 - obj.set_datetime("DTSTART", p.get_start())
1.71 - obj.set_datetime("DTEND", p.get_end())
1.72 -
1.73 - # Acquire the original recurrence identifier associated with
1.74 - # this period. This may differ where the start of the period has
1.75 - # changed.
1.76 -
1.77 - dt, attr = p.get_recurrenceid_item()
1.78 - obj["RECURRENCE-ID"] = [(format_datetime(dt), attr)]
1.79 -
1.80 - rescheduled_parts.append(self.object_to_part(method, obj))
1.81 + for obj in self.get_rescheduled_objects(periods):
1.82 + rescheduled_parts.append(self.object_to_part(method, obj))
1.83
1.84 return rescheduled_parts
1.85