Allows to manually add data changes into an object's history.
This commit is contained in:
parent
db8ad18c5f
commit
d192496c88
|
@ -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
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -319,10 +319,16 @@
|
|||
<th align="left" width="30%" tal:content="python: tool.translate('modified_field')"></th>
|
||||
<th align="left" width="70%" tal:content="python: tool.translate('previous_value')"></th>
|
||||
</tr>
|
||||
<tr tal:repeat="change event/changes/items">
|
||||
<tr tal:repeat="change event/changes/items" valign="top">
|
||||
<td tal:content="python: tool.translate(change[1][1])"></td>
|
||||
<td tal:define="appyType python:contextObj.getAppyType(change[0])"
|
||||
tal:content="python: contextObj.getAppyValue(change[0], appyType, True, change[1][0])"></td>
|
||||
<td tal:define="appyType python:contextObj.getAppyType(change[0]);
|
||||
appyValue python: contextObj.getAppyValue(change[0], appyType, True, change[1][0]);
|
||||
severalValues python: (appyType['multiplicity'][1] > 1) or (appyType['multiplicity'][1] == None)">
|
||||
<span tal:condition="not: severalValues" tal:replace="appyValue"></span>
|
||||
<ul tal:condition="python: severalValues">
|
||||
<li tal:repeat="av appyValue" tal:content="av"></li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue