container: Python3 fixes
This commit is contained in:
parent
80766f2279
commit
4b84e816b4
2 changed files with 9 additions and 28 deletions
|
@ -12,7 +12,7 @@ Let's add an ordered container and place some objects in it:
|
|||
>>> c1['sub3'] = OrderedContainer()
|
||||
>>> c1['sub4'] = OrderedContainer()
|
||||
>>> c1.keys()
|
||||
[u'sub1', u'sub2', u'sub3', u'sub4']
|
||||
['sub1', 'sub2', 'sub3', 'sub4']
|
||||
|
||||
A special management view provides methods for moving objects down, up,
|
||||
to the bottom, and to the top
|
||||
|
@ -22,14 +22,14 @@ to the bottom, and to the top
|
|||
>>> view = OrderedContainerView(c1, TestRequest())
|
||||
>>> view.move_bottom(('sub3',))
|
||||
>>> c1.keys()
|
||||
[u'sub1', u'sub2', u'sub4', u'sub3']
|
||||
['sub1', 'sub2', 'sub4', 'sub3']
|
||||
>>> view.move_up(('sub4',), 1)
|
||||
>>> c1.keys()
|
||||
[u'sub1', u'sub4', u'sub2', u'sub3']
|
||||
['sub1', 'sub4', 'sub2', 'sub3']
|
||||
>>> view.move_top(('sub2',))
|
||||
>>> c1.keys()
|
||||
[u'sub2', u'sub1', u'sub4', u'sub3']
|
||||
['sub2', 'sub1', 'sub4', 'sub3']
|
||||
>>> view.move_down(('sub2',), 2)
|
||||
>>> c1.keys()
|
||||
[u'sub1', u'sub4', u'sub2', u'sub3']
|
||||
['sub1', 'sub4', 'sub2', 'sub3']
|
||||
|
||||
|
|
|
@ -1,30 +1,11 @@
|
|||
#
|
||||
# Copyright (c) 2011 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# cybertools.util.container.ordered
|
||||
|
||||
"""
|
||||
Ordered container implementation.
|
||||
|
||||
$Id$
|
||||
""" Ordered container implementation.
|
||||
"""
|
||||
|
||||
from zope.app.container.ordered import OrderedContainer as BaseOrderedContainer
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.app.i18n import ZopeMessageFactory as _
|
||||
from zope.i18nmessageid import ZopeMessageFactory as _
|
||||
from zope.interface import Interface
|
||||
from base import ContainerView
|
||||
|
||||
|
@ -75,7 +56,7 @@ def moveByDelta(objs, toMove, delta):
|
|||
if delta < 0:
|
||||
objs = list(reversed(objs))
|
||||
result.reverse()
|
||||
toMove = sorted(toMove, lambda x,y: cmp(objs.index(x), objs.index(y)))
|
||||
toMove = sorted(toMove, key=lambda x: objs.index(x))
|
||||
for element in toMove:
|
||||
newPos = min(len(result), objs.index(element) + abs(delta))
|
||||
result.insert(newPos, element)
|
||||
|
|
Loading…
Add table
Reference in a new issue