[Checkins] SVN: plone.z3cform/trunk/ added wildcard support to fieldset 'move' utility function (still needs a test)

David Glick davidglick at onenw.org
Thu Dec 4 00:11:53 EST 2008


Log message for revision 93599:
  added wildcard support to fieldset 'move' utility function (still needs a test)

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

-=-
Modified: plone.z3cform/trunk/docs/HISTORY.txt
===================================================================
--- plone.z3cform/trunk/docs/HISTORY.txt	2008-12-04 05:10:02 UTC (rev 93598)
+++ plone.z3cform/trunk/docs/HISTORY.txt	2008-12-04 05:11:53 UTC (rev 93599)
@@ -4,6 +4,10 @@
 0.5.3 - unreleased
 ------------------
 
+* Added wildcard support to the 'before' and 'after' parameters of the
+  fieldset 'move' utility function.
+  [davisagli]
+
 * Fixes for Zope 2.12 compatibility.
   [davisagli]
 

Modified: plone.z3cform/trunk/plone/z3cform/fieldsets/utils.py
===================================================================
--- plone.z3cform/trunk/plone/z3cform/fieldsets/utils.py	2008-12-04 05:10:02 UTC (rev 93598)
+++ plone.z3cform/trunk/plone/z3cform/fieldsets/utils.py	2008-12-04 05:11:53 UTC (rev 93599)
@@ -53,7 +53,6 @@
 def move(form, field_name, before=None, after=None, prefix=None, relative_prefix=None):
     """Move the field with the given name before or after another field.
     """
-    
     if prefix:
         field_name = expandPrefix(prefix) + field_name
     
@@ -64,14 +63,14 @@
     if after:
         offset = 1
     
-    relative = before or after
+    relative = orig_relative = before or after
     if relative_prefix:
         relative = expandPrefix(relative_prefix) + relative
     
     if field_name not in form.fields:
         raise KeyError("Field %s not found" % field_name)
     
-    if relative not in form.fields:
+    if relative != '*' and relative not in form.fields:
         found = False
         for group in form.groups:
             if relative in group.fields:
@@ -87,11 +86,21 @@
     
     if relative in form.fields:
         index = form.fields.keys().index(relative)
+    elif orig_relative == '*' and relative_prefix is None:
+        if before:
+            index = 0
+        else:
+            index = len(form.fields.keys()) - 1
     else:
         for group in form.groups:
             if relative in group.fields:
                 index = group.fields.keys().index(relative)
                 break
+            elif orig_relative == '*' and relative_prefix == group.prefix:
+                if before:
+                    index = 0
+                else:
+                    index = len(group.fields.keys()) - 1
     
     if index is None:
         raise KeyError("Field %s not found" % relative)



More information about the Checkins mailing list