[Zope3-checkins] CVS: Zope3/src/zope/app/utilities - schema.py:1.11

Sidnei da Silva cvs-admin at zope.org
Wed Nov 12 13:47:04 EST 2003


Update of /cvs-repository/Zope3/src/zope/app/utilities
In directory cvs.zope.org:/tmp/cvs-serv28091/src/zope/app/utilities

Modified Files:
	schema.py 
Log Message:
Simplify a bit moveField. Add missing interface methods. Add a few more tests to make sure moving up works correctly (it wasn't before this change).


=== Zope3/src/zope/app/utilities/schema.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/utilities/schema.py:1.10	Sat Oct 18 14:56:24 2003
+++ Zope3/src/zope/app/utilities/schema.py	Wed Nov 12 13:46:32 2003
@@ -94,13 +94,11 @@
             raise KeyError, "Field %s already exists." % name
         if not 0 <= position <= len(field_names):
             raise IndexError, "Position %s out of range." % position
-        if fields and position > 0:
-            field.order = fields[position-1].order + 1
-        else:
-            field.order = 1
+        fields.insert(position, field)
         self[name] = field
-        for field in fields[position:]:
-            field.order += 1
+        for p, f in enumerate(fields):
+            if not f.order == p:
+                f.order = p
 
     def moveField(self, name, position):
         """See zope.app.interfaces.utilities.IMutableSchema"""
@@ -112,10 +110,13 @@
         if not 0 <= position <= len(field_names):
             raise IndexError, "Position %s out of range." % position
         index = field_names.index(name)
+        if index == position: return
         field = fields[index]
-        field.order = fields[position-1].order + 1
-        for field in fields[position:]:
-            field.order += 1
+        del fields[index]
+        fields.insert(position, field)
+        for p, f in enumerate(fields):
+            if not f.order == p:
+                f.order = p
 
     def __delitem__(self, name):
         uncontained(self._attrs[name], self, name)




More information about the Zope3-Checkins mailing list