[CMF-checkins] CVS: CMF/CMFCore - TypesTool.py:1.26.2.2
Tres Seaver
tseaver@zope.com
Fri, 4 Jan 2002 15:26:02 -0500
Update of /cvs-repository/CMF/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv19603/CMFCore
Modified Files:
Tag: CMF-1_2-branch
TypesTool.py
Log Message:
- Extended TypesTool to permit registration of new TypeInformation
implementations (Tracker #409, thanks to Jeffrey Shell for the
work!)
=== CMF/CMFCore/TypesTool.py 1.26.2.1 => 1.26.2.2 ===
from utils import _dtmldir, _checkPermission, cookString
import string
+import urllib
from AccessControl import getSecurityManager, ClassSecurityInfo
try:
from AccessControl import Unauthorized
@@ -34,6 +35,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.
@@ -435,7 +452,7 @@
return ob
InitializeClass( FactoryTypeInformation )
-
+addTypeFactory(FactoryTypeInformation)
class ScriptableTypeInformation( TypeInformation ):
"""
@@ -490,20 +507,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 ):
"""
@@ -527,14 +537,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.
@@ -569,24 +582,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()
@@ -600,8 +606,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)