[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/utility - addconfiguration.pt:1.1.2.2 useconfiguration.py:1.1.2.2
Jim Fulton
jim@zope.com
Tue, 18 Mar 2003 07:36:21 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/services/utility
In directory cvs.zope.org:/tmp/cvs-serv19240/src/zope/app/browser/services/utility
Modified Files:
Tag: local-utility-branch
addconfiguration.pt useconfiguration.py
Log Message:
Checking in current code to the branch.
It may be in a state of non-working-ness. We'll fix that later.
We're currently trying to clean up the logic for adding configs.
=== Zope3/src/zope/app/browser/services/utility/addconfiguration.pt 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/browser/services/utility/addconfiguration.pt:1.1.2.1 Mon Mar 17 11:16:48 2003
+++ Zope3/src/zope/app/browser/services/utility/addconfiguration.pt Tue Mar 18 07:35:50 2003
@@ -3,22 +3,30 @@
<div metal:fill-slot="body">
<form action="addConfiguration_action.html">
- <div class="row">
-
- <div class="label">Utility name</div>
- <div class="field"><input type="text" name="name"></div>
- <br>
- <div class="label">Interface</div>
- <select name="interface">
- <option tal:repeat="interface view/listInterfaces"
- tal:attributes="value interface/id"
- tal:content="interface/name">IFoo</option>
- </select>
- <br>
- <input type="reset" value="Reset form">
+ <div class="row">
+ <div tal:replace="structure view/name/row" />
+ </div>
+ <div class="row">
+ <div class="label">Interface</div>
+ <div class="field">
+ <select name="interface">
+ <option tal:repeat="interface view/listInterfaces"
+ tal:attributes="value interface/id"
+ tal:content="interface/name">IFoo</option>
+ </select>
+ </div>
+ </div>
+ <div class="row">
+ <div tal:replace="structure view/permission/row" />
+ </div>
+ <div class="row">
+ <div tal:replace="structure view/status/row" />
+ </div>
+ <div class="row">
+ <input type="reset" value="Reset form">
<input type="submit" value="Submit">
+ </div>
- </div>
</form>
</div>
=== Zope3/src/zope/app/browser/services/utility/useconfiguration.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/app/browser/services/utility/useconfiguration.py:1.1.2.1 Mon Mar 17 11:16:48 2003
+++ Zope3/src/zope/app/browser/services/utility/useconfiguration.py Tue Mar 18 07:35:50 2003
@@ -16,7 +16,7 @@
$Id$
"""
-from zope.component import getAdapter, getView
+from zope.component import getAdapter, getView, getServiceManager
from zope.app.interfaces.services.configuration import IUseConfiguration
from zope.app.traversing import traverse, getPhysicalPathString
from zope.publisher.browser import BrowserView
@@ -27,10 +27,17 @@
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
class UseConfiguration(BrowserView):
+ """View for displaying the configurations for a utility
+ """
+
def uses(self):
+ """Get a sequence of configuration summaries
+ """
component = self.context
useconfig = getAdapter(component, IUseConfiguration)
result = []
@@ -46,17 +53,76 @@
return result
class AddConfiguration(BrowserView):
+ """View for adding a utility configuration
+ """
- def action(self, name, interface=None):
+ 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")
- path = getPhysicalPathString(self.context)
+ 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)
- config = UtilityConfiguration(name, interface, path)
- name = container.setObject("", config)
- config = container[name]
- config.status = Active # XXX Really? Always activate it?
+
+ # 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")
def listInterfaces(self):
@@ -64,3 +130,61 @@
return [{'id': i.__module__ + "." + i.__name__, 'name': i.__name__}
for i in flattenInterfaces(bare.__implements__)
if i.names(True)]
+
+
+
+class AddConfiguration(BrowserView):
+ """View for adding a utility configuration
+ """
+
+ 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 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.
+