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

Tres Seaver tseaver@zope.com
Wed, 9 Jan 2002 17:28:43 -0500


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

Modified Files:
      Tag: CMF-1_2-branch
	TypesTool.py 
Log Message:


  - Backing out Jeffrey's feature, as it breaks the add list for
    the types tool (Tracker #409 won't land for CMF 1.2 b2).


=== CMF/CMFCore/TypesTool.py 1.26.2.3 => 1.26.2.4 ===
 from utils import _dtmldir, _checkPermission, cookString, getToolByName
 import string
-import urllib
 from AccessControl import getSecurityManager, ClassSecurityInfo
 try:
     from AccessControl import Unauthorized
@@ -35,22 +34,6 @@
 
 _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.
@@ -454,7 +437,7 @@
         return ob
 
 InitializeClass( FactoryTypeInformation )
-addTypeFactory(FactoryTypeInformation)
+
 
 class ScriptableTypeInformation( TypeInformation ):
     """
@@ -509,13 +492,20 @@
         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 ):
     """
@@ -539,17 +529,14 @@
 
     def all_meta_types(self):
         all = TypesTool.inheritedAttribute('all_meta_types')(self)
-        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
+        return (
+            {'name':FactoryTypeInformation.meta_type,
+             'action':'manage_addFactoryTIForm',
+             'permission':'Manage portal'},
+            {'name':ScriptableTypeInformation.meta_type,
+             'action':'manage_addScriptableTIForm',
+             'permission':'Manage portal'},
+            ) + tuple(all)
 
     def filtered_meta_types(self, user=None):
         # Filters the list of available meta types.
@@ -584,17 +571,24 @@
 
     _addTIForm = DTMLFile( 'addTypeInfo', _dtmldir )
 
-    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,
+    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',
                                types=self.listDefaultTypeInformation())
 
     security.declareProtected(ManagePortal, 'manage_addTypeInformation')
-    def manage_addTypeInformation(self, id=None, type_type=None,
+    def manage_addTypeInformation(self, id=None, scriptable='',
                                   typeinfo_name=None, RESPONSE=None):
-        """ Create a TypeInformation in self. """
+        """
+        Create a TypeInformation in self.
+        """
         fti = None
         if typeinfo_name:
             info = self.listDefaultTypeInformation()
@@ -608,9 +602,8 @@
                 id = fti.get('id', None)
         if not id:
             raise 'Bad Request', 'An id is required.'
-
-        if type_type in _type_factories.keys():
-            klass = _type_factories[type_type]
+        if scriptable:
+            klass = ScriptableTypeInformation
         else:
             klass = FactoryTypeInformation
         id = str(id)