1.1 --- a/imiptools/client.py Sun Oct 15 23:30:38 2017 +0200
1.2 +++ b/imiptools/client.py Mon Oct 16 18:37:33 2017 +0200
1.3 @@ -264,73 +264,31 @@
1.4 start=(future_only and self.get_window_start() or None),
1.5 end=(not explicit_only and self.get_window_end() or None))
1.6
1.7 - def get_updated_periods(self, obj):
1.8 + def get_updated_periods(self, obj, explicit_only=False, future_only=False):
1.9
1.10 """
1.11 Return the periods provided by 'obj' and associated recurrence
1.12 instances. Each original period is returned in a tuple with a
1.13 corresponding updated period which may be the same or which may be None
1.14 if the period is cancelled. A list of these tuples is returned.
1.15 +
1.16 + If 'explicit_only' is set to a true value, only explicit periods will be
1.17 + returned, not rule-based periods.
1.18 +
1.19 + If 'future_only' is set to a true value, only future periods will be
1.20 + returned, not all periods defined by an event starting in the past.
1.21 """
1.22
1.23 uid = obj.get_uid()
1.24 - recurrenceid = obj.get_recurrenceid()
1.25 -
1.26 - updated = []
1.27 -
1.28 - # Consider separate recurrences in isolation from the parent if
1.29 - # specified.
1.30 -
1.31 - if recurrenceid:
1.32 - for period in self.get_periods(obj):
1.33 - updated.append((period, period))
1.34 - return updated
1.35 -
1.36 - # For parent events, identify retained and replaced periods.
1.37 -
1.38 - recurrenceids = self.get_recurrences(uid)
1.39 -
1.40 - for period in self.get_periods(obj):
1.41 - recurrenceid = period.is_replaced(recurrenceids)
1.42 -
1.43 - # For parent event periods, obtain any replacement instead of the
1.44 - # replaced period.
1.45 -
1.46 - if recurrenceid:
1.47 - recurrence = self.get_stored_object(uid, recurrenceid)
1.48 - periods = recurrence and self.get_periods(recurrence)
1.49 -
1.50 - # Active periods are obtained.
1.51
1.52 - if periods:
1.53 -
1.54 - # Recurrence instances are assumed to provide only one
1.55 - # period.
1.56 -
1.57 - replacement = periods[0]
1.58 -
1.59 - # Redefine the origin of periods replacing recurrences and
1.60 - # not the main period, leaving DTSTART as the means of
1.61 - # identifying the main period.
1.62 -
1.63 - if replacement.origin == "DTSTART" and \
1.64 - period.origin != "DTSTART":
1.65 + if not obj.modifying:
1.66 + obj.set_modifying(self.store.get_active_recurrences(self.user, uid))
1.67 + if not obj.cancelling:
1.68 + obj.set_cancelling(self.store.get_cancelled_recurrences(self.user, uid))
1.69
1.70 - replacement.origin = "DTSTART-RECUR"
1.71 -
1.72 - updated.append((period, replacement))
1.73 -
1.74 - # Cancelled periods yield None.
1.75 -
1.76 - else:
1.77 - updated.append((period, None))
1.78 -
1.79 - # Otherwise, retain the known period.
1.80 -
1.81 - else:
1.82 - updated.append((period, period))
1.83 -
1.84 - return updated
1.85 + return obj.get_updated_periods(
1.86 + start=(future_only and self.get_window_start() or None),
1.87 + end=(not explicit_only and self.get_window_end() or None))
1.88
1.89 def get_main_period(self, obj):
1.90