1.1 --- a/imipweb/event.py Sat Oct 17 23:09:07 2015 +0200
1.2 +++ b/imipweb/event.py Sat Oct 17 23:49:28 2015 +0200
1.3 @@ -112,8 +112,11 @@
1.4
1.5 "Return recurrences computed using the current object."
1.6
1.7 + recurrenceids = self._get_recurrences(self.uid)
1.8 recurrences = []
1.9 for period in self.get_periods(self.obj):
1.10 + period = event_period_from_period(period)
1.11 + period.replaced = period.is_replaced(recurrenceids)
1.12 if period.origin != "DTSTART":
1.13 recurrences.append(period)
1.14 return recurrences
1.15 @@ -204,7 +207,7 @@
1.16
1.17 # Obtain any separate recurrences for this event.
1.18
1.19 - recurrenceids = self._get_active_recurrences(self.uid)
1.20 + recurrenceids = self._get_recurrences(self.uid)
1.21 replaced = not self.recurrenceid and period.is_replaced(recurrenceids)
1.22 excluded = period == stored_period and period not in self.get_periods(self.obj)
1.23
1.24 @@ -440,23 +443,20 @@
1.25 if len(recurrences) < 1:
1.26 return
1.27
1.28 - recurrenceids = self._get_recurrences(self.uid)
1.29 -
1.30 page.p("This event occurs on the following occasions within the next %d days:" % self.get_window_size())
1.31
1.32 # Show each recurrence in a separate table.
1.33
1.34 for index, period in enumerate(recurrences):
1.35 - self.show_recurrence(index, period, self.recurrenceid, recurrenceids, errors)
1.36 + self.show_recurrence(index, period, self.recurrenceid, errors)
1.37
1.38 - def show_recurrence(self, index, period, recurrenceid, recurrenceids, errors=None):
1.39 + def show_recurrence(self, index, period, recurrenceid, errors=None):
1.40
1.41 """
1.42 Show recurrence controls for a recurrence provided by the current object
1.43 with the given 'index' position in the list of periods, the given
1.44 'period' details, where a 'recurrenceid' indicates any specific
1.45 - recurrence, and where 'recurrenceids' indicates all known additional
1.46 - recurrences for the object.
1.47 + recurrence.
1.48
1.49 If 'errors' is given, show a suitable message for the different errors
1.50 provided.
1.51 @@ -465,14 +465,6 @@
1.52 page = self.page
1.53 args = self.env.get_args()
1.54
1.55 - try:
1.56 - p = event_period_from_period(period)
1.57 - except PeriodError, exc:
1.58 - replaced = False
1.59 - errors = list(errors or []) + [exc.args]
1.60 - else:
1.61 - replaced = not recurrenceid and p.is_replaced(recurrenceids)
1.62 -
1.63 # Isolate the controls from neighbouring tables.
1.64
1.65 page.div()
1.66 @@ -486,17 +478,17 @@
1.67 page.tr()
1.68 error = errors and ("dtstart", index) in errors and " error" or ""
1.69 page.th("Start", class_="objectheading start%s" % error)
1.70 - self.show_recurrence_controls(index, period, recurrenceid, recurrenceids, True)
1.71 + self.show_recurrence_controls(index, period, recurrenceid, True)
1.72 page.tr.close()
1.73 page.tr()
1.74 error = errors and ("dtend", index) in errors and " error" or ""
1.75 page.th("End", class_="objectheading end%s" % error)
1.76 - self.show_recurrence_controls(index, period, recurrenceid, recurrenceids, False)
1.77 + self.show_recurrence_controls(index, period, recurrenceid, False)
1.78 page.tr.close()
1.79
1.80 # Permit the removal of recurrences.
1.81
1.82 - if not replaced:
1.83 + if not period.replaced:
1.84 page.tr()
1.85 page.th("")
1.86 page.td()
1.87 @@ -833,7 +825,10 @@
1.88 changed = self.obj.set_period(period) or changed
1.89 changed = self.obj.set_periods(periods) or changed
1.90 changed = self.obj.update_exceptions(to_exclude) or changed
1.91 - changed = self.revert_cancellations(periods) or changed
1.92 +
1.93 + # Assert periods restored after cancellation.
1.94 +
1.95 + changed = self.revert_cancellations([p for p in periods if not p.replaced]) or changed
1.96
1.97 # Organiser-only changes...
1.98
1.99 @@ -997,15 +992,18 @@
1.100 all_starts = self.get_date_control_values("dtstart-recur", multiple=True)
1.101 all_ends = self.get_date_control_values("dtend-recur", multiple=True, tzid_name="dtstart-recur")
1.102 all_origins = args.get("recur-origin", [])
1.103 + all_replaced = args.get("recur-replaced", [])
1.104
1.105 periods = []
1.106
1.107 - for index, (start, end, dtend_enabled, dttimes_enabled, origin) in \
1.108 - enumerate(map(None, all_starts, all_ends, all_dtend_enabled, all_dttimes_enabled, all_origins)):
1.109 + for index, (start, end, origin) in \
1.110 + enumerate(map(None, all_starts, all_ends, all_origins)):
1.111
1.112 dtend_enabled = str(index) in all_dtend_enabled
1.113 dttimes_enabled = str(index) in all_dttimes_enabled
1.114 - period = FormPeriod(start, end, dtend_enabled, dttimes_enabled, self.get_tzid(), origin)
1.115 + replaced = str(index) in all_replaced
1.116 +
1.117 + period = FormPeriod(start, end, dtend_enabled, dttimes_enabled, self.get_tzid(), origin, replaced)
1.118 periods.append(period)
1.119
1.120 return periods
1.121 @@ -1019,6 +1017,7 @@
1.122 args["dtend-control-recur"] = []
1.123 args["dttimes-control-recur"] = []
1.124 args["recur-origin"] = []
1.125 + args["recur-replaced"] = []
1.126
1.127 all_starts = []
1.128 all_ends = []
1.129 @@ -1028,6 +1027,8 @@
1.130 args["dtend-control-recur"].append(str(index))
1.131 if period.times_enabled:
1.132 args["dttimes-control-recur"].append(str(index))
1.133 + if period.replaced:
1.134 + args["recur-replaced"].append(str(index))
1.135 args["recur-origin"].append(period.origin or "")
1.136
1.137 all_starts.append(period.get_form_start())