Commit ed81a3d4 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ERP5Site: Do not override newContent() but use FolderMixIn implementation to...

ERP5Site: Do not override newContent() but use FolderMixIn implementation to have a consistent behavior.

ERP5Site was raising error when ID or portal_type was not passed but there is
no reason to do so (as it is done in FolderMixIn.newContent()). This allows
calling ERP5Site.newContent(temp_object=True) without ID, likewise Folder.
parent 6879d011
......@@ -283,6 +283,9 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
request.RESPONSE.realm = None
return super(ERP5Site, self).__before_publishing_traverse__(self2, request)
def _getTypesTool(self):
return self.portal_types
def _initSystemPreference(self, cloudooo_url):
"""
Post-addERP5Site code to make sure that cloudoo is configured,
......@@ -1746,25 +1749,6 @@ class ERP5Site(FolderMixIn, CMFSite, CacheCookieMixin):
if module_id:
return getattr(self, module_id, None)
security.declareProtected(Permissions.AddPortalContent, 'newContent')
def newContent(self, id=None, portal_type=None, **kw):
"""
Creates a new content
"""
if id is None:
raise ValueError, 'The id should not be None'
if portal_type is None:
raise ValueError, 'The portal_type should not be None'
self.portal_types.constructContent(type_name=portal_type,
container=self,
id=id,
) # **kw) removed due to CMF bug
new_instance = self[id]
if kw:
new_instance._edit(force_update=1, **kw)
return new_instance
security.declarePublic('getVisibleAllowedContentTypeList')
def getVisibleAllowedContentTypeList(self):
"""Users cannot add anything in an ERP5Site using standard interface.
......
......@@ -267,6 +267,18 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
self.assertEqual(b.isTempObject(), 1)
self.assertEqual(b.getId(), str(2))
# Test newContent with the temp_object parameter on the Portal
o = portal.newContent(portal_type="Person", temp_object=1)
o.setTitle('bar')
self.assertEqual(o.getTitle(), 'bar')
self.assertEqual(o.isTempObject(), 1)
a = o.newContent(id=1, portal_type="Telephone", temp_object=1)
self.assertEqual(str(a.getId()), str(1))
self.assertEqual(a.isTempObject(), 1)
b = o.newContent(id=2, portal_type="Telephone")
self.assertEqual(b.isTempObject(), 1)
self.assertEqual(b.getId(), str(2))
# Test newContent with the temp_object parameter and where a non-temp_object would not be allowed
o = portal.person_module.newContent(portal_type="Organisation", temp_object=1)
o.setTitle('bar')
......
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