Commit 42422b43 authored by Romain Courteaud's avatar Romain Courteaud

Fix the diff method, but not yet usable enough.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4308 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 228dfaa2
...@@ -334,6 +334,9 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -334,6 +334,9 @@ class ObjectTemplateItem(BaseTemplateItem):
object.wl_clearLocks() object.wl_clearLocks()
def _backupObject(self, container, object_id, **kw): def _backupObject(self, container, object_id, **kw):
"""
Rename object as a _btsave_
"""
container_ids = container.objectIds() container_ids = container.objectIds()
n = 0 n = 0
new_object_id = object_id new_object_id = object_id
...@@ -451,11 +454,11 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -451,11 +454,11 @@ class ObjectTemplateItem(BaseTemplateItem):
diff_list = list(diff_instance.compare(xml_dict[str(object1)], diff_list = list(diff_instance.compare(xml_dict[str(object1)],
xml_dict[str(object2)])) xml_dict[str(object2)]))
diff_list = [x for x in diff_list if x[0] != ' '] diff_list = [x for x in diff_list if x[0] != ' ']
# Dirty patch to remove useless diff message (id different) # # Dirty patch to remove useless diff message (id different)
if btsave_object_included==1: # if btsave_object_included==1:
if len(diff_list) == 3: # if len(diff_list) == 3:
if '_btsave_' in diff_list[1]: # if '_btsave_' in diff_list[1]:
diff_list = [] # diff_list = []
# Return string # Return string
result = '%s' % ''.join(diff_list) result = '%s' % ''.join(diff_list)
return result return result
...@@ -467,8 +470,25 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -467,8 +470,25 @@ class ObjectTemplateItem(BaseTemplateItem):
""" """
result = '' result = ''
portal = self.getPortalObject() portal = self.getPortalObject()
if (getattr(self, 'template_format_version', 0)) == 0:
object_list = getattr(self, archive_variable).items()
else:
try:
object_list = []
keys = self._objects.keys()
keys.sort()
for path in keys:
container_path = path.split('/')[2:-1]
object_id = path.split('/')[-1]
container = portal.unrestrictedTraverse(container_path)
object = self._objects[path]
object_list.append(('/'.join(path.split('/')[2:]), object))
except:
import pdb
pdb.set_trace()
for relative_url, object in object_list:
# Browse all items stored # Browse all items stored
for relative_url, object in getattr(self, archive_variable).items():
object = portal.unrestrictedTraverse(relative_url) object = portal.unrestrictedTraverse(relative_url)
container_path = relative_url.split('/')[0:-1] container_path = relative_url.split('/')[0:-1]
object_id = relative_url.split('/')[-1] object_id = relative_url.split('/')[-1]
...@@ -483,14 +503,16 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -483,14 +503,16 @@ class ObjectTemplateItem(BaseTemplateItem):
# Found _btsave_ object # Found _btsave_ object
btsave_id_list.append(new_object_id) btsave_id_list.append(new_object_id)
compare_object_couple_list.append( compare_object_couple_list.append(
(object, portal.unrestrictedTraverse( (portal.unrestrictedTraverse(container_path+[object_id]),
container_path+[new_object_id]))) portal.unrestrictedTraverse(container_path+[new_object_id])))
# (object, portal.unrestrictedTraverse(
# container_path+[new_object_id])))
n += 1 n += 1
new_object_id = '%s_btsave_%s' % (object_id, n) new_object_id = '%s_btsave_%s' % (object_id, n)
if n == 1: # if n == 1:
result += "$$$ Added: %s $$$\n" % \ # result += "$$$ Added: %s $$$\n" % \
('/'.join(container_path+[object_id])) # ('/'.join(container_path+[object_id]))
result += '%s\n' % ('-'*80) # result += '%s\n' % ('-'*80)
# Find all objects to compare # Find all objects to compare
deep = 0 deep = 0
while deep != max_deep: while deep != max_deep:
...@@ -876,8 +898,13 @@ class PortalTypeTemplateItem(ObjectTemplateItem): ...@@ -876,8 +898,13 @@ class PortalTypeTemplateItem(ObjectTemplateItem):
result = ObjectTemplateItem.diff(self, verbose=verbose, **kw) result = ObjectTemplateItem.diff(self, verbose=verbose, **kw)
# Compare chains # Compare chains
container_ids = self.portal_types.objectIds() container_ids = self.portal_types.objectIds()
if (getattr(self, 'template_format_version', 0)) == 0:
for object in self._archive.values(): for object in self._archive.values():
try:
object_id = object.id object_id = object.id
except:
import pdb
pdb.set_trace()
object_chain = self.portal_workflow.getChainFor(object_id) object_chain = self.portal_workflow.getChainFor(object_id)
n = 1 n = 1
new_object_id = '%s_btsave_%s' % (object_id, n) new_object_id = '%s_btsave_%s' % (object_id, n)
......
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