Commit bff9e56b authored by Julien Muchembled's avatar Julien Muchembled

Fix testBusinessTemplate

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/portal_types@29263 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 28096d6a
......@@ -860,6 +860,7 @@ class ObjectTemplateItem(BaseTemplateItem):
raise
saved_uid_dict = {}
subobjects_dict = {}
portal_type_dict = {}
# Object already exists
old_obj = container._getOb(object_id, None)
if old_obj is not None:
......@@ -872,6 +873,15 @@ class ObjectTemplateItem(BaseTemplateItem):
old_groups[path] = deepcopy(old_obj.groups)
subobjects_dict = self._backupObject(action, trashbin,
container_path, object_id)
# in case of portal types, we want to keep some properties
if getattr(old_obj, 'meta_type', None) == 'ERP5 Type Information':
for attr in ('allowed_content_type_list',
'hidden_content_type_list',
'property_sheet_list',
'base_category_list'):
portal_type_dict[attr] = getattr(old_obj, attr, ())
portal_type_dict['workflow_chain'] = \
getChainByType(context)[1].get('chain_' + object_id, '')
container.manage_delObjects([object_id])
else:
self.onNewObject()
......@@ -897,43 +907,17 @@ class ObjectTemplateItem(BaseTemplateItem):
self.REQUEST.set('is_business_template_installation', 1)
obj.manage_afterClone(obj)
obj.wl_clearLocks()
# if portal types upgrade, set backup properties
if getattr(obj, 'meta_type', None) == 'ERP5 Type Information' and \
len(subobjects_dict) > 0:
setattr(obj, 'allowed_content_types',
subobjects_dict['allowed_content_type_list'] or [])
setattr(obj, 'hidden_content_type_list',
subobjects_dict['hidden_content_type_list'] or [])
setattr(obj, 'property_sheet_list',
subobjects_dict['property_sheet_list'] or [])
setattr(obj, 'base_category_list',
subobjects_dict['base_category_list'] or [])
setattr(obj, '_roles', subobjects_dict['roles_list'] or [])
# set actions
action_list = subobjects_dict['action_list']
for action in action_list:
action_text = action.action
if isinstance(action_text, Expression):
action_text = action_text.text
obj.addAction(id = action.id
, name = action.title
, action = action_text
, condition = action.getCondition()
, permission = action.permissions
, category = action.category
, visible = action.visible
, icon = getattr(action, 'icon', None) and action.icon.text or ''
, priority = action.priority
, description = action.description
)
if portal_type_dict:
# set workflow chain
wf_chain = subobjects_dict['workflow_chain']
wf_chain = portal_type_dict.pop('workflow_chain')
chain_dict = getChainByType(context)[1]
default_chain = ''
chain_dict['chain_%s' % (object_id)] = wf_chain
context.portal_workflow.manage_changeWorkflows(default_chain, props=chain_dict)
# restore some other properties
obj.__dict__.update(portal_type_dict)
# import sub objects if there is
elif len(subobjects_dict) > 0:
if subobjects_dict:
# get a jar
connection = obj._p_jar
o = obj
......@@ -4881,7 +4865,6 @@ 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
and the one installed if exists
"""
if check_dependencies:
# required because in multi installation, dependencies has already
# been checked before and it will failed here as dependencies can be
......@@ -5730,7 +5713,7 @@ Business Template is a set of definitions, such as skins, portal types and categ
portal_type = ttool.getTypeInfo(id)
if portal_type is None:
continue
if len(getattr(portal_type, '_roles', ())) > 0:
if portal_type.getRoleInformationList():
if id not in bt_portal_type_roles_list:
bt_portal_type_roles_list.append(id)
......@@ -5747,8 +5730,8 @@ Business Template is a set of definitions, such as skins, portal types and categ
property_sheet_list = portal_type.property_sheet_list
if hasattr(portal_type, 'base_category_list'):
base_category_list = portal_type.base_category_list
if hasattr(portal_type, 'listActions'):
action_list = [x.getId() for x in portal_type.listActions()]
for action in portal_type.getActionInformationList():
action_list.append(action.getReference())
for a_id in allowed_content_type_list:
allowed_id = id+' | '+a_id
......
......@@ -120,33 +120,14 @@ class TrashTool(BaseTool):
else:
object_path = container_path + [object_id]
obj = self.unrestrictedTraverse(object_path)
if obj is None:
pass
# in case of portal types, export properties instead of subobjects
elif getattr(obj, 'meta_type', None) == 'ERP5 Type Information':
subobjects_dict = {}
subobjects_dict['allowed_content_type_list'] = getattr(obj, 'allowed_content_types', []) or []
subobjects_dict['hidden_content_type_list'] = getattr(obj, 'hidden_content_type_list', []) or []
subobjects_dict['property_sheet_list'] = getattr(obj, 'property_sheet_list', []) or []
subobjects_dict['base_category_list'] = getattr(obj, 'base_category_list', []) or []
subobjects_dict['roles_list'] = getattr(obj, '_roles', []) or []
action_list = obj.listActions() or []
subobjects_dict['action_list'] = []
for action in action_list:
subobjects_dict['action_list'].append(action._getCopy(obj))
wf_chain = getChainByType(self.getPortalObject())[1]
if wf_chain.has_key('chain_%s' % object_id):
subobjects_dict['workflow_chain'] = wf_chain['chain_%s' % object_id]
else:
subobjects_dict['workflow_chain'] = ''
else:
if obj is not None:
for subobject_id in list(obj.objectIds()):
subobject_path = object_path + [subobject_id]
subobject = self.unrestrictedTraverse(subobject_path)
subobject_copy = subobject._p_jar.exportFile(subobject._p_oid)
subobjects_dict[subobject_id] = subobject_copy
if save: # remove subobjecs from backup object
obj.manage_delObjects([subobject_id])
obj._delObject(subobject_id)
return subobjects_dict
def newTrashBin(self, bt_title='trash', bt=None):
......
This diff is collapsed.
......@@ -210,14 +210,12 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
translation_service = DummyTranslationService()
setGlobalTranslationService(translation_service)
# adds a new jump action to Template Tool portal type
self.getTypesTool().getTypeInfo('Template Tool').addAction(
id='dummy_jump_action',
name='Dummy Jump Action',
action='',
condition='',
permission='View',
category='object_jump',
visible=1)
self.getTypesTool().getTypeInfo('Template Tool').newContent(
portal_type='Action Information',
reference='dummy_jump_action',
title='Dummy Jump Action',
action_permission='View',
action_type='object_jump')
response = self.publish('%s/portal_templates/view' %
self.portal_id, self.auth)
self.assertEquals(HTTP_OK, response.getStatus())
......
......@@ -593,6 +593,8 @@ class ERP5TypeInformation(XMLObject,
permissions=tuple(action.getActionPermissionList()))
for k, v in action.__dict__.iteritems():
if k in ('action', 'condition', 'icon'):
if not v:
continue
v = v.__class__(v.text)
elif k in ('id', 'float_index', 'action_permission', 'reference'):
continue
......
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