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

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


Update of /cvs-repository/Zope3/src/zope/app/browser/utilities
In directory cvs.zope.org:/tmp/cvs-serv28091/src/zope/app/browser/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/browser/utilities/schema.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/browser/utilities/schema.py:1.4	Sun Sep 21 13:31:11 2003
+++ Zope3/src/zope/app/browser/utilities/schema.py	Wed Nov 12 13:46:30 2003
@@ -45,14 +45,29 @@
     def update(self):
         status = ''
         container = zapi.getAdapter(self.context, IMutableSchema)
+        request = self.request
 
-        if 'DELETE' in self.request:
-            if not 'ids' in self.request:
+        if 'DELETE' in request:
+            if not 'ids' in request:
                 self.errors = (_("Must select a field to delete"),)
                 status = _("An error occured.")
-            for id in self.request.get('ids', []):
-                container.removeField(id)
-
+            for id in request.get('ids', []):
+                del container[id]
+        elif 'MOVE_UP' in request or 'MOVE_DOWN' in request:
+            up = request.get('MOVE_UP')
+            down = request.get('MOVE_DOWN')
+            name = up or down
+            delta = up and -1 or 1
+            names = self.fieldNames()
+            if name not in names:
+                self.errors = (_("Invalid field name: %s" % name),)
+                status = _("An error occured.")
+            p = names.index(name) + delta
+            try:
+                self.context.moveField(name, p)
+            except IndexError:
+                self.errors = (_("Invalid position: %s" % p),)
+                status = _("An error occured.")
         self.update_status = status
         return status
 




More information about the Zope3-Checkins mailing list