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

Fred L. Drake, Jr. fred@zope.com
Wed, 16 Apr 2003 17:49:30 -0400


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

Modified Files:
	utility.py 
Log Message:
- setUpDisplayWidgets():  New function; returns a display-only widget
  for all fields, regardless of the readonly setting
- refactored setUpDisplayWidgets() and setUpEditWidgets() to share an
  implementation


=== Zope3/src/zope/app/form/utility.py 1.16 => 1.17 ===
--- Zope3/src/zope/app/form/utility.py:1.16	Mon Apr 14 04:27:16 2003
+++ Zope3/src/zope/app/form/utility.py	Wed Apr 16 17:49:29 2003
@@ -126,6 +126,32 @@
     No initial data is provided if the content lacks a named
     attribute, or if the named attribute value is None.
     """
+    _setUpWidgets(view, schema, content, prefix, force,
+                  names, context, 'display', 'edit')
+
+def setUpDisplayWidgets(view, schema, content=None, prefix=None, force=False,
+                        names=None, context=None):
+    """Set up widgets for the fields defined by a schema
+
+    Initial data is provided by content object attributes.
+    No initial data is provided if the content lacks a named
+    attribute, or if the named attribute value is None.
+    """
+    _setUpWidgets(view, schema, content, prefix, force,
+                  names, context, 'display', 'display')
+
+def _setUpWidgets(view, schema, content, prefix, force,
+                  names, context, displayname, editname):
+    # Set up widgets for the fields defined by a schema.
+    #
+    # displayname is the name of the view used for a field that is
+    # marked read-only; editname is the name of the view used for a
+    # field that is editable.
+    #
+    # Initial data is provided by content object attributes.
+    # No initial data is provided if the content lacks a named
+    # attribute, or if the named attribute value is None.
+    #
     if content is None:
         if context is None:
             content = view.context
@@ -134,9 +160,9 @@
 
     for name, field in _fieldlist(names, schema):
         if field.readonly:
-            vname = 'display'
+            vname = displayname
         else:
-            vname = 'edit'
+            vname = editname
 
         try:
             value = field.get(content)