Commit 4568a93b authored by Jérome Perrin's avatar Jérome Perrin

New feature: manage_afterClone can be customized in a type based script



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7658 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8b6da607
...@@ -208,11 +208,15 @@ class CopyContainer: ...@@ -208,11 +208,15 @@ class CopyContainer:
l.append('Owner') l.append('Owner')
# Clear the transaction references # Clear the transaction references
# THIS IS NOT GENERIC ENOUGH - PROPERTY SHEET EXTENSION REQUIRED
if getattr(self_base, 'default_source_reference', None): if getattr(self_base, 'default_source_reference', None):
delattr(self_base, 'default_source_reference') delattr(self_base, 'default_source_reference')
if getattr(self_base, 'default_destination_reference', None): if getattr(self_base, 'default_destination_reference', None):
delattr(self_base, 'default_destination_reference') delattr(self_base, 'default_destination_reference')
# Call a type based method to reset so properties if necessary
script = self._getTypeBasedMethod('afterClone')
if script is not None and callable(script):
script()
# Clear the workflow history # Clear the workflow history
# XXX This need to be tested again # XXX This need to be tested again
......
...@@ -240,6 +240,52 @@ class TestERP5Type(ERP5TypeTestCase): ...@@ -240,6 +240,52 @@ class TestERP5Type(ERP5TypeTestCase):
clearCache() clearCache()
self.assertEquals(cache2(), cached_var2) self.assertEquals(cache2(), cached_var2)
def test_afterCloneScript(self):
"""manage_afterClone can call a type based script."""
# setup the script for Person portal type
custom_skin = self.getPortal().portal_skins.custom
method_id = 'Person_afterClone'
if method_id in custom_skin.objectIds():
custom_skin.manage_delObjects([method_id])
custom_skin.manage_addProduct['PythonScripts']\
.manage_addPythonScript(id = method_id)
script = custom_skin[method_id]
script.ZPythonScript_edit('', "context.setTitle('reseted')")
self.getPortal().changeSkin(None)
# copy / pasted person have their title reseted
folder = self.getPersonModule()
pers = folder.newContent(portal_type='Person',
title='something', )
copy_data = folder.manage_copyObjects([pers.getId()])
new_id = folder.manage_pasteObjects(copy_data)[0]['new_id']
new_pers = folder[new_id]
self.assertEquals(new_pers.getTitle(), 'reseted')
# we can even change subobjects in the script
if not hasattr(pers, 'default_address'):
pers.newContent(portal_type='Address', id='default_address')
pers.default_address.setTitle('address_title')
# modify script to update subobject title
script.ZPythonScript_edit('',
"context.default_address.setTitle('address_title_reseted')")
copy_data = folder.manage_copyObjects([pers.getId()])
new_id = folder.manage_pasteObjects(copy_data)[0]['new_id']
new_pers = folder[new_id]
self.assertEquals(new_pers.default_address.getTitle(),
'address_title_reseted')
# of course, other portal types are not affected
folder = self.getOrganisationModule()
orga = folder.newContent(portal_type='Organisation',
title='something', )
copy_data = folder.manage_copyObjects([orga.getId()])
new_id = folder.manage_pasteObjects(copy_data)[0]['new_id']
new_orga = folder[new_id]
self.assertEquals(new_orga.getTitle(), 'something')
if __name__ == '__main__': if __name__ == '__main__':
framework() framework()
else: else:
......
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