[CMF-checkins] SVN: CMF/trunk/CMF - added newstyle factories for
PortalFolder and CMFBTreeFolder
Yvo Schubbe
y.2006_ at wcm-solutions.de
Mon May 29 12:24:39 EDT 2006
Log message for revision 68353:
- added newstyle factories for PortalFolder and CMFBTreeFolder
- switched from ContentInit based to five:registerClass based meta_type registration
- removed hardcoded meta_type and portal_type attributes
Changed:
U CMF/trunk/CMFCore/CMFBTreeFolder.py
U CMF/trunk/CMFCore/PortalFolder.py
U CMF/trunk/CMFCore/PortalObject.py
U CMF/trunk/CMFCore/__init__.py
U CMF/trunk/CMFCore/configure.zcml
A CMF/trunk/CMFCore/content.zcml
U CMF/trunk/CMFCore/tests/test_PortalFolder.py
U CMF/trunk/CMFDefault/profiles/default/types/CMF_BTree_Folder.xml
U CMF/trunk/CMFDefault/profiles/default/types/Folder.xml
-=-
Modified: CMF/trunk/CMFCore/CMFBTreeFolder.py
===================================================================
--- CMF/trunk/CMFCore/CMFBTreeFolder.py 2006-05-29 15:55:43 UTC (rev 68352)
+++ CMF/trunk/CMFCore/CMFBTreeFolder.py 2006-05-29 16:24:38 UTC (rev 68353)
@@ -19,6 +19,7 @@
from AccessControl.SecurityInfo import ClassSecurityInfo
from Globals import InitializeClass
from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2Base
+from zope.component.factory import Factory
from PortalFolder import PortalFolderBase
@@ -40,7 +41,6 @@
"""BTree folder for CMF sites.
"""
- meta_type = 'CMF BTree Folder'
security = ClassSecurityInfo()
def __init__(self, id, title=''):
@@ -52,3 +52,5 @@
BTreeFolder2Base._checkId(self, id, allow_dup)
InitializeClass(CMFBTreeFolder)
+
+CMFBTreeFolderFactory = Factory(CMFBTreeFolder)
Modified: CMF/trunk/CMFCore/PortalFolder.py
===================================================================
--- CMF/trunk/CMFCore/PortalFolder.py 2006-05-29 15:55:43 UTC (rev 68352)
+++ CMF/trunk/CMFCore/PortalFolder.py 2006-05-29 16:24:38 UTC (rev 68353)
@@ -25,6 +25,7 @@
from Globals import InitializeClass
from OFS.OrderSupport import OrderSupport
from OFS.Folder import Folder
+from zope.component.factory import Factory
from zope.interface import implements
from CMFCatalogAware import CMFCatalogAware
@@ -51,8 +52,6 @@
"""Base class for portal folder.
"""
- meta_type = 'Portal Folder Base'
-
implements(IFolderish, IMutableMinimalDublinCore)
__implements__ = (z2IFolderish, DynamicType.__implements__,
Folder.__implements__)
@@ -64,9 +63,10 @@
manage_options = ( Folder.manage_options +
CMFCatalogAware.manage_options )
- def __init__( self, id, title='' ):
+ def __init__(self, id, title='', description=''):
self.id = id
self.title = title
+ self.description = description
#
# 'IMutableMinimalDublinCore' interface methods
@@ -464,8 +464,6 @@
"""Implements portal content management, but not UI details.
"""
- meta_type = 'Portal Folder'
- portal_type = 'Folder'
__implements__ = (PortalFolderBase.__implements__,
OrderSupport.__implements__)
@@ -487,6 +485,8 @@
InitializeClass(PortalFolder)
+PortalFolderFactory = Factory(PortalFolder)
+
manage_addPortalFolder = PortalFolder.manage_addPortalFolder.im_func
Modified: CMF/trunk/CMFCore/PortalObject.py
===================================================================
--- CMF/trunk/CMFCore/PortalObject.py 2006-05-29 15:55:43 UTC (rev 68352)
+++ CMF/trunk/CMFCore/PortalObject.py 2006-05-29 16:24:38 UTC (rev 68353)
@@ -35,6 +35,7 @@
implements(ISiteRoot)
meta_type = 'Portal Site'
+ portal_type = 'Folder'
_isPortalRoot = 1
# Ensure certain attributes come from the correct base class.
Modified: CMF/trunk/CMFCore/__init__.py
===================================================================
--- CMF/trunk/CMFCore/__init__.py 2006-05-29 15:55:43 UTC (rev 68352)
+++ CMF/trunk/CMFCore/__init__.py 2006-05-29 16:24:38 UTC (rev 68353)
@@ -65,15 +65,10 @@
cmfcore_globals=globals()
-_CONTENT_TYPES = ( PortalFolder.PortalFolder
- , CMFBTreeFolder.CMFBTreeFolder
- )
+# BBB: oldstyle constructors
+_EXTRA_CONSTRUCTORS = (PortalFolder.manage_addPortalFolder,
+ CMFBTreeFolder.manage_addCMFBTreeFolder)
-_EXTRA_CONSTRUCTORS = ( PortalFolder.manage_addPortalFolder
- , CMFBTreeFolder.manage_addCMFBTreeFolder
- )
-
-
# Because persistent objects may be out there which were
# created when the module was in that product, we need
# __module_aliases__ .
@@ -145,8 +140,9 @@
, icon='tool.gif'
).initialize( context )
+ # BBB: register oldstyle constructors
utils.ContentInit( 'CMF Core Content'
- , content_types=_CONTENT_TYPES
+ , content_types=()
, permission=AddPortalFolders
, extra_constructors=_EXTRA_CONSTRUCTORS
).initialize( context )
Modified: CMF/trunk/CMFCore/configure.zcml
===================================================================
--- CMF/trunk/CMFCore/configure.zcml 2006-05-29 15:55:43 UTC (rev 68352)
+++ CMF/trunk/CMFCore/configure.zcml 2006-05-29 16:24:38 UTC (rev 68353)
@@ -7,6 +7,8 @@
<include package=".exportimport"/>
+ <include file="content.zcml"/>
+
<include file="event.zcml"/>
<five:registerClass
Added: CMF/trunk/CMFCore/content.zcml
===================================================================
--- CMF/trunk/CMFCore/content.zcml 2006-05-29 15:55:43 UTC (rev 68352)
+++ CMF/trunk/CMFCore/content.zcml 2006-05-29 16:24:38 UTC (rev 68353)
@@ -0,0 +1,27 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:five="http://namespaces.zope.org/five">
+
+ <five:registerClass
+ class=".PortalFolder.PortalFolder"
+ meta_type="Portal Folder"
+ permission="cmf.AddPortalFolders"
+ />
+
+ <factory
+ component=".PortalFolder.PortalFolderFactory"
+ id="cmf.folder"
+ />
+
+ <five:registerClass
+ class=".CMFBTreeFolder.CMFBTreeFolder"
+ meta_type="CMF BTree Folder"
+ permission="cmf.AddPortalFolders"
+ />
+
+ <factory
+ component=".CMFBTreeFolder.CMFBTreeFolderFactory"
+ id="cmf.folder.btree"
+ />
+
+</configure>
Property changes on: CMF/trunk/CMFCore/content.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: CMF/trunk/CMFCore/tests/test_PortalFolder.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_PortalFolder.py 2006-05-29 15:55:43 UTC (rev 68352)
+++ CMF/trunk/CMFCore/tests/test_PortalFolder.py 2006-05-29 16:24:38 UTC (rev 68353)
@@ -31,7 +31,10 @@
from OFS.Application import Application
from OFS.Image import manage_addFile
from OFS.tests.testCopySupport import makeConnection
+from Products.Five import zcml
from Testing.makerequest import makerequest
+from zope.component import getGlobalSiteManager
+from zope.component.interfaces import IFactory
from zope.testing.cleanup import cleanUp
from Products.CMFCore.CatalogTool import CatalogTool
@@ -58,38 +61,42 @@
class PortalFolderFactoryTests(SecurityTest):
+ _PORTAL_TYPE = 'Test Folder'
+
+ def _getTargetObject(self):
+ from Products.CMFCore.PortalFolder import PortalFolderFactory
+
+ return PortalFolderFactory
+
def setUp(self):
from Products.CMFCore.PortalFolder import PortalFolder
SecurityTest.setUp(self)
setUpEvents()
+ gsm = getGlobalSiteManager()
+ gsm.provideUtility(IFactory, self._getTargetObject(), 'cmf.folder')
+ self.site = DummySite('site').__of__(self.root)
+ acl_users = self.site._setObject('acl_users', DummyUserFolder())
+ newSecurityManager(None, acl_users.all_powerful_Oz)
- self.root._setObject( 'portal_types', TypesTool() )
- types_tool = self.root.portal_types
- types_tool._setObject( 'Folder'
- , FTI( id='Folder'
- , title='Folder or Directory'
- , meta_type=PortalFolder.meta_type
- , product='CMFCore'
- , factory='manage_addPortalFolder'
- , filter_content_types=0
- )
- )
- fti = FTIDATA_DUMMY[0].copy()
- types_tool._setObject( 'Dummy Content', FTI(**fti) )
+ ttool = self.site._setObject('portal_types', TypesTool())
+ ttool._setObject(self._PORTAL_TYPE,
+ FTI(id=self._PORTAL_TYPE,
+ title='Folder or Directory',
+ meta_type=PortalFolder.meta_type,
+ factory='cmf.folder',
+ filter_content_types=0))
+ ttool._setObject('Dummy Content', FTI(**FTIDATA_DUMMY[0].copy()))
+ self.f = self.site._setObject('container', PortalFolder('container'))
+ self.f._setPortalTypeName(self._PORTAL_TYPE)
+
def tearDown(self):
SecurityTest.tearDown(self)
cleanUp()
- def _makeOne( self, id ):
- from Products.CMFCore.PortalFolder import PortalFolder
- return PortalFolder( id ).__of__( self.root )
-
- def test_invokeFactory( self ):
-
- f = self._makeOne( 'container' )
-
+ def test_invokeFactory(self):
+ f = self.f
self.failIf( 'foo' in f.objectIds() )
f.manage_addProduct = {'FooProduct': DummyFactoryDispatcher(f)}
@@ -101,25 +108,19 @@
self.assertEqual( foo.getPortalTypeName(), 'Dummy Content' )
self.assertEqual( foo.Type(), 'Dummy Content Title' )
- def test_invokeFactory_disallowed_type( self ):
-
- f = self._makeOne( 'container' )
-
- ftype = self.root.portal_types.Folder
+ def test_invokeFactory_disallowed_type(self):
+ f = self.f
+ ftype = getattr(self.site.portal_types, self._PORTAL_TYPE)
ftype.filter_content_types = 1
+ self.assertRaises(ValueError,
+ f.invokeFactory, self._PORTAL_TYPE, 'sub')
- self.assertRaises( ValueError
- , f.invokeFactory, type_name='Folder', id='sub' )
+ ftype.allowed_content_types = (self._PORTAL_TYPE,)
+ f.invokeFactory(self._PORTAL_TYPE, id='sub')
+ self.failUnless('sub' in f.objectIds())
+ self.assertRaises(ValueError, f.invokeFactory, 'Dummy Content', 'foo')
- ftype.allowed_content_types = ( 'Folder', )
- f.invokeFactory( type_name='Folder', id='sub' )
- self.failUnless( 'sub' in f.objectIds() )
- self.assertRaises( ValueError
- , f.invokeFactory
- , type_name='Dummy Content', id='foo' )
-
-
class PortalFolderTests(ConformsToFolder, SecurityTest):
def _getTargetClass(self):
@@ -132,8 +133,15 @@
self._getTargetClass()(id, *args, **kw))
def setUp(self):
+ import Products
+ from Products.CMFCore.PortalFolder import PortalFolderFactory
+
SecurityTest.setUp(self)
setUpEvents()
+ zcml.load_config('permissions.zcml', Products.Five)
+ zcml.load_config('content.zcml', Products.CMFCore)
+ gsm = getGlobalSiteManager()
+ gsm.provideUtility(IFactory, PortalFolderFactory, 'cmf.folder')
self.site = DummySite('site').__of__(self.root)
def tearDown(self):
@@ -290,14 +298,14 @@
from Products.CMFCore.PortalFolder import PortalFolder
test = self._makeOne('test')
+ test._setPortalTypeName('Folder')
ttool = self.site._setObject( 'portal_types', TypesTool() )
ttool._setObject( 'Folder'
, FTI( id='Folder'
, title='Folder or Directory'
, meta_type=PortalFolder.meta_type
- , product='CMFCore'
- , factory='manage_addPortalFolder'
+ , factory='cmf.folder'
, filter_content_types=0
)
)
@@ -305,8 +313,7 @@
, FTI( 'Grabbed'
, title='Grabbed Content'
, meta_type=PortalFolder.meta_type
- , product='CMFCore'
- , factory='manage_addPortalFolder'
+ , factory='cmf.folder'
)
)
@@ -349,8 +356,10 @@
ttool._setObject( 'Dummy Content', FTI(**fti) )
ttool._setObject( 'Folder', FTI(**fti) )
sub1 = self._makeOne('sub1')
+ sub1._setPortalTypeName('Folder')
sub1._setObject( 'dummy', DummyContent( 'dummy' ) )
sub2 = self._makeOne('sub2')
+ sub2._setPortalTypeName('Folder')
sub2.all_meta_types = extra_meta_types()
# Allow adding of Dummy Content
@@ -864,12 +873,17 @@
_old_policy = None
def setUp( self ):
+ import Products
+
self._scrubSecurity()
+ zcml.load_config('meta.zcml', Products.Five)
+ zcml.load_config('permissions.zcml', Products.Five)
+ zcml.load_config('content.zcml', Products.CMFCore)
def tearDown( self ):
-
self._scrubSecurity()
self._cleanApp()
+ cleanUp()
def _initFolders( self ):
from Products.CMFCore.PortalFolder import PortalFolder
@@ -886,6 +900,8 @@
self.app._setObject( 'folder2', PortalFolder( 'folder2' ) )
folder1 = getattr( self.app, 'folder1' )
folder2 = getattr( self.app, 'folder2' )
+ folder1._setPortalTypeName('Folder')
+ folder2._setPortalTypeName('Folder')
manage_addFile( folder1, 'file'
, file='', content_type='text/plain')
@@ -1105,7 +1121,6 @@
#
from AccessControl.Permissions import delete_objects as DeleteObjects
from Products.CMFCore.PortalFolder import PortalFolder
- from Products.CMFCore.permissions import AddPortalFolders
folder1, folder2 = self._initFolders()
folder1.manage_permission( DeleteObjects, roles=(), acquire=0 )
@@ -1113,14 +1128,6 @@
folder1._setObject( 'sub', PortalFolder( 'sub' ) )
transaction.savepoint(optimistic=True) # get a _p_jar for 'sub'
- FOLDER_CTOR = 'manage_addProducts/CMFCore/manage_addPortalFolder'
- folder2.all_meta_types = ( { 'name' : 'CMF Core Content'
- , 'action' : FOLDER_CTOR
- , 'permission' : AddPortalFolders
- }
- ,
- )
-
self.app.portal_types = DummyTypesTool()
def _no_delete_objects(permission, object, context):
Modified: CMF/trunk/CMFDefault/profiles/default/types/CMF_BTree_Folder.xml
===================================================================
--- CMF/trunk/CMFDefault/profiles/default/types/CMF_BTree_Folder.xml 2006-05-29 15:55:43 UTC (rev 68352)
+++ CMF/trunk/CMFDefault/profiles/default/types/CMF_BTree_Folder.xml 2006-05-29 16:24:38 UTC (rev 68353)
@@ -6,8 +6,8 @@
i18n:translate="">Folder for holding very large numbers of items.</property>
<property name="content_icon">folder_icon.gif</property>
<property name="content_meta_type">CMF BTree Folder</property>
- <property name="product">CMFCore</property>
- <property name="factory">manage_addCMFBTreeFolder</property>
+ <property name="product"></property>
+ <property name="factory">cmf.folder.btree</property>
<property name="immediate_view">folder_edit_form</property>
<property name="global_allow">True</property>
<property name="filter_content_types">False</property>
Modified: CMF/trunk/CMFDefault/profiles/default/types/Folder.xml
===================================================================
--- CMF/trunk/CMFDefault/profiles/default/types/Folder.xml 2006-05-29 15:55:43 UTC (rev 68352)
+++ CMF/trunk/CMFDefault/profiles/default/types/Folder.xml 2006-05-29 16:24:38 UTC (rev 68353)
@@ -6,8 +6,8 @@
i18n:translate="">Use folders to put content in categories.</property>
<property name="content_icon">folder_icon.gif</property>
<property name="content_meta_type">Portal Folder</property>
- <property name="product">CMFCore</property>
- <property name="factory">manage_addPortalFolder</property>
+ <property name="product"></property>
+ <property name="factory">cmf.folder</property>
<property name="immediate_view">folder_edit_form</property>
<property name="global_allow">True</property>
<property name="filter_content_types">False</property>
More information about the CMF-checkins
mailing list