Commit 42c67a7f authored by Aurel's avatar Aurel

allow to specify temp_object parameter to newContent in order to

generate temporary object
add unit test for this


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10880 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a26f7cd0
......@@ -70,7 +70,7 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer):
def newContent(self, id=None, portal_type=None, id_group=None,
default=None, method=None, immediate_reindex=0,
container=None, created_by_builder=0, activate_kw=None,
is_indexable=None, **kw):
is_indexable=None, temp_object=0, **kw):
"""Creates a new content.
This method is public, since TypeInformation.constructInstance will perform
the security check.
......@@ -86,6 +86,17 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer):
# XXX This feature is very confusing
# And made the code more difficult to update
portal_type = container.allowedContentTypes()[0].id
if temp_object:
from Products.ERP5Type import Document
# we get an object from factory only for first temp container object
# otherwise we get an id so we can use the classic way
if not hasattr(container, 'isTempObject') or \
(hasattr(container, 'isTempObject') and not container.isTempObject()):
factory_name = 'newTemp%s' %(portal_type.replace(' ', ''))
m = getattr(Document, factory_name)
return m(container, new_id)
self.portal_types.constructContent(type_name=portal_type,
container=container,
id=new_id,
......
......@@ -225,9 +225,23 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
self.assertEquals(o.isTempObject(), 1)
# Create a subobject and make sure it is a Temp Object
a = o.newContent(portal_type = 'Telephone')
a = o.newContent(portal_type = 'Telephone')
self.assertEquals(a.isTempObject(), 1)
# Test newContent with the temp_object parameter
o = portal.person_module.newContent(id=987, portal_type="Person", temp_object=1)
o.setTitle('bar')
self.assertEquals(o.getTitle(), 'bar')
self.assertEquals(str(o.getId()), str(987))
self.assertEquals(o.isTempObject(), 1)
a = o.newContent(id=1, portal_type="Telephone", temp_object=1)
self.assertEquals(str(a.getId()), str(1))
self.assertEquals(a.isTempObject(), 1)
b = o.newContent(id=2, portal_type="Telephone")
self.assertEquals(b.isTempObject(), 1)
self.assertEquals(b.getId(), str(2))
def test_04_CategoryAccessors(self, quiet=quiet, run=run_all_test):
"""
This test provides basic testing of category
......
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