1.1 --- a/imipweb/data.py Sun Oct 15 23:21:37 2017 +0200
1.2 +++ b/imipweb/data.py Sun Oct 15 23:22:28 2017 +0200
1.3 @@ -343,7 +343,7 @@
1.4
1.5 "Classify period update operations."
1.6
1.7 - new, replaced, retained, cancelled = self.classify_periods()
1.8 + new, replaced, retained, cancelled, obsolete = self.classify_periods()
1.9
1.10 modified, unmodified, removed = self.classify_period_changes()
1.11
1.12 @@ -351,7 +351,7 @@
1.13 is_shared = self.obj.is_shared()
1.14
1.15 return classify_period_operations(new, replaced, retained, cancelled,
1.16 - modified, removed,
1.17 + obsolete, modified, removed,
1.18 is_organiser, is_shared, is_changed)
1.19
1.20 def properties_changed(self):
1.21 @@ -1195,19 +1195,22 @@
1.22
1.23 """
1.24 Using the 'updated_periods', being a list of (stored, current) periods,
1.25 - return a tuple containing collections of new, replaced, retained and
1.26 - cancelled periods.
1.27 + return a tuple containing collections of new, replaced, retained, cancelled
1.28 + and obsolete periods.
1.29
1.30 Note that replaced and retained indicate the presence or absence of
1.31 differences between the original event periods and the current periods that
1.32 would need to be represented using separate recurrence instances, not
1.33 whether any editing operations have changed the periods.
1.34 +
1.35 + Obsolete periods are those that have been replaced but not cancelled.
1.36 """
1.37
1.38 new = []
1.39 replaced = []
1.40 retained = []
1.41 cancelled = []
1.42 + obsolete = []
1.43
1.44 for sp, p in updated_periods:
1.45
1.46 @@ -1226,6 +1229,7 @@
1.47 replaced.append(p)
1.48 if not p.replacement:
1.49 p.new_replacement = True
1.50 + obsolete.append(sp)
1.51
1.52 # With retained, not differing current periods.
1.53
1.54 @@ -1239,7 +1243,7 @@
1.55 elif p:
1.56 new.append(p)
1.57
1.58 - return new, replaced, retained, cancelled
1.59 + return new, replaced, retained, cancelled, obsolete
1.60
1.61 def classify_period_changes(updated_periods):
1.62
1.63 @@ -1274,7 +1278,7 @@
1.64 return modified, unmodified, removed
1.65
1.66 def classify_period_operations(new, replaced, retained, cancelled,
1.67 - modified, removed,
1.68 + obsolete, modified, removed,
1.69 is_organiser, is_shared, is_changed):
1.70
1.71 """
1.72 @@ -1306,14 +1310,6 @@
1.73
1.74 cancelled_removed = select_recurrences(cancelled, removed).values()
1.75
1.76 - # Cancelled periods originating from rules must be excluded since there are
1.77 - # no explicit instances to be deleted.
1.78 -
1.79 - cancelled_rule = []
1.80 - for p in cancelled_removed:
1.81 - if p.origin == "RRULE":
1.82 - cancelled_rule.append(p)
1.83 -
1.84 # Reinstated periods are previously-cancelled periods that are now modified
1.85 # periods, and they appear in updates.
1.86
1.87 @@ -1324,6 +1320,22 @@
1.88
1.89 cancelled_unmodified = subtract_recurrences(cancelled, modified).values()
1.90
1.91 + # Cancelled periods originating from rules must be excluded since there are
1.92 + # no explicit instances to be deleted.
1.93 +
1.94 + cancelled_rule = []
1.95 + for p in cancelled_removed:
1.96 + if p.origin == "RRULE":
1.97 + cancelled_rule.append(p)
1.98 +
1.99 + # Obsolete periods (replaced by other periods) originating from rules must
1.100 + # be excluded if no explicit instance will be used to replace them.
1.101 +
1.102 + obsolete_rule = []
1.103 + for p in obsolete:
1.104 + if p.origin == "RRULE":
1.105 + obsolete_rule.append(p)
1.106 +
1.107 # As organiser...
1.108
1.109 if is_organiser:
1.110 @@ -1339,7 +1351,7 @@
1.111
1.112 if not is_shared or new and not replaced:
1.113 to_set = active_periods
1.114 - to_exclude = cancelled_rule
1.115 + to_exclude = list(chain(cancelled_rule, obsolete_rule))
1.116 to_unschedule = []
1.117 to_reschedule = []
1.118 to_add = []
1.119 @@ -1376,11 +1388,11 @@
1.120 all_rescheduled = list(chain(replaced_unmodified, to_reschedule))
1.121
1.122 # Otherwise, the event is defined in terms of new periods and
1.123 - # exceptions for removed periods.
1.124 + # exceptions for removed periods or obsolete rule periods.
1.125
1.126 else:
1.127 to_set = active_periods
1.128 - to_exclude = cancelled
1.129 + to_exclude = list(chain(cancelled, obsolete_rule))
1.130 to_reschedule = []
1.131 all_unscheduled = []
1.132 all_rescheduled = []