[Checkins] SVN: plone.z3cform/trunk/ Handle wrong fieldnames more cleanly in the ++widget++ traverser.

Laurence Rowe l at lrowe.co.uk
Mon Feb 21 12:32:52 EST 2011


Log message for revision 120504:
  Handle wrong fieldnames more cleanly in the ++widget++ traverser.

Changed:
  U   plone.z3cform/trunk/docs/HISTORY.txt
  U   plone.z3cform/trunk/plone/z3cform/traversal.py
  U   plone.z3cform/trunk/plone/z3cform/traversal.txt

-=-
Modified: plone.z3cform/trunk/docs/HISTORY.txt
===================================================================
--- plone.z3cform/trunk/docs/HISTORY.txt	2011-02-21 15:12:07 UTC (rev 120503)
+++ plone.z3cform/trunk/docs/HISTORY.txt	2011-02-21 17:32:51 UTC (rev 120504)
@@ -4,6 +4,8 @@
 0.7.3dev - unreleased
 ---------------------
 
+* Handle wrong fieldnames more cleanly in the ++widget++ traverser.
+  [elro]
 
 0.7.2 - 2011-02-17
 ------------------

Modified: plone.z3cform/trunk/plone/z3cform/traversal.py
===================================================================
--- plone.z3cform/trunk/plone/z3cform/traversal.py	2011-02-21 15:12:07 UTC (rev 120503)
+++ plone.z3cform/trunk/plone/z3cform/traversal.py	2011-02-21 17:32:51 UTC (rev 120504)
@@ -12,8 +12,10 @@
 from plone.z3cform.interfaces import IDeferSecurityCheck
 from plone.z3cform import z2
 
+from Acquisition import aq_base
 from Acquisition import aq_inner
 
+
 class FormWidgetTraversal(object):
     """Allow traversal to widgets via the ++widget++ namespace. The context
     is the from itself (used when the layout wrapper view is not used).
@@ -58,10 +60,12 @@
         # Find the widget - it may be in a group
         if name in form.widgets:
             widget = form.widgets.get(name)
-        elif form.groups is not None:
+        elif getattr(aq_base(form), 'groups', None) is not None:
             for group in form.groups:
                 if name in group.widgets:
                     widget = group.widgets.get(name)
+        else:
+            raise KeyError(name)
         
         # Make the parent of the widget the traversal parent.
         # This is required for security to work in Zope 2.12

Modified: plone.z3cform/trunk/plone/z3cform/traversal.txt
===================================================================
--- plone.z3cform/trunk/plone/z3cform/traversal.txt	2011-02-21 15:12:07 UTC (rev 120503)
+++ plone.z3cform/trunk/plone/z3cform/traversal.txt	2011-02-21 17:32:51 UTC (rev 120504)
@@ -158,4 +158,12 @@
     Updating test form
     <TextWidget 'form.widgets.age'>
 
-Please note that this point, the form has been updated, but not rendered.
\ No newline at end of file
+Please note that this point, the form has been updated, but not rendered.
+
+When a form field does not exist a KeyError is raised.
+
+    >>> traverser = getMultiAdapter((form, request), name=u"widget")
+    >>> traverser.traverse('missing', [])
+    Traceback (most recent call last):
+    ...
+    KeyError: 'missing'



More information about the checkins mailing list