[Zope-Checkins] CVS: Zope/lib/python/OFS - IOrderSupport.py:1.4
OrderSupport.py:1.6
Yvo Schubbe
y.2004_ at wcm-solutions.de
Fri Apr 9 08:26:57 EDT 2004
Update of /cvs-repository/Zope/lib/python/OFS
In directory cvs.zope.org:/tmp/cvs-serv22861/lib/python/OFS
Modified Files:
IOrderSupport.py OrderSupport.py
Log Message:
- added optional 'subset_ids' argument to move methods
=== Zope/lib/python/OFS/IOrderSupport.py 1.3 => 1.4 ===
--- Zope/lib/python/OFS/IOrderSupport.py:1.3 Thu Dec 11 12:39:18 2003
+++ Zope/lib/python/OFS/IOrderSupport.py Fri Apr 9 08:26:26 2004
@@ -25,13 +25,17 @@
collections.
"""
- def moveObjectsByDelta(ids, delta):
+ def moveObjectsByDelta(ids, delta, subset_ids=None):
""" Move specified sub-objects by delta.
If delta is higher than the possible maximum, objects will be moved to
the bottom. If delta is lower than the possible minimum, objects will
be moved to the top.
+ If subset_ids is not None, delta will be interpreted relative to the
+ subset specified by a sequence of ids. The position of objects that
+ are not part of this subset will not be changed.
+
The order of the objects specified by ids will always be preserved. So
if you don't want to change their original order, make sure the order
of ids corresponds to their original order.
@@ -43,7 +47,7 @@
Returns -- Number of moved sub-objects
"""
- def moveObjectsUp(ids, delta=1):
+ def moveObjectsUp(ids, delta=1, subset_ids=None):
""" Move specified sub-objects up by delta in container.
If no delta is specified, delta is 1. See moveObjectsByDelta for more
@@ -54,7 +58,7 @@
Returns -- Number of moved sub-objects
"""
- def moveObjectsDown(ids, delta=1):
+ def moveObjectsDown(ids, delta=1, subset_ids=None):
""" Move specified sub-objects down by delta in container.
If no delta is specified, delta is 1. See moveObjectsByDelta for more
@@ -65,7 +69,7 @@
Returns -- Number of moved sub-objects
"""
- def moveObjectsToTop(ids):
+ def moveObjectsToTop(ids, subset_ids=None):
""" Move specified sub-objects to top of container.
See moveObjectsByDelta for more details.
@@ -75,7 +79,7 @@
Returns -- Number of moved sub-objects
"""
- def moveObjectsToBottom(ids):
+ def moveObjectsToBottom(ids, subset_ids=None):
""" Move specified sub-objects to bottom of container.
See moveObjectsByDelta for more details.
=== Zope/lib/python/OFS/OrderSupport.py 1.5 => 1.6 ===
--- Zope/lib/python/OFS/OrderSupport.py:1.5 Thu Dec 11 12:39:18 2003
+++ Zope/lib/python/OFS/OrderSupport.py Fri Apr 9 08:26:26 2004
@@ -130,68 +130,76 @@
#
security.declareProtected(manage_properties, 'moveObjectsByDelta')
- def moveObjectsByDelta(self, ids, delta):
+ def moveObjectsByDelta(self, ids, delta, subset_ids=None):
""" Move specified sub-objects by delta.
"""
if type(ids) is StringType:
ids = (ids,)
min_position = 0
objects = list(self._objects)
- obj_dict = {}
- for obj in self._objects:
- obj_dict[ obj['id'] ] = obj
+ if subset_ids == None:
+ subset_ids = [ obj['id'] for obj in objects ]
+ else:
+ subset_ids = list(subset_ids)
# unify moving direction
if delta > 0:
ids = list(ids)
ids.reverse()
- objects.reverse()
+ subset_ids.reverse()
counter = 0
for id in ids:
- try:
- object = obj_dict[id]
- except KeyError:
- raise ValueError('The object with the id "%s" does not exist.'
- % id)
- old_position = objects.index(object)
+ old_position = subset_ids.index(id)
new_position = max( old_position - abs(delta), min_position )
if new_position == min_position:
min_position += 1
if not old_position == new_position:
- objects.remove(object)
- objects.insert(new_position, object)
+ subset_ids.remove(id)
+ subset_ids.insert(new_position, id)
counter += 1
if counter > 0:
if delta > 0:
- objects.reverse()
+ subset_ids.reverse()
+ obj_dict = {}
+ for obj in objects:
+ obj_dict[ obj['id'] ] = obj
+ pos = 0
+ for i in range( len(objects) ):
+ if objects[i]['id'] in subset_ids:
+ try:
+ objects[i] = obj_dict[ subset_ids[pos] ]
+ pos += 1
+ except KeyError:
+ raise ValueError('The object with the id "%s" does '
+ 'not exist.' % subset_ids[pos])
self._objects = tuple(objects)
return counter
security.declareProtected(manage_properties, 'moveObjectsUp')
- def moveObjectsUp(self, ids, delta=1):
+ def moveObjectsUp(self, ids, delta=1, subset_ids=None):
""" Move specified sub-objects up by delta in container.
"""
- return self.moveObjectsByDelta(ids, -delta)
+ return self.moveObjectsByDelta(ids, -delta, subset_ids)
security.declareProtected(manage_properties, 'moveObjectsDown')
- def moveObjectsDown(self, ids, delta=1):
+ def moveObjectsDown(self, ids, delta=1, subset_ids=None):
""" Move specified sub-objects down by delta in container.
"""
- return self.moveObjectsByDelta(ids, delta)
+ return self.moveObjectsByDelta(ids, delta, subset_ids)
security.declareProtected(manage_properties, 'moveObjectsToTop')
- def moveObjectsToTop(self, ids):
+ def moveObjectsToTop(self, ids, subset_ids=None):
""" Move specified sub-objects to top of container.
"""
- return self.moveObjectsByDelta( ids, -len(self._objects) )
+ return self.moveObjectsByDelta( ids, -len(self._objects), subset_ids )
security.declareProtected(manage_properties, 'moveObjectsToBottom')
- def moveObjectsToBottom(self, ids):
+ def moveObjectsToBottom(self, ids, subset_ids=None):
""" Move specified sub-objects to bottom of container.
"""
- return self.moveObjectsByDelta( ids, len(self._objects) )
+ return self.moveObjectsByDelta( ids, len(self._objects), subset_ids )
security.declareProtected(manage_properties, 'orderObjects')
def orderObjects(self, key, reverse=None):
More information about the Zope-Checkins
mailing list