[Zope-Checkins] CVS: Zope/lib/python/OFS - ObjectManager.py:1.145.4.1

Casey Duncan casey_duncan@yahoo.com
Fri, 14 Dec 2001 00:11:45 -0500


Update of /cvs-repository/Zope/lib/python/OFS
In directory cvs.zope.org:/tmp/cvs-serv24685

Modified Files:
      Tag: casey-better_put_handling-branch
	ObjectManager.py 
Log Message:
Initial coding for "Death To Index_html"
Added API calls to allow default view to be changed
Added calls to allow "MKD" behavior to be modified
Added utility function for "setting" management screen for OM


=== Zope/lib/python/OFS/ObjectManager.py 1.145 => 1.145.4.1 ===
 __version__='$Revision$'[11:-2]
 
+import types
 import App.Management, Acquisition, Globals, CopySupport, Products
 import os, App.FactoryDispatcher, re, Products
 from OFS.Traversable import Traversable
@@ -104,7 +105,7 @@
     __ac_permissions__=(
         ('View management screens', ('manage_main','manage_menu')),
         ('Access contents information',
-         ('objectIds', 'objectValues', 'objectItems',''),
+         ('objectIds', 'objectValues', 'objectItems','getDefaultViewId'''),
          ('Anonymous', 'Manager'),
          ),
         ('Delete objects',     ('manage_delObjects',)),
@@ -112,7 +113,10 @@
         ('Import/Export objects',
          ('manage_importObject','manage_importExportForm',
           'manage_exportObject')
-         ),
+        ),
+        ('Manage Folderish Settings',
+         ('manage_settings', 'manage_editDefaultViewId')
+        ),
     )
 
 
@@ -128,6 +132,7 @@
     manage_options=(
         {'label':'Contents', 'action':'manage_main',
          'help':('OFSP','ObjectManager_Contents.stx')},
+        {'label':'Settings', 'action':'manage_settings'},
 #        {'label':'Import/Export', 'action':'manage_importExportForm',
 #         'help':('OFSP','ObjectManager_Import-Export.stx')},         
         )
@@ -200,6 +205,44 @@
                 meta_types.append(meta_type)
         return meta_types
 
+    def folderish_meta_types(self):
+        # Meta types for classes which inherit from ObjectManager
+
+        # We need to figure out which ZClasses inherit ObjectManager
+        # This is not so easy because the ZClass itself is not present
+        # in the _product_meta_types list and the information we need
+        # is in the ZClass object 8^/. (casey)
+        pmt=()
+        if hasattr(self, '_product_meta_types'): pmt=self._product_meta_types
+        elif hasattr(self, 'aq_acquire'):
+            try: pmt=self.aq_acquire('_product_meta_types')
+            except:  pass
+        OMs = []
+        # basically we rummage through each TTW product looking for the
+        # right ZClass, and see if it's an ObjectManager
+        for p in pmt:
+            product = self.Control_Panel.Products[p['product']]
+            meta_type = p['name']
+            for ob in product.objectValues():
+                print ob.getId()
+                if ob.meta_type == 'Z Class' \
+                   and ob._zclass_.meta_type == meta_type \
+                   and getattr(ob._zclass_, 'isAnObjectManager', 0):
+                    # We found the right ZClass and its an OM, so add it
+                    OMs.append(p)
+                    break
+
+        # Now look through the other products for ObjectManagers
+        all = self.all_meta_types
+        if callable(all):
+            all = all()
+        for p in all:
+            if p.has_key('instance') \
+               and getattr(p['instance'], 'isAnObjectManager', 0):
+                OMs.append(p)
+
+        return OMs
+
     _checkId = checkValidId
 
     def _setOb(self, id, object): setattr(self, id, object)
@@ -625,6 +668,89 @@
                 return NullResource(self, key, request).__of__(self)
         raise KeyError, key
 
+    # Death to index_html support (Casey)
+    # Allows user to override default view published by this OM
+
+    # By default, the default object name is acquired from the parent
+    # since this is a private attr, we must force acquisition
+    __default_view_name__ = Acquisition.Acquired
+
+    def getDefaultViewId(self, acquire=0):
+        """Returns the id of the default view object. If acquire is
+           set to false, then None is returned if the value is not set
+           at this level (acquired). Otherwise, the acquired value is
+           returned"""
+        if acquire or aq_base(self).__default_view_name__\
+                      is not Acquisition.Acquired:
+           return self.__default_view_name__
+        else:
+           return None
+
+    def manage_setDefaultViewId(self, id='', acquire=0):
+        """Set the id of the default view object for this ObjectManager
+           set acquire to acquire from parent"""
+        if not acquire:
+            self._checkId(id, allow_dup=1)
+            self.__default_view_name__ = id
+        else:
+            self.__default_view_name__ = Acquisition.Acquired
+
+    # Mkdir customization support (Casey)
+    # Allows user to select object type added by mkdir command
+
+    def getMkdirMetaType(self, acquire=0):
+        """Returns the object meta type created for the ObjectManager
+           by the mkdir command through FTP or WebDAV"""
+        if hasattr(aq_base(self), '_mkdir_meta_type'):
+            return self._mkdir_meta_type
+        elif acquire and hasattr(self, 'aq_acquire'):
+            return self.aq_acquire('_mkdir_meta_type')
+        else:
+            return None
+
+    def manage_setMkdirMetaType(self, meta_type='', acquire=0):
+        """Set the object meta type created by the mkdir command. This
+           should be a "folderish" object type. 
+           set acquire to acquire this setting"""
+        if not acquire:
+            all = self.all_meta_types
+            if callable(all):
+                all = all()
+            all = map(lambda x: x['name'], all) # Get available meta type names
+            if meta_type not in all:
+                raise BadRequestException, \
+                      ('Meta type "%s" is not valid or cannot '
+                       'be created in this object') % meta_type
+
+            self._mkdir_meta_type = meta_type
+        else:
+            if hasattr(aq_base(self), '_mkdir_meta_type'):
+                del self._mkdir_meta_type
+
+    def manage_mkdir(self, id, title='', REQUEST=None, RESPONSE=None):
+        """Add the appropriate folderish object in response to a mkdir
+           command"""
+        # Try to figure out the meta_type to use
+        if hasattr(self, 'aq_acquire'):
+            mkdir_type = self.aq_acquire('_mkdir_meta_type')
+        elif hasattr(aq_base(self), '_mkdir_meta_type'):
+            mkdir_type = self._mkdir_meta_type
+        else:
+            mkdir_type = 'Folder' # If we get here, something's weird
+ 
+        # Get the product and find the constructor for this meta_type
+        product = self.manage_addProduct[self._mkdir_meta_type]
+        all = self.all_meta_types
+        if callable(all):
+            all = all()
+        for meta_type in all:
+            if meta_type['name'] == mkdir_type:
+                # Get the name of the constructor
+                # this is kindof a hack, but it should work
+                constructor = meta_type['action'].split('/')[-1]
+                # now see if we can just call it...
+                
+                    
 
 def findChilds(obj,dirname=''):
     """ recursive walk through the object hierarchy to