Commit c111b3a5 authored by Aurel's avatar Aurel

fix some preinstall

add way to make diff of objects with a given business template


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4957 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 92744996
...@@ -1972,7 +1972,9 @@ class RoleTemplateItem(BaseTemplateItem): ...@@ -1972,7 +1972,9 @@ class RoleTemplateItem(BaseTemplateItem):
if installed_bt.id == 'installed_bt_for_diff': if installed_bt.id == 'installed_bt_for_diff':
#must rename keys in dict if reinstall #must rename keys in dict if reinstall
new_dict = PersistentMapping() new_dict = PersistentMapping()
old_keys = installed_bt._objects.values()[0] old_keys = ()
if len(installed_bt._objects.values()) > 0:
old_keys = installed_bt._objects.values()[0]
for key in old_keys: for key in old_keys:
new_dict[key] = '' new_dict[key] = ''
installed_bt._objects = new_dict installed_bt._objects = new_dict
...@@ -3207,7 +3209,8 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3207,7 +3209,8 @@ Business Template is a set of definitions, such as skins, portal types and categ
""" """
Return the list of modified/new/removed object between a Business Template Return the list of modified/new/removed object between a Business Template
and the one installed if exists and the one installed if exists
""" """
modified_object_list = {} modified_object_list = {}
bt_title = self.getTitle() bt_title = self.getTitle()
installed_bt = self.portal_templates.getInstalledBusinessTemplate(title=bt_title) installed_bt = self.portal_templates.getInstalledBusinessTemplate(title=bt_title)
...@@ -3227,6 +3230,11 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3227,6 +3230,11 @@ Business Template is a set of definitions, such as skins, portal types and categ
bt2.edit(description='tmp bt generated for diff') bt2.edit(description='tmp bt generated for diff')
bt2.build() bt2.build()
installed_bt = bt2 installed_bt = bt2
# can be call to diff two Business Template in template tool
bt2 = kw.get('compare_to', None)
if bt2 is not None:
installed_bt = bt2
new_bt_format = self.getTemplateFormatVersion() new_bt_format = self.getTemplateFormatVersion()
if installed_bt_format == 0 and new_bt_format == 0: if installed_bt_format == 0 and new_bt_format == 0:
...@@ -3705,7 +3713,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3705,7 +3713,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
getattr(self, item_name).importFile(bta) getattr(self, item_name).importFile(bta)
def diffObject(self, REQUEST): def diffObject(self, REQUEST, **kw):
""" """
Make a diff between an object in the Business Template Make a diff between an object in the Business Template
and the same in the Business Template installed in the site and the same in the Business Template installed in the site
...@@ -3746,10 +3754,17 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3746,10 +3754,17 @@ Business Template is a set of definitions, such as skins, portal types and categ
object_class = REQUEST.object_class object_class = REQUEST.object_class
# get objects # get objects
item_name = class_name_dict[object_class] item_name = class_name_dict[object_class]
new_bt =self new_bt =self
installed_bt = self.getInstalledBusinessTemplate(title=self.getTitle()) installed_bt = self.getInstalledBusinessTemplate(title=self.getTitle())
if installed_bt == new_bt: if installed_bt == new_bt:
return 'No diff at reinstall' return 'No diff at reinstall'
# compare with a given business template
bt2_id = kw.get('compare_with', None)
if bt2_id is not None:
installed_bt = self.portal_templates._getOb(bt2_id)
new_item = getattr(new_bt, item_name) new_item = getattr(new_bt, item_name)
installed_item = getattr(installed_bt, item_name) installed_item = getattr(installed_bt, item_name)
new_object = new_item._objects[object_id] new_object = new_item._objects[object_id]
...@@ -3781,6 +3796,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3781,6 +3796,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
diff_msg += '\n'.join(diff_list) diff_msg += '\n'.join(diff_list)
else: else:
diff_msg = 'No diff' diff_msg = 'No diff'
elif item_name in item_list_2: elif item_name in item_list_2:
new_obj_xml = new_item.generateXml(path= object_id) new_obj_xml = new_item.generateXml(path= object_id)
installed_obj_xml = installed_item.generateXml(path= object_id) installed_obj_xml = installed_item.generateXml(path= object_id)
...@@ -3792,6 +3808,7 @@ Business Template is a set of definitions, such as skins, portal types and categ ...@@ -3792,6 +3808,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
diff_msg += '\n'.join(diff_list) diff_msg += '\n'.join(diff_list)
else: else:
diff_msg = 'No diff' diff_msg = 'No diff'
elif item_name in item_list_3: elif item_name in item_list_3:
new_obj_lines = new_object.splitlines() new_obj_lines = new_object.splitlines()
installed_obj_lines = installed_object.splitlines() installed_obj_lines = installed_object.splitlines()
......
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