# HG changeset patch # User Paul Boddie # Date 1513033522 -3600 # Node ID 05de61cc499f715c89a3bbb784122cb7331674dd # Parent 0249f30178a473d815421afa6ccbc84f1549582b Made period classification use unedited rather than stored periods. diff -r 0249f30178a4 -r 05de61cc499f imiptools/editing.py --- a/imiptools/editing.py Mon Dec 11 22:09:38 2017 +0100 +++ b/imiptools/editing.py Tue Dec 12 00:05:22 2017 +0100 @@ -401,26 +401,16 @@ "Classify changes in the updated periods for the edited event." - updated = self.combine_periods_for_comparison() - return classify_period_changes(updated) + return classify_period_changes(self.combine_periods()) def classify_periods(self): "Classify the updated periods for the edited event." - updated = self.combine_periods() - return classify_periods(updated) + return classify_periods(self.combine_periods()) def combine_periods(self): - "Combine stored and checked edited periods to make updated periods." - - stored = self.get_stored_periods() - current = self.get_checked_periods() - return combine_periods(stored, current) - - def combine_periods_for_comparison(self): - "Combine unedited and checked edited periods to make updated periods." original = self.state.get_original("periods") @@ -1207,8 +1197,9 @@ def periods_from_updated_periods(updated_periods, fn): """ - Return periods from the given 'updated_periods' created using 'fn', setting - replacement, cancelled and recurrence identifier details. + Return periods from the given 'updated_periods' having the form (stored, + unedited), creating them using 'fn', and setting replacement, cancelled and + recurrence identifier details. This function should be used to produce editing-related periods from the general updated periods provided by the client abstractions. @@ -1244,9 +1235,21 @@ return periods def event_periods_from_updated_periods(updated_periods): + + """ + Return event periods from the 'updated_periods' having the form (stored, + unedited). + """ + return periods_from_updated_periods(updated_periods, event_period_from_period) def form_periods_from_updated_periods(updated_periods): + + """ + Return form periods from the 'updated_periods' having the form (stored, + unedited). + """ + return periods_from_updated_periods(updated_periods, form_period_from_period) def periods_by_recurrence(periods): @@ -1271,7 +1274,8 @@ """ Combine 'old' and 'new' periods for comparison, making a list of (old, new) - updated period tuples. + updated period tuples. Such tuples encode correspondences between periods + representing the same, potentially-edited data. """ old_by_recurrenceid, _new_periods = periods_by_recurrence(old) @@ -1302,10 +1306,10 @@ return combined -def classify_periods(updated_periods): +def classify_periods(edited_periods): """ - Using the 'updated_periods', being a list of (stored, current) periods, + Using the 'edited_periods', being a list of (unedited, edited) periods, return a tuple containing collections of new, replaced, retained, cancelled and obsolete periods. @@ -1323,24 +1327,24 @@ cancelled = [] obsolete = [] - for sp, p in updated_periods: + for op, p in edited_periods: - # Stored periods... + # Unedited periods that are not cancelled. - if sp: + if op and not op.cancelled: # With cancelled or absent current periods. if not p or p.cancelled: - cancelled.append(sp) + cancelled.append(op) # With differing or replacement current periods. - elif p != sp or p.replacement: + elif p != op or p.replacement: replaced.append(p) if not p.replacement: p.new_replacement = True - obsolete.append(sp) + obsolete.append(op) # With retained, not differing current periods. @@ -1349,17 +1353,17 @@ if p.new_replacement: p.new_replacement = False - # New periods without corresponding stored periods. + # New periods without corresponding unedited periods. elif p: new.append(p) return new, replaced, retained, cancelled, obsolete -def classify_period_changes(updated_periods): +def classify_period_changes(edited_periods): """ - Using the 'updated_periods', being a list of (original, current) periods, + Using the 'edited_periods', being a list of (unedited, edited) periods, return a tuple containing collections of modified, unmodified and removed periods. """ @@ -1368,7 +1372,7 @@ unmodified = [] removed = [] - for op, p in updated_periods: + for op, p in edited_periods: # Test for periods cancelled, reinstated or changed, or left unmodified # during editing.