[Checkins] SVN: plone.z3cform/trunk/ Add ability to find widgets with non-integer names in lists

Jamie Lentin jm at lentin.co.uk
Tue May 10 11:50:29 EDT 2011


Log message for revision 121650:
  Add ability to find widgets with non-integer names in lists

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

-=-
Modified: plone.z3cform/trunk/docs/HISTORY.txt
===================================================================
--- plone.z3cform/trunk/docs/HISTORY.txt	2011-05-10 14:33:29 UTC (rev 121649)
+++ plone.z3cform/trunk/docs/HISTORY.txt	2011-05-10 15:50:29 UTC (rev 121650)
@@ -1,6 +1,14 @@
 Changelog
 =========
 
+0.7.6 - unreleased
+------------------
+
+* Add ability to find widgets with non-integer names in lists. This shouldn't
+  generally be something that happens, and ideally should be removed if
+  DataGridField looses it's 'AA' and 'TT' rows.
+  [lentinj]
+
 0.7.5 - 2011-05-03
 ------------------
 

Modified: plone.z3cform/trunk/plone/z3cform/traversal.py
===================================================================
--- plone.z3cform/trunk/plone/z3cform/traversal.py	2011-05-10 14:33:29 UTC (rev 121649)
+++ plone.z3cform/trunk/plone/z3cform/traversal.py	2011-05-10 15:50:29 UTC (rev 121650)
@@ -72,11 +72,22 @@
             part = parts.pop(0)
             if type(getattr(target,'widgets',None)) is list: # i.e. a z3c.form.widget.MultiWidget
                 try:
+                    # part should be integer index in list, look it up
                     target = target.widgets[int(part)]
                 except IndexError:
                     raise TraversalError("'"+part+"' not in range")
                 except ValueError:
-                    raise TraversalError("'"+part+"' not valid index")
+                    #HACK: part isn't integer. Iterate through widgets to
+                    # find matching name. This is required for 
+                    # DataGridField, which appends 'AA' and 'TT' rows to
+                    # it's widget list.
+                    prefix = util.expandPrefix(target.prefix)
+                    filtered = [w for w in target.widgets
+                                        if w.name[len(prefix):] == part]
+                    if len(filtered) == 1:
+                        target = filtered[0]
+                    else:
+                        raise TraversalError("'"+part+"' not valid index")
             elif hasattr(target,'widgets'): # Either base form, or subform
                 # Check to see if we can find a "Behaviour.widget"
                 new_target = None

Modified: plone.z3cform/trunk/setup.py
===================================================================
--- plone.z3cform/trunk/setup.py	2011-05-10 14:33:29 UTC (rev 121649)
+++ plone.z3cform/trunk/setup.py	2011-05-10 15:50:29 UTC (rev 121650)
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 import os
 
-version = '0.7.5'
+version = '0.7.6'
 
 
 def description():



More information about the checkins mailing list