[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/utility - configure.zcml:1.1.2.3 useconfiguration.py:1.1.2.3

Jim Fulton jim@zope.com
Tue, 18 Mar 2003 11:56:15 -0500


Update of /cvs-repository/Zope3/src/zope/app/browser/services/utility
In directory cvs.zope.org:/tmp/cvs-serv21811/zope/app/browser/services/utility

Modified Files:
      Tag: local-utility-branch
	configure.zcml useconfiguration.py 
Log Message:
checkpoint into branch

=== Zope3/src/zope/app/browser/services/utility/configure.zcml 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/zope/app/browser/services/utility/configure.zcml:1.1.2.2	Thu Mar 13 17:28:09 2003
+++ Zope3/src/zope/app/browser/services/utility/configure.zcml	Tue Mar 18 11:55:44 2003
@@ -17,6 +17,20 @@
       menu="zmi_views" title="Configurations"
       />
 
+
+  <addform
+      for="zope.app.interfaces.services.utility.ILocalUtility"
+      name="addConfiguration.html"
+      schema="zope.app.interfaces.services.utility.IUtilityConfiguration"
+      class=".useconfiguration.AddConfiguration"
+      permission="zope.ManageServices"
+      content_factory="zope.app.services.utility.UtilityConfiguration"
+      arguments="name interface componentPath"
+      set_after_add="status"
+      />
+           
+
+<!--
   <pages
       for="zope.app.interfaces.services.utility.ILocalUtility"
       class=".useconfiguration.AddConfiguration"
@@ -28,5 +42,7 @@
     <page name="addConfiguration_action.html" attribute="action" />
 
   </pages>
+-->
+
 
 </zopeConfigure>


=== Zope3/src/zope/app/browser/services/utility/useconfiguration.py 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/zope/app/browser/services/utility/useconfiguration.py:1.1.2.2	Tue Mar 18 07:35:50 2003
+++ Zope3/src/zope/app/browser/services/utility/useconfiguration.py	Tue Mar 18 11:55:44 2003
@@ -21,14 +21,15 @@
 from zope.app.traversing import traverse, getPhysicalPathString
 from zope.publisher.browser import BrowserView
 from zope.interface.implements import flattenInterfaces
-from zope.app.interfaces.services.configuration \
-     import Unregistered, Registered, Active
 from zope.app.services.utility import UtilityConfiguration
 from zope.proxy.introspection import removeAllProxies
 from zope.proxy.context import getWrapperContainer
 from zope.app.interfaces.container import IZopeContainer
 from zope.app.interfaces.services.utility import IUtilityConfiguration
 from zope.app.form.utility import setUpWidgets
+from zope.app.form.widget import CustomWidget
+from zope.app.browser.component.interfacewidget import InterfaceWidget
+from zope.app.browser.services.field import ComponentPathDisplayWidget
 
 class UseConfiguration(BrowserView):
     """View for displaying the configurations for a utility
@@ -51,140 +52,33 @@
                            'status': config.status,
                            })
         return result
+        
 
-class AddConfiguration(BrowserView):
+class AddConfiguration:
     """View for adding a utility configuration
     """
 
-    def __init__(self, context, request):
-        super(AddConfiguration, self).__init__(context, request)
-
-        # Use widgets for the fields we can use them for.
-        setUpWidgets(self, IUtilityConfiguration,
-                     names=('name', 'permission', 'status'))
-
-    def createAndAdd(self, data):
-        
-
-        # Get the configuration manager for this folder
-        configure = traverse(getWrapperContainer(self.context), 'configure')
-        container = getAdapter(configure, IZopeContainer)
-
-        path = getPhysicalPathString(self.context)
-
-        # Create the configuration object
-        config = UtilityConfiguration(data['name'], data['interface'], path,
-                                      permission=data['permission'])
-
-        # Add the configuration
-        configname = container.setObject("", config)
-
-        # Get the config in context, so we can set its status
-        config = container[configname]
-
-        
-        config.status = data['status']
-
-    def nextURL(self):
-        return "@@useConfiguration.html"
-        
-
-
-    def action(self, interface=None):
-        
-        # Handle the interface input. We wish we could use a widget!
-        if interface is None:
-            raise UserError("you must select an interface")
-        sm = getServiceManager(self.context)
-        interface = sm.resolve(interface)
-        if not interface.isImplementedBy(self.context):
-            raise ValueError("Invalid interface for the utility component")
-
-
-        # Get the configuration manager for this folder
-        configure = traverse(getWrapperContainer(self.context), 'configure')
-        container = getAdapter(configure, IZopeContainer)
-
-        # Get additional data
-        path = getPhysicalPathString(self.context)
-        permission = self.permission.getData()
-        name = self.name = getValue()
-
-        # Create the configuration object
-        config = UtilityConfiguration(name, interface, path,
-                                      permission=permission)
-
-        # Add the configuration
-        configname = container.setObject("", config)
-
-        # Get the config in context, so we can set its status
-        config = container[configname]
-
-        
-        config.status = self.status.getData()
-
-        self.request.response.redirect("@@useConfiguration.html")
+    interface = CustomWidget(InterfaceWidget)
+    componentPath = CustomWidget(ComponentPathDisplayWidget)
 
-    def listInterfaces(self):
+    def beforeUpdateHook(self):
         bare = removeAllProxies(self.context)
-        return [{'id': i.__module__ + "." + i.__name__, 'name': i.__name__}
-                for i in flattenInterfaces(bare.__implements__)
-                if i.names(True)]
-
-
+        self.interface.interfaces = [
+            interface
+            for interface in flattenInterfaces(bare.__implements__)
+            if list(interface) # Does the interface define any names
+            ]
 
-class AddConfiguration(BrowserView):
-    """View for adding a utility configuration
-    """
-
-    def createAndAdd(self, data):
+        path = getPhysicalPathString(self.context)
+        self.request.form[self.componentPath.name] = path
+        #self.componentPath.setData(path)
         
-
+    def add(self, content):
         # Get the configuration manager for this folder
         configure = traverse(getWrapperContainer(self.context), 'configure')
         container = getAdapter(configure, IZopeContainer)
-
-        path = getPhysicalPathString(self.context)
-
-        # Create the configuration object
-        config = UtilityConfiguration(data['name'], data['interface'], path,
-                                      permission=data['permission'])
-
-        # Add the configuration
-        configname = container.setObject("", config)
-
-        # Get the config in context, so we can set its status
-        config = container[configname]
-
-        
-        config.status = data['status']
+        return container[container.setObject("", content)]
 
     def nextURL(self):
         return "@@useConfiguration.html"
-        
-
-    def listInterfaces(self):
-        bare = removeAllProxies(self.context)
-        return [{'id': i.__module__ + "." + i.__name__, 'name': i.__name__}
-                for i in flattenInterfaces(bare.__implements__)
-                if i.names(True)]
-
-
-
-# Notes
-#
-# We have an add form with fields that depend on an existing object.
-#
-# We're creating a configuration for some other object.
-#
-# The configuration has a path that must be equal to the object's path.
-#
-# The configuration has an interface that depends on the object's interface.
-#
-
-"""
-
-what if the form had some notion of a "base" object.
-
-This object would be bound to some object provided by the view.