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

Jim Fulton jim@zope.com
Wed, 11 Dec 2002 06:41:37 -0500


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

Modified Files:
      Tag: AdapterAndView-branch
	Utility.py 
Log Message:
Got AdapterService views working.

=== Zope3/lib/python/Zope/App/Forms/Utility.py 1.6 => 1.6.4.1 ===
--- Zope3/lib/python/Zope/App/Forms/Utility.py:1.6	Mon Dec  9 11:09:18 2002
+++ Zope3/lib/python/Zope/App/Forms/Utility.py	Wed Dec 11 06:41:06 2002
@@ -41,7 +41,8 @@
 from Zope.ComponentArchitecture.IView import IViewFactory
 
 
-def setUpWidget(view, name, field, value=None, prefix=None, force=0, vname=None):
+def setUpWidget(view, name, field, value=None, prefix=None,
+                force=0, vname=None):
     """Set up a single view widget
 
     The widget will be an attribute of the view. If there is already
@@ -98,20 +99,21 @@
 
     return [name[1] for name in names]
 
-def setUpWidgets(view, schema, prefix=None, force=0, **kw):
+def setUpWidgets(view, schema, prefix=None, force=0,
+                 initial={}, names=None):
     """Set up widgets for the fields defined by a schema
 
-    Initial data is provided by keyword arguments.
     """
-    
-    for name in schema:
+
+    for name in (names or schema):
         field = schema[name]
         if IField.isImplementedBy(field):
             # OK, we really got a field
-            setUpWidget(view, name, field, kw.get(name),
+            setUpWidget(view, name, field, initial.get(name),
                         prefix=prefix, force=force)
 
-def setUpEditWidgets(view, schema, content=None, prefix=None, force=0):
+def setUpEditWidgets(view, schema, content=None, prefix=None, force=0,
+                     names=None):
     """Set up widgets for the fields defined by a schema
 
     Initial data is provided by content object attributes.
@@ -121,7 +123,7 @@
     if content is None:
         content = view.context
 
-    for name in schema:
+    for name in (names or schema):
         field = schema[name]
         if IField.isImplementedBy(field):
             # OK, we really got a field
@@ -133,7 +135,7 @@
             setUpWidget(view, name, field, getattr(content, name, None),
                         prefix = prefix, force = force, vname = vname)
 
-def haveWidgetsData(view, schema):
+def haveWidgetsData(view, schema, names=None):
     """Collect the user-entered data defined by a schema
 
     Data is collected from view widgets. For every field in the
@@ -142,7 +144,7 @@
     The data are returned in a mapping from field name to value.
     """
 
-    for name in schema:
+    for name in (names or schema):
         field = schema[name]
         if IField.isImplementedBy(field):
             # OK, we really got a field
@@ -151,7 +153,7 @@
 
     return False
 
-def getWidgetsData(view, schema, required=1):
+def getWidgetsData(view, schema, required=1, names=None):
     """Collect the user-entered data defined by a schema
 
     Data is collected from view widgets. For every field in the
@@ -167,7 +169,7 @@
     result = {}
     errors = []
 
-    for name in schema:
+    for name in (names or schema):
         field = schema[name]
         if IField.isImplementedBy(field):
             # OK, we really got a field
@@ -186,7 +188,8 @@
     
     return result
 
-def getWidgetsDataForContent(view, schema, content=None, required=0):
+def getWidgetsDataForContent(view, schema, content=None, required=0,
+                             names=None):
     """Collect the user-entered data defined by a schema
 
     Data is collected from view widgets. For every field in the
@@ -199,7 +202,7 @@
     input, an error will be raised.
     """
     
-    data = getWidgetsData(view, schema, required)
+    data = getWidgetsData(view, schema, required, names)
     
     if content is None:
         content = view.context