[Zope3-checkins] SVN: Zope3/branches/3.3/ Merge zope.formlib bugfix from trunk revision 68275

Roger Ineichen roger at projekt01.ch
Thu May 25 19:07:23 EDT 2006


Log message for revision 68297:
  Merge zope.formlib bugfix from trunk revision 68275
  Make use of get_rendered in setUpInputWidget 
  which is used in AddFormBase 
  
  Update CHANGES.txt

Changed:
  U   Zope3/branches/3.3/doc/CHANGES.txt
  U   Zope3/branches/3.3/src/zope/formlib/form.py
  U   Zope3/branches/3.3/src/zope/formlib/form.txt
  U   Zope3/branches/3.3/src/zope/formlib/tests.py

-=-
Modified: Zope3/branches/3.3/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.3/doc/CHANGES.txt	2006-05-25 22:51:27 UTC (rev 68296)
+++ Zope3/branches/3.3/doc/CHANGES.txt	2006-05-25 23:07:22 UTC (rev 68297)
@@ -136,6 +136,9 @@
 
     Bug Fixes
 
+      - Fix get_rendered in zope.formlib. Make use of get_rendered in 
+        setUpInputWidget which is used in AddFormBase.
+
       - Fixed error handling in sequence item input widget. This widget
         was raising a ValidationError instead a WidgetInputError. The formlib
         didn't catch ValidationErrors. Added also ValidationError handling to

Modified: Zope3/branches/3.3/src/zope/formlib/form.py
===================================================================
--- Zope3/branches/3.3/src/zope/formlib/form.py	2006-05-25 22:51:27 UTC (rev 68296)
+++ Zope3/branches/3.3/src/zope/formlib/form.py	2006-05-25 23:07:22 UTC (rev 68297)
@@ -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/branches/3.3/src/zope/formlib/form.txt
===================================================================
--- Zope3/branches/3.3/src/zope/formlib/form.txt	2006-05-25 22:51:27 UTC (rev 68296)
+++ Zope3/branches/3.3/src/zope/formlib/form.txt	2006-05-25 23:07:22 UTC (rev 68297)
@@ -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/branches/3.3/src/zope/formlib/tests.py
===================================================================
--- Zope3/branches/3.3/src/zope/formlib/tests.py	2006-05-25 22:51:27 UTC (rev 68296)
+++ Zope3/branches/3.3/src/zope/formlib/tests.py	2006-05-25 23:07:22 UTC (rev 68297)
@@ -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