# HG changeset patch # User Thierry Florac # Date 1540898621 -3600 # Node ID e5dfdb14f9cb54c0101b02cec0c7fbbca142b7f3 # Parent 0c77057e2fa17aaf38b4f81ce766f18d776d8713 Keep order when updating container's object URL's diff -r 0c77057e2fa1 -r e5dfdb14f9cb src/pyams_content/shared/common/zmi/rename.py --- a/src/pyams_content/shared/common/zmi/rename.py Tue Oct 30 11:01:52 2018 +0100 +++ b/src/pyams_content/shared/common/zmi/rename.py Tue Oct 30 12:23:41 2018 +0100 @@ -12,30 +12,26 @@ __docformat__ = 'restructuredtext' +from pyramid.events import subscriber +from z3c.form import field +from z3c.form.interfaces import IDataExtractedEvent +from zope.container.interfaces import IOrderedContainer +from zope.interface import Interface, Invalid +from zope.location.interfaces import ILocation -# import standard library - -# import interfaces from pyams_content.interfaces import MANAGE_SITE_PERMISSION from pyams_content.shared.common.interfaces import ISharedSite from pyams_content.shared.site.interfaces import ISiteFolder from pyams_content.skin.zmi.interfaces import ISiteTreeTable -from pyams_skin.interfaces.viewlet import ITableItemColumnActionsMenu, IContextActions -from pyams_skin.layer import IPyAMSLayer -from z3c.form.interfaces import IDataExtractedEvent -from zope.location.interfaces import ILocation - -# import packages from pyams_form.form import ajax_config from pyams_pagelet.pagelet import pagelet_config +from pyams_skin.interfaces.viewlet import IContextActions, ITableItemColumnActionsMenu +from pyams_skin.layer import IPyAMSLayer from pyams_skin.viewlet.toolbar import ToolbarMenuItem from pyams_utils.unicode import translate_string from pyams_utils.url import absolute_url from pyams_viewlet.viewlet import viewlet_config from pyams_zmi.form import AdminDialogEditForm -from pyramid.events import subscriber -from z3c.form import field -from zope.interface import Interface, Invalid from pyams_content import _ @@ -95,8 +91,14 @@ # revert rename to adjust container properties content.__name__ = old_name parent = content.__parent__ + # memoize keys order before renaming object + order = list(parent.keys()) parent[new_name] = content del parent[old_name] + # restore keys order + if IOrderedContainer.providedBy(parent): + order[order.index(old_name)] = new_name + parent.updateOrder(order) return changes def get_ajax_output(self, changes):