[CMF-checkins] CVS: Products/CMFCore - TypesTool.py:1.83 __init__.py:1.30

Yvo Schubbe y.2004_ at wcm-solutions.de
Sun Nov 28 16:40:57 EST 2004


Update of /cvs-repository/Products/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv4222/CMFCore

Modified Files:
	TypesTool.py __init__.py 
Log Message:
- replaced hardcoded 'typeClasses' by an IFAwareObjectManager based solution


=== Products/CMFCore/TypesTool.py 1.82 => 1.83 ===
--- Products/CMFCore/TypesTool.py:1.82	Mon Nov 22 06:56:28 2004
+++ Products/CMFCore/TypesTool.py	Sun Nov 28 16:40:27 2004
@@ -25,6 +25,7 @@
 from Globals import DTMLFile
 from Globals import InitializeClass
 from OFS.Folder import Folder
+from OFS.ObjectManager import IFAwareObjectManager
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from zLOG import LOG, ERROR
 import Products
@@ -43,6 +44,7 @@
 from utils import _wwwdir
 from utils import cookString
 from utils import getActionContext
+from utils import getToolByName
 from utils import SimpleItemWithProperties
 from utils import UniqueObject
 
@@ -536,6 +538,15 @@
 
 InitializeClass( FactoryTypeInformation )
 
+def manage_addFactoryTIForm(self, REQUEST):
+    """ Get the add form for factory-based type infos.
+    """
+    addTIForm = DTMLFile('addTypeInfo', _dtmldir).__of__(self)
+    ttool = getToolByName(self, 'portal_types')
+    return addTIForm( self, REQUEST,
+                      add_meta_type=FactoryTypeInformation.meta_type,
+                      types=ttool.listDefaultTypeInformation() )
+
 
 class ScriptableTypeInformation( TypeInformation ):
     """
@@ -592,24 +603,20 @@
 
 InitializeClass( ScriptableTypeInformation )
 
+def manage_addScriptableTIForm(self, REQUEST):
+    """ Get the add form for scriptable type infos.
+    """
+    addTIForm = DTMLFile('addTypeInfo', _dtmldir).__of__(self)
+    ttool = getToolByName(self, 'portal_types')
+    return addTIForm( self, REQUEST,
+                      add_meta_type=ScriptableTypeInformation.meta_type,
+                      types=ttool.listDefaultTypeInformation() )
+
 
 # Provide aliases for backward compatibility.
 ContentFactoryMetadata = FactoryTypeInformation
 ContentTypeInformation = ScriptableTypeInformation
 
-
-typeClasses = [
-    {'class':FactoryTypeInformation,
-     'name':FactoryTypeInformation.meta_type,
-     'action':'manage_addFactoryTIForm',
-     'permission':ManagePortal},
-    {'class':ScriptableTypeInformation,
-     'name':ScriptableTypeInformation.meta_type,
-     'action':'manage_addScriptableTIForm',
-     'permission':ManagePortal},
-    ]
-
-
 allowedTypes = [
     'Script (Python)',
     'Python Method',
@@ -618,7 +625,8 @@
     ]
 
 
-class TypesTool(UniqueObject, Folder, ActionProviderBase):
+class TypesTool(UniqueObject, IFAwareObjectManager, Folder,
+                ActionProviderBase):
     """
         Provides a configurable registry of portal content types.
     """
@@ -627,6 +635,7 @@
 
     id = 'portal_types'
     meta_type = 'CMF Types Tool'
+    _product_interfaces = (ITypeInformation,)
 
     security = ClassSecurityInfo()
 
@@ -652,20 +661,12 @@
     #   ObjectManager methods
     #
     def all_meta_types(self):
-        """Adds TypesTool-specific meta types."""
+        # this is a workaround and should be removed again if allowedTypes
+        # have an interface we can use in _product_interfaces
         all = TypesTool.inheritedAttribute('all_meta_types')(self)
-        return tuple(typeClasses) + tuple(all)
-
-    def filtered_meta_types(self, user=None):
-        # Filters the list of available meta types.
-        allowed = {}
-        for tc in typeClasses:
-            allowed[tc['name']] = 1
-        for name in allowedTypes:
-            allowed[name] = 1
-
-        all = TypesTool.inheritedAttribute('filtered_meta_types')(self)
-        return tuple( [ mt for mt in all if mt['name'] in allowed ] )
+        others = [ mt for mt in Products.meta_types
+                   if mt['name'] in allowedTypes ]
+        return tuple(all) + tuple(others)
 
     #
     #   other methods
@@ -700,24 +701,6 @@
 
         return res
 
-    _addTIForm = DTMLFile( 'addTypeInfo', _dtmldir )
-
-    security.declareProtected(ManagePortal, 'manage_addFactoryTIForm')
-    def manage_addFactoryTIForm(self, REQUEST):
-        ' '
-        return self._addTIForm(
-            self, REQUEST,
-            add_meta_type=FactoryTypeInformation.meta_type,
-            types=self.listDefaultTypeInformation())
-
-    security.declareProtected(ManagePortal, 'manage_addScriptableTIForm')
-    def manage_addScriptableTIForm(self, REQUEST):
-        ' '
-        return self._addTIForm(
-            self, REQUEST,
-            add_meta_type=ScriptableTypeInformation.meta_type,
-            types=self.listDefaultTypeInformation())
-
     security.declareProtected(ManagePortal, 'manage_addTypeInformation')
     def manage_addTypeInformation(self, add_meta_type, id=None,
                                   typeinfo_name=None, RESPONSE=None):
@@ -737,9 +720,9 @@
                 id = fti.get('id', None)
         if not id:
             raise BadRequest('An id is required.')
-        for mt in typeClasses:
+        for mt in Products.meta_types:
             if mt['name'] == add_meta_type:
-                klass = mt['class']
+                klass = mt['instance']
                 break
         else:
             raise ValueError, (


=== Products/CMFCore/__init__.py 1.29 => 1.30 ===
--- Products/CMFCore/__init__.py:1.29	Tue Sep 14 15:02:21 2004
+++ Products/CMFCore/__init__.py	Sun Nov 28 16:40:27 2004
@@ -32,6 +32,7 @@
 import utils
 
 from permissions import AddPortalFolders
+from permissions import ManagePortal
 
 
 bases = (
@@ -99,6 +100,20 @@
         icon = 'images/registry.gif'
         )
 
+    context.registerClass(
+        TypesTool.FactoryTypeInformation,
+        permission=ManagePortal,
+        constructors=( TypesTool.manage_addFactoryTIForm, ),
+        icon='images/typeinfo.gif',
+        visibility=None)
+
+    context.registerClass(
+        TypesTool.ScriptableTypeInformation,
+        permission=ManagePortal,
+        constructors=( TypesTool.manage_addScriptableTIForm, ),
+        icon='images/typeinfo.gif',
+        visibility=None)
+
     utils.registerIcon(FSDTMLMethod.FSDTMLMethod,
                        'images/fsdtml.gif', globals())
     utils.registerIcon(FSPythonScript.FSPythonScript,
@@ -113,10 +128,6 @@
                        'images/fsprops.gif', globals())
     utils.registerIcon(FSZSQLMethod.FSZSQLMethod,
                        'images/fssqlmethod.gif', globals())
-    utils.registerIcon(TypesTool.FactoryTypeInformation,
-                       'images/typeinfo.gif', globals())
-    utils.registerIcon(TypesTool.ScriptableTypeInformation,
-                       'images/typeinfo.gif', globals())
 
     context.registerHelpTitle('CMF Core Help')
     context.registerHelp(directory='interfaces')



More information about the CMF-checkins mailing list