From d192496c88bad0bd2f1c01b97a974fe9cff52238 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Thu, 14 Jan 2010 08:56:04 +0100 Subject: [PATCH] Allows to manually add data changes into an object's history. --- gen/plone25/mixins/ToolMixin.py | 2 +- gen/plone25/mixins/__init__.py | 35 ++++++++++++++++++++++---------- gen/plone25/skin/macros.pt | 12 ++++++++--- gen/plone25/wrappers/__init__.py | 10 +++++++++ 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/gen/plone25/mixins/ToolMixin.py b/gen/plone25/mixins/ToolMixin.py index 92a2b16..f25652a 100644 --- a/gen/plone25/mixins/ToolMixin.py +++ b/gen/plone25/mixins/ToolMixin.py @@ -703,6 +703,6 @@ class ToolMixin(AbstractMixin): res = [] for v in validator: text = self.translate('%s_list_%s' % (appyType['label'], v)) - res.append((v, self.truncate(text, 70))) + res.append((v, self.truncate(text, 50))) return res # ------------------------------------------------------------------------------ diff --git a/gen/plone25/mixins/__init__.py b/gen/plone25/mixins/__init__.py index 02233b7..c3b37cd 100644 --- a/gen/plone25/mixins/__init__.py +++ b/gen/plone25/mixins/__init__.py @@ -159,6 +159,28 @@ class AbstractMixin: atField.widget.label_msgid) return res + def addDataChange(self, changes, labels=False): + '''This method allows to add "manually" a data change into the objet's + history. Indeed, data changes are "automatically" recorded only when + a HTTP form is uploaded, not if, in the code, a setter is called on + a field. The method is also called by the method historizeData below, + that performs "automatic" recording when a HTTP form is uploaded.''' + # Add to the p_changes dict the field labels if they are not present + if not labels: + for fieldName in changes.iterkeys(): + appyType = self.getAppyType(fieldName) + changes[fieldName] = (changes[fieldName], appyType['label']) + # Create the event to record in the history + DateTime = self.getProductConfig().DateTime + state = self.portal_workflow.getInfoFor(self, 'review_state') + user = self.portal_membership.getAuthenticatedMember() + event = {'action': '_datachange_', 'changes': changes, + 'review_state': state, 'actor': user.id, + 'time': DateTime(), 'comments': ''} + # Add the event to the history + histKey = self.workflow_history.keys()[0] + self.workflow_history[histKey] += (event,) + def historizeData(self, previousData): '''Records in the object history potential changes on historized fields. p_previousData contains the values, before an update, of the @@ -172,16 +194,7 @@ class AbstractMixin: ((prev == '') and (curr == None)): del previousData[fieldName] if previousData: - # Create the event to add in the history - DateTime = self.getProductConfig().DateTime - state = self.portal_workflow.getInfoFor(self, 'review_state') - user = self.portal_membership.getAuthenticatedMember() - event = {'action': '_datachange_', 'changes': previousData, - 'review_state': state, 'actor': user.id, - 'time': DateTime(), 'comments': ''} - # Add the event to the history - histKey = self.workflow_history.keys()[0] - self.workflow_history[histKey] += (event,) + self.addDataChange(previousData, labels=True) def goto(self, url, addParams=False): '''Brings the user to some p_url after an action has been executed.''' @@ -670,7 +683,7 @@ class AbstractMixin: def getHistory(self, startNumber=0, reverse=True, includeInvisible=False): '''Returns the history for this object, sorted in reverse order (most recent change first) if p_reverse is True.''' - batchSize = 3 + batchSize = 5 key = self.workflow_history.keys()[0] history = list(self.workflow_history[key][1:]) if not includeInvisible: diff --git a/gen/plone25/skin/macros.pt b/gen/plone25/skin/macros.pt index 3efb590..b33765c 100644 --- a/gen/plone25/skin/macros.pt +++ b/gen/plone25/skin/macros.pt @@ -319,10 +319,16 @@ - + - + + + + diff --git a/gen/plone25/wrappers/__init__.py b/gen/plone25/wrappers/__init__.py index e1db04d..830764d 100644 --- a/gen/plone25/wrappers/__init__.py +++ b/gen/plone25/wrappers/__init__.py @@ -324,6 +324,16 @@ class AbstractWrapper: else: return xml + def historize(self, data): + '''This method allows to add "manually" a "data-change" event into the + object's history. Indeed, data changes are "automatically" recorded + only when an object is edited through the edit form, not when a + setter is called from the code. + + p_data must be a dictionary whose keys are field names (strings) and + whose values are the previous field values.''' + self.o.addDataChange(data, labels=False) + # ------------------------------------------------------------------------------ class FileWrapper: '''When you get, from an appy object, the value of a File attribute, you