[Zope-Checkins] CVS: Zope/lib/python/OFS - Application.py:1.180.18.1 ObjectManager.py:1.147.18.2

Casey Duncan c.duncan@nlada.org
Tue, 12 Mar 2002 12:45:19 -0500


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

Modified Files:
      Tag: casey-death_to_index_html-branch
	Application.py ObjectManager.py 
Log Message:
Implemented overrideable browser_default implementation in ObjectManager and
Application root. Added API to manipulate browser default method id in
ObjectManager.


=== Zope/lib/python/OFS/Application.py 1.180 => 1.180.18.1 ===
 
 import Globals,Folder,os,sys,App.Product, App.ProductRegistry, misc_
-import time, traceback, os,  Products
+import time, traceback, os,  Products, ObjectManager
 from DateTime import DateTime
 from AccessControl.User import UserFolder
 from App.ApplicationManager import ApplicationManager
@@ -58,6 +58,9 @@
     # to replace the top-level UserFolder object.
     
     __allow_groups__=UserFolder()
+
+    # Setup a default top level browser default for use throughout (casey)
+    browser_default = ObjectManager.BrowserDefault('index_html')
 
     def title_and_id(self): return self.title
     def title_or_id(self): return self.title


=== Zope/lib/python/OFS/ObjectManager.py 1.147.18.1 => 1.147.18.2 ===
 from webdav.Collection import Collection
 from Acquisition import aq_base
+from AccessControl.SecurityInfo import ClassSecurityInfo
 from urllib import quote
 from cStringIO import StringIO
 import marshal
@@ -88,7 +89,9 @@
        We also define this class as replaceable so that TTW scripts can
        override it
     """
-    __replaceable__ = REPLACEABLE # Allow this to be overridden
+    security = ClassSecurityInfo()
+
+    __replaceable__ = REPLACEABLE # Allow this to be overridden in instances
 
     def __init__(self, default_name):
         self._default_path = (default_name,)
@@ -97,6 +100,13 @@
         """Return the proper default method name to be published"""
         return self.aq_parent, self._default_path
 
+    security.declarePrivate('getDefaultId')
+    def getDefaultId(self):
+        """Return the browser default method id"""
+        return self._default_path[0]
+
+default__class_init__(BrowserDefault)
+
 class BeforeDeleteException( Exception ): pass # raise to veto deletion
 class BreakoutException ( Exception ): pass  # raised to break out of loops
 
@@ -127,6 +137,9 @@
          ('manage_importObject','manage_importExportForm',
           'manage_exportObject')
          ),
+        ('Manage folderish settings',
+         ('manage_settings', 'setBrowserDefaultId', 'getBrowserDefaultId')
+        ),
     )
 
 
@@ -142,8 +155,6 @@
     manage_options=(
         {'label':'Contents', 'action':'manage_main',
          'help':('OFSP','ObjectManager_Contents.stx')},
-#        {'label':'Import/Export', 'action':'manage_importExportForm',
-#         'help':('OFSP','ObjectManager_Import-Export.stx')},         
         )
 
     isAnObjectManager=1
@@ -213,7 +224,6 @@
                 self.aq_acquire('_getProductRegistryData')('ac_permissions')
                 )
 
-
     def filtered_meta_types(self, user=None):
         # Return a list of the types for which the user has
         # adequate permission to add that type of object.
@@ -656,6 +666,38 @@
                 return NullResource(self, key, request).__of__(self)
         raise KeyError, key
 
+    #######################################################################
+    # Death to index_html implementation (casey)
+
+    # By default, we explicitly acquire browser_default from the parent
+    # normally HTTPRequest.traverse does not acquire it
+    browser_default = Acquisition.Acquired
+
+    def setBrowserDefaultId(self, id='', acquire=0):
+        """Set the id of the browser_default method. If acquire is true
+           then the local browser_default is cleared and the setting is
+           acquired
+        """
+        if acquire:
+            if aq_base(self).browser_default is not Acquisition.Acquired:
+                del self.browser_default
+        else:
+            self._checkId(id, allow_dup=1)
+            self.browser_default = BrowserDefault(id)
+
+    def getBrowserDefaultId(self, acquire=0):
+        """Get the id of the browser_default method. If acquire is true
+           then the acquired value is returned if there is no local setting,
+           otherwise None is returned. None is also returned if
+           browser_default has been overidden in this (or a higher) instance
+           using a custom callable.
+        """
+        if (acquire
+            or aq_base(self).browser_default is not Acquisition.Acquired
+            and isinstance(aq_base(self.browser_default), BrowserDefault)):
+            return self.browser_default.getDefaultId()
+        else:
+            return None
 
 def findChilds(obj,dirname=''):
     """ recursive walk through the object hierarchy to