[CMF-checkins] CVS: CMF/CMFCore - TypesTool.py:1.26.12.1

Jeffrey P Shell jeffrey@zope.com
Fri, 28 Dec 2001 16:22:26 -0500


Update of /cvs-repository/CMF/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv25543

Modified Files:
      Tag: jshell-tracker_409-branch
	TypesTool.py 
Log Message:
Checking in changes for Tracker issue #409, dealing with the ability
to register and add in new Type Information components to the types
tool in a manner similar to the ability to register new Workflow
Agents to the workflow tool.


=== CMF/CMFCore/TypesTool.py 1.26 => 1.26.12.1 ===
 from utils import UniqueObject, SimpleItemWithProperties, tuplize
 from utils import _dtmldir, _checkPermission, cookString
+import urllib
 import string
 from AccessControl import getSecurityManager, ClassSecurityInfo
 from Acquisition import aq_base
@@ -30,6 +31,22 @@
 
 _marker = []  # Create a new marker.
 
+
+_type_factories = {}
+allowedTypes = ( 'Script (Python)'
+               , 'Python Method'
+               , 'DTML Method'
+               , 'External Method'
+               )
+
+def addTypeFactory(factory, id=None):
+    # modeled after WorkflowTool.addWorkflowFactory()
+    global allowedTypes
+    if id is None:
+        id = getattr(factory, 'id', '') or getattr(factory, 'meta_type', '')
+    _type_factories[id] = factory
+    allowedTypes = allowedTypes + (factory.meta_type,)
+
 class TypeInformation (SimpleItemWithProperties):
     """
     Base class for information about a content type.
@@ -431,7 +448,7 @@
         return ob
 
 InitializeClass( FactoryTypeInformation )
-
+addTypeFactory(FactoryTypeInformation)
 
 class ScriptableTypeInformation( TypeInformation ):
     """
@@ -486,20 +503,13 @@
         return ob
 
 InitializeClass( ScriptableTypeInformation )
-
+addTypeFactory(ScriptableTypeInformation)
 
 # Provide aliases for backward compatibility.
 ContentFactoryMetadata = FactoryTypeInformation
 ContentTypeInformation = ScriptableTypeInformation
 
 
-allowedTypes = ( 'Script (Python)'
-               , 'Python Method'
-               , 'DTML Method'
-               , 'External Method'
-               , FactoryTypeInformation.meta_type
-               , ScriptableTypeInformation.meta_type
-               )
 
 class TypesTool( UniqueObject, OFS.Folder.Folder ):
     """
@@ -523,14 +533,17 @@
 
     def all_meta_types(self):
         all = TypesTool.inheritedAttribute('all_meta_types')(self)
-        return (
-            {'name':FactoryTypeInformation.meta_type,
-             'action':'manage_addFactoryTIForm',
-             'permission':'Manage portal'},
-            {'name':ScriptableTypeInformation.meta_type,
-             'action':'manage_addScriptableTIForm',
-             'permission':'Manage portal'},
-            ) + tuple(all)
+        factypes = []
+        add_fac = factypes.append
+        for name, fac in _type_factories.items():
+            query = urllib.urlencode({'type_type': name})
+            factypes.append({
+                'name': fac.meta_type,
+                'action': 'manage_addTypeInfoForm?%s' % query,
+                'permission': CMFCorePermissions.ManagePortal,
+                })
+        factypes.extend(all)
+        return factypes
 
     def filtered_meta_types(self, user=None):
         # Filters the list of available meta types.
@@ -565,24 +578,17 @@
 
     _addTIForm = DTMLFile( 'addTypeInfo', _dtmldir )
 
-    security.declareProtected(ManagePortal, 'manage_addFactoryTIForm')
-    def manage_addFactoryTIForm(self, REQUEST):
-        ' '
-        return self._addTIForm(self, REQUEST, scriptable='',
-                               types=self.listDefaultTypeInformation())
-
-    security.declareProtected(ManagePortal, 'manage_addScriptableTIForm')
-    def manage_addScriptableTIForm(self, REQUEST):
-        ' '
-        return self._addTIForm(self, REQUEST, scriptable='1',
+    security.declareProtected(ManagePortal, 'manage_addTypeInfoForm')
+    def manage_addTypeInfoForm(self, REQUEST={}, type_type=''):
+        """ Return the type info form while keeping the list of
+        prefab type information up to date """
+        return self._addTIForm(self, REQUEST, type_type=type_type,
                                types=self.listDefaultTypeInformation())
 
     security.declareProtected(ManagePortal, 'manage_addTypeInformation')
-    def manage_addTypeInformation(self, id=None, scriptable='',
+    def manage_addTypeInformation(self, id=None, type_type=None,
                                   typeinfo_name=None, RESPONSE=None):
-        """
-        Create a TypeInformation in self.
-        """
+        """ Create a TypeInformation in self. """
         fti = None
         if typeinfo_name:
             info = self.listDefaultTypeInformation()
@@ -596,8 +602,9 @@
                 id = fti.get('id', None)
         if not id:
             raise 'Bad Request', 'An id is required.'
-        if scriptable:
-            klass = ScriptableTypeInformation
+
+        if type_type in _type_factories.keys():
+            klass = _type_factories[type_type]
         else:
             klass = FactoryTypeInformation
         id = str(id)