[Zope-Checkins] CVS: Zope/lib/python/OFS - Application.py:1.181 Folder.py:1.98 ObjectManager.py:1.148

Casey Duncan casey@zope.com
Wed, 27 Mar 2002 16:51:34 -0500


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

Modified Files:
	Application.py Folder.py ObjectManager.py 
Log Message:
Merging death (to index_html). Sorry about the previous noise. Note that the
new settings tab will have more stuff under it before 2.6 ships.


=== Zope/lib/python/OFS/Application.py 1.180 => 1.181 ===
 
 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
@@ -59,6 +59,9 @@
     
     __allow_groups__=UserFolder()
 
+    # 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
 
@@ -700,6 +703,11 @@
                     raise
 
 def install_standards(app):
+    # Check to see if we've already done this before
+    # Don't do it twice (Casey)
+    if getattr(app, '_standard_objects_have_been_added', 0):
+        return
+        
     # Install the replaceable standard objects
     from Products.PageTemplates.PageTemplateFile import PageTemplateFile
     std_dir = os.path.join(Globals.package_home(globals()), 'standard')
@@ -722,9 +730,11 @@
         else:
             continue
         wrote = 1
-        ob.__replaceable__ = Globals.REPLACEABLE
-        setattr(Application, fn, ob)
+        # Below is icky and sneaky since it makes these impossible to delete
+        #ob.__replaceable__ = Globals.REPLACEABLE
+        #setattr(Application, fn, ob)
     if wrote:
+        app._standard_objects_have_been_added = 1
         get_transaction().note('Installed standard objects')
         get_transaction().commit()
 


=== Zope/lib/python/OFS/Folder.py 1.97 => 1.98 ===
     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)
@@ -87,9 +90,9 @@
     _properties=({'id':'title', 'type': 'string'},)
 
     manage_options=(
-        (ObjectManager.ObjectManager.manage_options[0],)+
+        ObjectManager.ObjectManager.manage_options+
         (
-        {'label':'View', 'action':'index_html',
+        {'label':'View', 'action':'',
          'help':('OFSP','Folder_View.stx')},
         )+
         PropertyManager.PropertyManager.manage_options+


=== Zope/lib/python/OFS/ObjectManager.py 1.147 => 1.148 ===
 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
 from webdav.NullResource import NullResource
 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
@@ -82,6 +84,23 @@
             'The id "%s" contains characters illegal in URLs.' % id
             )
 
+class BrowserDefault(Acquisition.Implicit, Persistent):
+    """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 __call__(self, request):
+        """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)
 
 class BeforeDeleteException( Exception ): pass # raise to veto deletion
 class BreakoutException ( Exception ): pass  # raised to break out of loops
@@ -113,6 +132,11 @@
          ('manage_importObject','manage_importExportForm',
           'manage_exportObject')
          ),
+        ('View', ('getBrowserDefaultId',)),
+        ('Manage folderish settings',
+         ('manage_settings', 'setBrowserDefaultId', 
+           'isBrowserDefaultAcquired','hasCustomBrowserDefault')
+        ),
     )
 
 
@@ -124,12 +148,12 @@
 
     manage_main=DTMLFile('dtml/main', globals())
     manage_index_main=DTMLFile('dtml/index_main', globals())
+    manage_settings=DTMLFile('dtml/objectManagerSettings', globals())
 
     manage_options=(
         {'label':'Contents', 'action':'manage_main',
          'help':('OFSP','ObjectManager_Contents.stx')},
-#        {'label':'Import/Export', 'action':'manage_importExportForm',
-#         'help':('OFSP','ObjectManager_Import-Export.stx')},         
+        {'label':'Settings', 'action':'manage_settings'},
         )
 
     isAnObjectManager=1
@@ -199,7 +223,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.
@@ -642,6 +665,72 @@
                 return NullResource(self, key, request).__of__(self)
         raise KeyError, key
 
+    #######################################################################
+    # Death to index_html implementation (casey)
+
+    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
+           acquired
+        """
+        if self.hasCustomBrowserDefault():
+            # If a custom browser default is installed, don't override it
+            raise BadRequestException, \
+                'Cannot override custom browser default'
+
+        if acquire:
+            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._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 + 
+                '/manage_settings?manage_tabs_message=Settings+Changed')
+
+    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 self.hasCustomBrowserDefault():
+            return None
+        if acquire:
+            return self.aq_acquire('_object_manager_browser_default_id')
+        else:
+            return getattr(self, '_object_manager_browser_default_id', None)
+
+    def isBrowserDefaultAcquired(self):
+        """Return true if the current browser default is being acquired"""
+        return not hasattr(self, '_object_manager_browser_default_id')
+
+    def hasCustomBrowserDefault(self):
+        """Return true if a custom browser_default object has been
+           installed
+        """
+        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