[Zope3-checkins] SVN: Zope3/branches/3.2/src/zope/formlib/ Applied the bugfix from trunk rev 66255: fixed a bug in form prefix handling

Albertas Agejevas alga at pov.lt
Wed Mar 29 04:47:03 EST 2006


Log message for revision 66257:
  Applied the bugfix from trunk rev 66255:  fixed a bug in form prefix handling
  in setUp*Widgets.
  

Changed:
  U   Zope3/branches/3.2/src/zope/formlib/form.py
  U   Zope3/branches/3.2/src/zope/formlib/tests.py

-=-
Modified: Zope3/branches/3.2/src/zope/formlib/form.py
===================================================================
--- Zope3/branches/3.2/src/zope/formlib/form.py	2006-03-29 09:40:55 UTC (rev 66256)
+++ Zope3/branches/3.2/src/zope/formlib/form.py	2006-03-29 09:47:02 UTC (rev 66257)
@@ -254,11 +254,9 @@
                 widget = component.getMultiAdapter((field, request),
                                                    IInputWidget)
 
-        prefix = form_field.prefix
-        if prefix:
-            prefix = form_prefix + '.' + prefix
-        else:
-            prefix = form_prefix
+        prefix = form_prefix
+        if form_field.prefix:
+            prefix += '.' + form_field.prefix
 
         widget.setPrefix(prefix)
 
@@ -283,12 +281,17 @@
     for form_field in form_fields:
         field = form_field.field.bind(context)
         widget = _createWidget(form_field, field, request, IInputWidget)
+
+        prefix = form_prefix
         if form_field.prefix:
-            form_prefix = form_prefix + '.' + form_field.prefix
+            prefix += '.' + form_field.prefix
+
+        widget.setPrefix(prefix)
+
         if ignore_request:
             value = field.default
             widget.setRenderedValue(value)
-        widget.setPrefix(form_prefix)
+
         widgets.append((True, widget))
     return Widgets(widgets, len(form_prefix)+1)
 
@@ -363,10 +366,11 @@
             iface = IInputWidget
         widget = _createWidget(form_field, field, request, iface)
 
+        prefix = form_prefix
         if form_field.prefix:
-            form_prefix = form_prefix + '.' + form_field.prefix
+            prefix += '.' + form_field.prefix
 
-        widget.setPrefix(form_prefix)
+        widget.setPrefix(prefix)
 
         if ignore_request or readonly or not widget.hasInput():
             # Get the value to render
@@ -389,9 +393,10 @@
             iface = IInputWidget
         widget = _createWidget(form_field, field, request, iface)
 
+        prefix = form_prefix
         if form_field.prefix:
-            form_prefix = form_prefix + '.' + form_field.prefix
-        widget.setPrefix(form_prefix)
+            prefix += '.' + form_field.prefix
+        widget.setPrefix(prefix)
 
         if ((form_field.__name__ in data)
             and (ignore_request or readonly or not widget.hasInput())

Modified: Zope3/branches/3.2/src/zope/formlib/tests.py
===================================================================
--- Zope3/branches/3.2/src/zope/formlib/tests.py	2006-03-29 09:40:55 UTC (rev 66256)
+++ Zope3/branches/3.2/src/zope/formlib/tests.py	2006-03-29 09:47:02 UTC (rev 66257)
@@ -353,41 +353,61 @@
     [[my.domain][Enter your name]]
     [[my.domain][Ok]]
 
+"""
 
 
+def test_setUpWidgets_prefix():
+    """This is a regression test for field prefix handling in setUp*Widgets.
 
+    Let's set up fields with some interface and a prefix on fields:
 
+        >>> from zope.formlib import form
+        >>> from zope import interface, schema
 
+        >>> class ITrivial(interface.Interface):
+        ...     name = schema.TextLine(title=u"Name")
 
+        >>> form_fields = form.Fields(ITrivial, prefix='one')
+        >>> form_fields += form.Fields(ITrivial, prefix='two')
+        >>> form_fields += form.Fields(ITrivial, prefix='three')
 
+    Let's call setUpDataWidgets and see their names:
 
+        >>> class Trivial(object):
+        ...     interface.implements(ITrivial)
+        ...     name = 'foo'
+        >>> context = Trivial()
 
+        >>> from zope.publisher.browser import TestRequest
+        >>> request = TestRequest()
 
+        >>> widgets = form.setUpDataWidgets(form_fields, 'form', context,
+        ...                                 request, {})
+        >>> [w.name for w in widgets]
+        ['form.one.name', 'form.two.name', 'form.three.name']
 
+    Let's try the same with setUpEditWidgets:
 
+        >>> widgets = form.setUpEditWidgets(form_fields, 'form', context,
+        ...                                  request)
+        >>> [w.name for w in widgets]
+        ['form.one.name', 'form.two.name', 'form.three.name']
 
+    And setUpInputWidgets:
 
+        >>> widgets = form.setUpInputWidgets(form_fields, 'form', context,
+        ...                                  request)
+        >>> [w.name for w in widgets]
+        ['form.one.name', 'form.two.name', 'form.three.name']
 
+    And setUpWidgets:
 
+        >>> widgets = form.setUpWidgets(form_fields, 'form', context, request)
+        >>> [w.name for w in widgets]
+        ['form.one.name', 'form.two.name', 'form.three.name']
 
+    """
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-"""
-
 def test_suite():
     from zope.testing import doctest
     return unittest.TestSuite((



More information about the Zope3-Checkins mailing list