Renames items within an ordered container.
This renamer preserves the original order of the contained items.
To illustrate, we need to setup an IObjectMover, which is used in the renaming:
>>> from zope.app.container.interfaces import IContained >>> gsm = zope.component.getGlobalSiteManager() >>> gsm.registerAdapter(ObjectMover, (IContained, ), IObjectMover)
To rename an item in an ordered container, we instantiate a OrderedContainerItemRenamer with the container:
>>> from zope.app.container.ordered import OrderedContainer >>> container = OrderedContainer() >>> renamer = OrderedContainerItemRenamer(container)
We'll add three items to the container:
>>> container['1'] = 'Item 1'
>>> container['2'] = 'Item 2'
>>> container['3'] = 'Item 3'
>>> container.items()
[('1', 'Item 1'), ('2', 'Item 2'), ('3', 'Item 3')]
When we rename one of the items:
>>> renamer.renameItem('1', 'I')
the order is preserved:
>>> container.items()
[('I', 'Item 1'), ('2', 'Item 2'), ('3', 'Item 3')]
Renaming the other two items also preserves the origina order:
>>> renamer.renameItem('2', 'II')
>>> renamer.renameItem('3', 'III')
>>> container.items()
[('I', 'Item 1'), ('II', 'Item 2'), ('III', 'Item 3')]
As with the standard renamer, trying to rename a non-existent item raises an error:
>>> renamer.renameItem('IV', '4') # doctest:+ELLIPSIS
Traceback (most recent call last):
ItemNotFoundError: (<...OrderedContainer...>, 'IV')
And if the new item name already exists, a DuplicationError is raised:
>>> renamer.renameItem('III', 'I')
Traceback (most recent call last):
DuplicationError: I is already in use
There are no attributes in this class.
renameItem(oldName, newName)
There are no known subclasses.