From f4e40caf5ce47547f8bac8a8849f8e4f6d301817 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Thu, 10 Jan 2013 11:47:39 +0100 Subject: [PATCH] [gen] Bugfixes in historization. --- gen/mixins/__init__.py | 5 +++-- shared/diff.py | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gen/mixins/__init__.py b/gen/mixins/__init__.py index e24d791..f70b7c0 100644 --- a/gen/mixins/__init__.py +++ b/gen/mixins/__init__.py @@ -1041,7 +1041,8 @@ class BaseMixin: else: for event in history: if (event['action'] == '_datachange_') and \ - (fieldName in event['changes']): return True + (fieldName in event['changes']) and \ + event['changes'][fieldName][0]: return True def getHistory(self, startNumber=0, reverse=True, includeInvisible=False, batchSize=5): @@ -1079,7 +1080,7 @@ class BaseMixin: (field.format == gen.String.XHTML): # For rich text fields, instead of simply showing the # previous value, we propose a diff with the next - # version. + # version, excepted if the previous value is empty. if field.isEmptyValue(oldValue[0]): val = '-' else: diff --git a/shared/diff.py b/shared/diff.py index e2b0aa0..5654571 100644 --- a/shared/diff.py +++ b/shared/diff.py @@ -660,6 +660,14 @@ class HtmlDiff: def get(self): '''Produces the result.''' + # Normally, if self.old is empty, the whole self.new should be + # considered as inserted text. But see this line: if not self.old or not self.old.strip(): return self.new + # Why? This is for avoiding problems in the case of cumulative diffs. + # A cumulative diff means: calling HtmlDiff with, as old value, the + # result of a previous call to HtmlDiff. In this case, if the whole text + # is already considered as inserted, we will already have overlaps in + # the next diff. Overlaps are hard to manage, so we avoid to get them + # as a starting point when computing cumulative diffs. return self.getHtmlDiff(self.old, self.new, '\n') # ------------------------------------------------------------------------------