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

Guido van Rossum guido@python.org
Wed, 19 Mar 2003 16:30:18 -0500


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

Modified Files:
      Tag: local-utility-branch
	useconfiguration.py 
Log Message:
Use a custom widget for selecting the interface in the utility add
form.  Now we don't have to use beforeUpdateHook.


=== Zope3/src/zope/app/browser/services/utility/useconfiguration.py 1.1.2.5 => 1.1.2.6 ===
--- Zope3/src/zope/app/browser/services/utility/useconfiguration.py:1.1.2.5	Wed Mar 19 16:09:05 2003
+++ Zope3/src/zope/app/browser/services/utility/useconfiguration.py	Wed Mar 19 16:30:16 2003
@@ -26,6 +26,8 @@
 from zope.app.interfaces.container import IZopeContainer
 from zope.app.form.widget import CustomWidget
 from zope.app.browser.services.field import ComponentPathDisplayWidget
+from zope.app.interfaces.services.configuration import IComponentConfiguration
+from zope.app.browser.component.interfacewidget import InterfaceWidget
 
 class UseConfiguration(BrowserView):
     """View for displaying the configurations for a utility.
@@ -49,26 +51,42 @@
         return result
         
 
-class AddConfiguration:
-    """View for adding a utility configuration.
-
-    This overrides some methods from IAddFormCustomization.
-
-    This is a view on a local utility, configured by an <addform>
-    directive.
+class UtilityInterfaceWidget(InterfaceWidget):
+    """Custom widget to select an interface from the component's interfaces.
     """
 
-    def beforeUpdateHook(self):
+    def __call__(self):
+        field = self.context
+        component = field.context
         # XXX Have to remove proxies because flattenInterfaces
         #     doesn't work with proxies.
-        bare = removeAllProxies(self.context)
-        # Tell the interface widget which interfaces the user can select
-        self.interface.interfaces = [
+        bare = removeAllProxies(component)
+        # Compute the list of interfaces that the component implements
+        interfaces = [
             interface
             for interface in flattenInterfaces(bare.__implements__)
             if list(interface) # Does the interface define any names
             ]
+        result = ['\n<select name="%s">' % self.name]
+        for interface in interfaces:
+            result.append('  <option value="%s.%s">%s</option>' %
+                          (interface.__module__, interface.__name__,
+                           interface.__name__))
+        result.append('</select>')
+        return '\n'.join(result)
         
+
+class AddConfiguration:
+    """View for adding a utility configuration.
+
+    This overrides some methods from IAddFormCustomization.
+
+    This is a view on a local utility, configured by an <addform>
+    directive.
+    """
+
+    interface = CustomWidget(UtilityInterfaceWidget)
+
     def add(self, content):
         # Get the configuration manager for this folder
         configure = traverse(getWrapperContainer(self.context), 'configure')