[Zope-Checkins] CVS: Zope/lib/python/OFS - Application.py:1.180.18.3 Folder.py:1.97.34.2 ObjectManager.py:1.147.18.5
Casey Duncan
casey@zope.com
Wed, 27 Mar 2002 15:26:23 -0500
Update of /cvs-repository/Zope/lib/python/OFS
In directory cvs.zope.org:/tmp/cvs-serv13008/OFS
Modified Files:
Tag: casey-death_to_index_html-branch
Application.py Folder.py ObjectManager.py
Log Message:
Refactored death to index_html implementation to handle the root app object,
and for better bw compatibility with products subclassing
ObjectManager/Folder and legacy Folder instances. Previous implementation was
a bit overzealous by default.
=== Zope/lib/python/OFS/Application.py 1.180.18.2 => 1.180.18.3 ===
__allow_groups__=UserFolder()
- # Setup a default top level browser default for use throughout (casey)
- browser_default = ObjectManager.BrowserDefault('index_html')
+ # Set the universal default method to index_html
+ _object_manager_browser_default_id = 'index_html'
def title_and_id(self): return self.title
def title_or_id(self): return self.title
=== Zope/lib/python/OFS/Folder.py 1.97.34.1 => 1.97.34.2 ===
self._setObject(id, ob)
ob=self._getOb(id)
+
+ # Acquire browser_default from parent
+ ob.setBrowserDefaultId(acquire=1)
checkPermission=getSecurityManager().checkPermission
@@ -61,7 +64,7 @@
'You are not authorized to add Page Templates.'
)
ob.manage_addProduct['PageTemplates'].manage_addPageTemplate(
- id='index_html', title='')
+ id=ob.getBrowserDefaultId(acquire=1), title='')
if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=1)
=== Zope/lib/python/OFS/ObjectManager.py 1.147.18.4 => 1.147.18.5 ===
import os, App.FactoryDispatcher, re, Products
from OFS.Traversable import Traversable
+from OFS import SimpleItem
from Globals import DTMLFile, Persistent
from Globals import MessageDialog, default__class_init__
from Globals import REPLACEABLE, NOT_REPLACEABLE, UNIQUE
@@ -84,26 +85,20 @@
)
class BrowserDefault(Acquisition.Implicit, Persistent):
- """Callable default browser object. This is made as a class so that
- folderish objs not overriding browser_default can simply not define it.
- We also define this class as replaceable so that TTW scripts can
- override it
+ """Callable default browser object for object managers. This is made as a
+ class so that folderish objs not overriding browser_default can simply
+ not define it. We also define this class as replaceable so that TTW
+ scripts can override it
"""
security = ClassSecurityInfo()
__replaceable__ = REPLACEABLE # Allow this to be overridden in instances
- def __init__(self, default_name):
- self._default_path = (default_name,)
-
def __call__(self, request):
- """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]
+ """Return the proper default method name to be published
+ This name is acquired from the parent object"""
+ return self.aq_parent, \
+ (self.aq_acquire('_object_manager_browser_default_id'),)
default__class_init__(BrowserDefault)
@@ -673,10 +668,6 @@
#######################################################################
# 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, REQUEST=None):
"""Set the id of the browser_default method. If acquire is true
then the local browser_default is cleared and the setting is
@@ -688,11 +679,26 @@
'Cannot override custom browser default'
if acquire:
- if not self.isBrowserDefaultAcquired():
- del self.browser_default
+ try:
+ del self._object_manager_browser_default_id
+ except (AttributeError, KeyError):
+ pass # If its already gone, so be it
+ id = self.aq_acquire('_object_manager_browser_default_id')
else:
self._checkId(id, allow_dup=1)
- self.browser_default = BrowserDefault(id)
+ self._object_manager_browser_default_id = id
+
+ if id == 'index_html':
+ # This is a small optimization since the publisher stills falls
+ # back on this default value if there is no browser_default
+ # method at all for bw compatibility
+ try:
+ del self.browser_default
+ except (AttributeError, KeyError):
+ pass
+ else:
+ # Create a browser_default callable
+ self.browser_default = BrowserDefault()
if REQUEST:
REQUEST.RESPONSE.redirect(REQUEST.URL1 +
@@ -707,22 +713,24 @@
"""
if self.hasCustomBrowserDefault():
return None
- elif acquire or not self.isBrowserDefaultAcquired():
- return self.browser_default.getDefaultId()
+ if acquire:
+ return self.aq_acquire('_object_manager_browser_default_id')
else:
- return None
+ return getattr(self, '_object_manager_browser_default_id', None)
def isBrowserDefaultAcquired(self):
"""Return true if the current browser default is being acquired"""
- return aq_base(self).browser_default is Acquisition.Acquired
+ return not hasattr(self, '_object_manager_browser_default_id')
def hasCustomBrowserDefault(self):
"""Return true if a custom browser_default object has been
installed
"""
- return not (self.isBrowserDefaultAcquired()
- or getattr(self.browser_default, '__class__', None)
- is BrowserDefault)
+ try:
+ return getattr(self.browser_default, '__class__', None) \
+ is not BrowserDefault
+ except AttributeError:
+ return 0
def findChilds(obj,dirname=''):
""" recursive walk through the object hierarchy to