1.1 --- a/imipweb/data.py Wed Sep 13 00:09:24 2017 +0200
1.2 +++ b/imipweb/data.py Wed Sep 13 00:21:06 2017 +0200
1.3 @@ -358,6 +358,39 @@
1.4 active_periods[p] += 1
1.5 return active_periods
1.6
1.7 +def get_removed_periods(periods, still_to_remove):
1.8 +
1.9 + """
1.10 + From the recurrence 'periods', given details of those 'still_to_remove',
1.11 + return the remaining active periods and the periods to unschedule or
1.12 + exclude, using a tuple of the form (active, unscheduled, excluded).
1.13 + """
1.14 +
1.15 + to_remove = set()
1.16 +
1.17 + # Get all periods that are not replaced.
1.18 +
1.19 + active_periods = get_active_periods(periods)
1.20 +
1.21 + for i in still_to_remove:
1.22 + try:
1.23 + period = periods[int(i)]
1.24 + except (IndexError, ValueError):
1.25 + continue
1.26 +
1.27 + active_periods[period] -= 1
1.28 + to_remove.add(period)
1.29 +
1.30 + # Determine whether some periods are both removed and added.
1.31 +
1.32 + remaining = []
1.33 + for period, n in active_periods.items():
1.34 + if n > 0:
1.35 + remaining.append(period)
1.36 +
1.37 + to_remove.difference_update(remaining)
1.38 + return remaining, to_remove
1.39 +
1.40
1.41
1.42 # Form field extraction and serialisation.