Commit 5eac0483 authored by Ayush Tiwari's avatar Ayush Tiwari

[erp5_core]: Add functions for property history in ZODB History component

parent 95352144
......@@ -28,6 +28,8 @@
#
##############################################################################
from DateTime import DateTime
from OFS.History import historicalRevision
from Products.ERP5Type.Log import log
def _parseCategory(category):
if category is None or category.find('/') < 0:
......@@ -110,7 +112,8 @@ def getChangeHistoryList(document, size=50, attribute_name=None):
current_state = connection.oldstate(document, d_['tid'])
changes = {}
current_datetime = toDateTime(d_['time'])
record = {'datetime':current_datetime,
record = {'serial': d_['tid'],
'datetime':current_datetime,
'user':d_['user_name'],
'action':d_['description'],
'changes':changes
......@@ -140,6 +143,49 @@ def getChangeHistoryList(document, size=50, attribute_name=None):
return history
def getChangeHistoryListDiffFormat(document, size=50, attribute_name=None):
"""
Returns ZODB History in the format which can be used to create diff,
i.e, just follow the basic key value pair format of a python dictionary.
"""
connection = document._p_jar
result = document._p_jar.db().history(document._p_oid, size=size)
if result is None:
return []
result = list(reversed(result))
history = []
previous_state = None
for d_ in result:
current_state = connection.oldstate(document, d_['tid'])
changes = {}
current_datetime = toDateTime(d_['time'])
record = {'serial': d_['tid'],
'datetime':current_datetime,
'user':d_['user_name'],
'action':d_['description'],
'changes':changes
}
log(record)
if previous_state is None:
previous_state = {}
for key in current_state:
if key.startswith('_') or key == 'workflow_history':
continue
if previous_state.get(key) != current_state[key]:
changes[key] = current_state[key]
if key == 'categories':
for cat in current_state.get('categories', ()):
ck, cv = _parseCategory(cat)
if ck in changes:
changes[ck].append(cv)
else:
changes[ck] = [cv]
history.append(record)
previous_state = current_state
return history
def getChangeHistoryListForProperty(document,
property_name,
size=50,
......@@ -168,6 +214,9 @@ def getChangeHistoryListForProperty(document,
return property_change_list
def getHistoricalRevisionFromSerial(document, serial):
return historicalRevision(document, serial).showDict()
def getHistoricalRevisionsDateList(document, size=50):
"""
Returns the list dates in float format for the last
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment