[CMF-checkins] CVS: CMF - PortalFolder.py:1.14 TypesTool.py:1.13

tseaver@digicool.com tseaver@digicool.com
Sat, 26 May 2001 12:35:31 -0400 (EDT)


Update of /cvs-repository/CMF/CMFCore
In directory korak.digicool.com:/tmp/cvs-serv26488/CMFCore

Modified Files:
	PortalFolder.py TypesTool.py 
Log Message:


 - Remove ugly '_mimetype_registry' hack for 'PUT_factory'.

 - Make 'PUT_factory' use new 'content_type_registry' tool.

 - Make 'PUT_factory' use 'invokeFactory', so that objects created
   via PUT have their 'portal_type' set properly.



--- Updated File PortalFolder.py in package CMF --
--- PortalFolder.py	2001/05/24 20:39:39	1.13
+++ PortalFolder.py	2001/05/26 16:35:30	1.14
@@ -131,23 +131,7 @@
                            ,
                            )
 
-#
-#   HACK! HACK! HACK! HACK! HACK! HACK! HACK! HACK! HACK!
-#
-#   This registry needs to go away, and be replaced by a web-configurable,
-#   instance-specific 'portal_types' tool.
-#
-_mime_type_registry = {}
 
-def addPortalTypeHandler( MIMEType, klass ):
-    """
-        Set up a mapping from 'MIMEType' to 'klass', so that
-        PortalFolder.PUT_factory knows what to make.  'klass' should be
-        either an actual class object, whose __init__() takes no paramters
-        (except 'self'), or a function taking no paramters.
-    """
-    _mime_type_registry[ MIMEType ] = klass
-
 class PortalFolder( Folder, DynamicType ):
     """
         Implements portal content management, but not UI details.
@@ -361,20 +345,37 @@
             an object of the appropriate type (or None, if we don't
             know what to do).
         """
-        klass = _mime_type_registry.get( typ, None )
-        if klass is None:
+        registry = getToolByName( self, 'content_type_registry' )
+        if registry is None:
             return None
-        obj = klass(id=name)
+
+        typeObjectName = registry.findTypeName( name, typ, body )
+        if typeObjectName is None:
+            return None
+        
+        self.invokeFactory( typeObjectName, name )
+
+        # XXX: this is butt-ugly.
+        obj = aq_base( self._getOb( name ) )
+        self._delObject( name )
         return obj
 
     security.declareProtected(AddPortalContent, 'invokeFactory')
-    def invokeFactory(self, type_name, id, RESPONSE=None, *args, **kw):
+    def invokeFactory( self
+                     , type_name
+                     , id
+                     , RESPONSE=None
+                     , *args
+                     , **kw
+                     ):
         '''
         Invokes the portal_types tool.
         '''
-        pt = getToolByName(self, 'portal_types')
-        apply(pt.constructContent, (type_name, self, id, RESPONSE) + args,
-              kw)
+        pt = getToolByName( self, 'portal_types' )
+        apply( pt.constructContent
+             , (type_name, self, id, RESPONSE) + args
+             , kw
+             )
 
     def _checkId(self, id, allow_dup=0):
         PortalFolder.inheritedAttribute('_checkId')(self, id, allow_dup)

--- Updated File TypesTool.py in package CMF --
--- TypesTool.py	2001/05/11 03:38:28	1.12
+++ TypesTool.py	2001/05/26 16:35:30	1.13
@@ -531,6 +531,7 @@
         ob = apply(constructor, (container, id) + args, kw)
         if hasattr(ob, '_setPortalTypeName'):
             ob._setPortalTypeName(self.getId())
+
         return '%s/%s' % ( ob.absolute_url(), self.immediate_view )
 
 InitializeClass( ScriptableTypeInformation )
@@ -712,8 +713,14 @@
 
     
     security.declarePublic('constructContent')
-    def constructContent( self, type_name, container, id,
-                          RESPONSE=None, *args, **kw ):
+    def constructContent( self
+                        , type_name
+                        , container
+                        , id
+                        , RESPONSE=None
+                        , *args
+                        , **kw
+                        ):
         """
             Build an instance of the appropriate content class in
             'container', using 'id'.
@@ -723,7 +730,7 @@
             raise 'ValueError', 'No such content type: %s' % type_name
         
         immediate_url = apply(info.constructInstance,
-                              (container, id) + args, kw)
+                            (container, id) + args, kw)
 
         if RESPONSE is not None:
             RESPONSE.redirect( immediate_url )