diff --git a/product/ERP5Type/Core/Folder.py b/product/ERP5Type/Core/Folder.py index 1257b1890b93f61ce73f2ab2841e22767042d9af..5594f1471efabd2f696ec75a87ea67515a79af2c 100644 --- a/product/ERP5Type/Core/Folder.py +++ b/product/ERP5Type/Core/Folder.py @@ -162,42 +162,6 @@ class FolderMixIn(ExtensionClass.Base): security = ClassSecurityInfo() security.declareObjectProtected(Permissions.AccessContentsInformation) - security.declarePublic('allowedContentTypes') - def allowedContentTypes(self): - """ - List portal_types which can be added in this folder / object. - """ - portal_types = self.getPortalObject().portal_types - myType = portal_types.getTypeInfo(self) - if myType is not None: - if myType.filter_content_types: - # Iterate over allowed content types to avoid going over all portal - # types and retaining only a fraction. - result = [] - for portal_type in myType.getTypeAllowedContentTypeList(): - contentType = portal_types.getTypeInfo(portal_type) - if contentType is None: - raise AttributeError( - "Portal type '%s' does not exist and should not be allowed in '%s'" % ( - portal_type, - self.getPortalType(), - ), - ) - result.append(contentType) - else: - result = [ - contentType - for contentType in portal_types.listTypeInfo(self) - if myType.allowType(contentType.getId()) - ] - else: - result = portal_types.listTypeInfo() - return [ - x - for x in result - if x.isConstructionAllowed(self) - ] - security.declarePublic('newContent') def newContent(self, id=None, portal_type=None, id_group=None, default=None, method=None, container=None, temp_object=0, **kw): diff --git a/product/ERP5Type/ZopePatch.py b/product/ERP5Type/ZopePatch.py index e939461dd5d28620725170833fe321e2f33bb834..cf2e5e2b7b8b37d177cf58a42d01913fc55edab0 100644 --- a/product/ERP5Type/ZopePatch.py +++ b/product/ERP5Type/ZopePatch.py @@ -51,6 +51,7 @@ from Products.ERP5Type.patches import CookieCrumbler from Products.ERP5Type.patches import PropertySheets from Products.ERP5Type.patches import CMFCoreSkinnable from Products.ERP5Type.patches import CMFCoreSkinsTool +from Products.ERP5Type.patches import CMFBTreeFolder from Products.ERP5Type.patches import OFSFile from Products.ERP5Type.patches import OFSFolder from Products.ERP5Type.patches import OFSUninstalled diff --git a/product/ERP5Type/patches/CMFBTreeFolder.py b/product/ERP5Type/patches/CMFBTreeFolder.py new file mode 100644 index 0000000000000000000000000000000000000000..6162af7af66627bc42f8fdbd9c0767fa0a310708 --- /dev/null +++ b/product/ERP5Type/patches/CMFBTreeFolder.py @@ -0,0 +1,58 @@ +############################################################################## +# +# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved. +# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## + +#from Products.CMFCore.PortalFolder import PortalFolder +try: + from Products.CMFCore.CMFBTreeFolder import CMFBTreeFolder +except ImportError: + from Products.BTreeFolder2.CMFBTreeFolder import CMFBTreeFolder + +""" + This patch tries to give only portal types that are defined + in the allowed content types field. This will make the + speed of allowed content type in almost O(1) instead of O(n), + where n is the number of portal types in types tool. +""" + +def CMFBTreeFolder_allowedContentTypes(self): + """ + List type info objects for types which can be added in + this folder. + """ + result = [] + portal_types = self.getPortalObject().portal_types + myType = portal_types.getTypeInfo(self) + + if myType is not None: + allowed_types_to_check = [] + if myType.filter_content_types: + for portal_type in myType.getTypeAllowedContentTypeList(): + contentType = portal_types.getTypeInfo(portal_type) + if contentType is None: + raise AttributeError, "Portal type '%s' does not exist " \ + "and should not be allowed in '%s'" % \ + (portal_type, self.getPortalType()) + result.append(contentType) + else: + for contentType in portal_types.listTypeInfo(self): + if myType.allowType(contentType.getId()): + result.append(contentType) + else: + result = portal_types.listTypeInfo() + + return filter( + lambda typ, container=self: typ.isConstructionAllowed(container), + result) + +CMFBTreeFolder.allowedContentTypes = CMFBTreeFolder_allowedContentTypes