[Zope3-checkins] SVN: Zope3/trunk/src/zope/formlib/ Bugfix zope.formlib

Roger Ineichen roger at projekt01.ch
Thu May 25 12:17:07 EDT 2006


Log message for revision 68275:
  Bugfix zope.formlib
  Make use of get_rendered in setUpInputWidget 
  which is used in AddFormBase 

Changed:
  U   Zope3/trunk/src/zope/formlib/form.py
  U   Zope3/trunk/src/zope/formlib/form.txt
  U   Zope3/trunk/src/zope/formlib/tests.py

-=-
Modified: Zope3/trunk/src/zope/formlib/form.py
===================================================================
--- Zope3/trunk/src/zope/formlib/form.py	2006-05-25 14:29:46 UTC (rev 68274)
+++ Zope3/trunk/src/zope/formlib/form.py	2006-05-25 16:17:02 UTC (rev 68275)
@@ -277,7 +277,7 @@
     return Widgets(widgets, len(form_prefix)+1)
 
 def setUpInputWidgets(form_fields, form_prefix, context, request,
-                      ignore_request=False):
+                      form=None, ignore_request=False):
     widgets = []
     for form_field in form_fields:
         field = form_field.field.bind(context)
@@ -290,7 +290,10 @@
         widget.setPrefix(prefix)
 
         if ignore_request:
-            value = field.default
+            if form_field.get_rendered is not None:
+                value = form_field.get_rendered(form)
+            else:
+                value = field.default
             widget.setRenderedValue(value)
 
         widgets.append((True, widget))

Modified: Zope3/trunk/src/zope/formlib/form.txt
===================================================================
--- Zope3/trunk/src/zope/formlib/form.txt	2006-05-25 14:29:46 UTC (rev 68274)
+++ Zope3/trunk/src/zope/formlib/form.txt	2006-05-25 16:17:02 UTC (rev 68275)
@@ -1528,6 +1528,37 @@
            size="10" type="text" value="100.0"  />
     <span class="dateTime">2002 12 2  12:30:00 </span>
 
+Now try the same with the AddFormBase which uses a setUpInputWidget:
+
+    >>> class MyAddForm(form.AddFormBase):
+    ...     actions = ()
+    ...
+    ...     def now(self):
+    ...         return datetime.datetime(2002, 12, 2, 12, 30)
+    ...
+    ...     form_fields = form.Fields(
+    ...         form.Fields(IOrder).omit('now'),
+    ...         form.Field(IOrder['now'], get_rendered=now),
+    ...         )
+    ...
+    ...     def setUpWidgets(self, ignore_request=True):
+    ...         super(MyAddForm, self).setUpWidgets(ignore_request)
+
+    >>> print MyAddForm(None, request)() # doctest: +NORMALIZE_WHITESPACE
+    <input class="textType" id="form.identifier" name="form.identifier" 
+           size="10" type="text" value=""  />
+    <input class="textType" id="form.name" name="form.name" size="20" 
+           type="text" value=""  />
+    <input class="textType" id="form.min_size" name="form.min_size" 
+           size="10" type="text" value=""  />
+    <input class="textType" id="form.max_size" name="form.max_size" 
+           size="10" type="text" value=""  />
+    <input class="textType" id="form.now" name="form.now" size="20" 
+           type="text" value="2002-12-02 12:30:00"  />
+
+Note that a EditForm can't make use of a get_rendered method. The get_rendered
+method does only set initial values.
+
 Note that the function passed must take a form as an argument.  The
 `setUpWidgets` function takes an optional 'form' argument, which
 **must** be passed if any fields use the get_rendered option.  The

Modified: Zope3/trunk/src/zope/formlib/tests.py
===================================================================
--- Zope3/trunk/src/zope/formlib/tests.py	2006-05-25 14:29:46 UTC (rev 68274)
+++ Zope3/trunk/src/zope/formlib/tests.py	2006-05-25 16:17:02 UTC (rev 68275)
@@ -127,6 +127,13 @@
         zope.app.form.interfaces.IDisplayWidget,
         )
     component.provideAdapter(
+        zope.app.form.browser.DatetimeWidget,
+        [zope.schema.interfaces.IDatetime,
+         zope.publisher.interfaces.browser.IBrowserRequest,
+         ],
+        zope.app.form.interfaces.IInputWidget,
+        )
+    component.provideAdapter(
         zope.app.form.browser.exception.WidgetInputErrorView,
         [zope.app.form.interfaces.IWidgetInputError,
          zope.publisher.interfaces.browser.IBrowserRequest,



More information about the Zope3-Checkins mailing list