[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Forms - Utility.py:1.3

Jim Fulton jim@zope.com
Tue, 29 Oct 2002 12:12:38 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Forms
In directory cvs.zope.org:/tmp/cvs-serv29399

Modified Files:
	Utility.py 
Log Message:
Added option to specify a widget prefix when setting up widgets.


=== Zope3/lib/python/Zope/App/Forms/Utility.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/Forms/Utility.py:1.2	Mon Oct 28 18:52:31 2002
+++ Zope3/lib/python/Zope/App/Forms/Utility.py	Tue Oct 29 12:12:37 2002
@@ -41,7 +41,7 @@
 from Zope.Proxy.ContextWrapper import ContextWrapper
 
 
-def setUpWidget(view, name, field, value=None):
+def setUpWidget(view, name, field, value=None, prefix=None):
     """Set up a single view widget
 
     The widget will be an attribute of the view. If there is already
@@ -68,10 +68,13 @@
                 "but isn't."
                 % (view.__class__.__name__, name))
 
+    if prefix:
+        widget.setPrefix(prefix)
+
     if value is not None:
         widget.setData(value)
 
-def setUpWidgets(view, schema, **kw):
+def setUpWidgets(view, schema, prefix=None, **kw):
     """Set up widgets for the fields defined by a schema
 
     Initial data is provided by keyword arguments.
@@ -81,9 +84,9 @@
         field = schema[name]
         if IField.isImplementedBy(field):
             # OK, we really got a field
-            setUpWidget(view, name, field, kw.get(name))
+            setUpWidget(view, name, field, kw.get(name), prefix=prefix)
 
-def setUpEditWidgets(view, schema, content=None):
+def setUpEditWidgets(view, schema, content=None, prefix=None):
     """Set up widgets for the fields defined by a schema
 
     Initial data is provided by content object attributes.
@@ -97,7 +100,8 @@
         field = schema[name]
         if IField.isImplementedBy(field):
             # OK, we really got a field
-            setUpWidget(view, name, field, getattr(content, name, None))
+            setUpWidget(view, name, field, getattr(content, name, None),
+                        prefix = prefix)
 
 def getWidgetsData(view, schema):
     """Collect the user-entered data defined by a schema