[Zope3-checkins] CVS: Zope3/src/zope/app/form - utility.py:1.15

Jim Fulton jim@zope.com
Fri, 7 Mar 2003 16:28:03 -0500


Update of /cvs-repository/Zope3/src/zope/app/form
In directory cvs.zope.org:/tmp/cvs-serv12416

Modified Files:
	utility.py 
Log Message:
Fixed a bug in getWidgetsData's (recently changed) handling of
readonly fields. getWidgetsData needs to read readonly fields unless
explictly told not to. We need to be able to collect data for readonly
fields in *add* forms.


=== Zope3/src/zope/app/form/utility.py 1.14 => 1.15 ===
--- Zope3/src/zope/app/form/utility.py:1.14	Wed Mar  5 08:13:40 2003
+++ Zope3/src/zope/app/form/utility.py	Fri Mar  7 16:27:32 2003
@@ -161,7 +161,7 @@
     return False
 
 def getWidgetsData(view, schema, strict=True, names=None, set_missing=True,
-                   do_not_raise=False):
+                   do_not_raise=False, exclude_readonly=False):
     """Collect the user-entered data defined by a schema
 
     Data is collected from view widgets. For every field in the
@@ -188,6 +188,10 @@
     do_not_raise is used if a call to getWidgetsData raises an exception,
     and you want to make use of the data that *is* available in your
     error-handler.
+
+    Normaly, readonly fields are included. To exclude readonly fields,
+    provide a exclude_readonly keyword argument with a true value.
+    
     """
 
     result = {}
@@ -195,18 +199,19 @@
 
     for name, field in _fieldlist(names, schema):
         widget = getattr(view, name)
-        if not field.readonly:
-            if widget.haveData():
-                try:
-                    result[name] = widget.getData()
-                except InputErrors, v:
-                    errors.append(v)
-            elif strict and field.required:
-                errors.append(MissingInputError(name, widget.title,
-                                                'the field is required')
-                              )
-            elif set_missing:
-                result[name] = None # XXX field.missing_value
+        if exclude_readonly and widget.context.readonly:
+            continue
+        if widget.haveData():
+            try:
+                result[name] = widget.getData()
+            except InputErrors, v:
+                errors.append(v)
+        elif strict and field.required:
+            errors.append(MissingInputError(name, widget.title,
+                                            'the field is required')
+                          )
+        elif set_missing:
+            result[name] = None # XXX field.missing_value
 
     if errors and not do_not_raise:
         raise WidgetsError(*errors)