Skip to content

Instantly share code, notes, and snippets.

@david-batranu
Created April 19, 2018 17:33
Show Gist options
  • Save david-batranu/98f38ab9668ed2c244ee276636ebf75b to your computer and use it in GitHub Desktop.
Save david-batranu/98f38ab9668ed2c244ee276636ebf75b to your computer and use it in GitHub Desktop.
Rename and move Plone/Zope objects without triggering events
portal = app['Plone']
catalog = portal['portal_catalog']
src = portal['src_folder']
dst = portal['dst_folder']
orig = [
'name1',
'name2',
]
final = [
'renamed_name_1',
'renamed_name_2',
]
for orig_name, final_name in zip(orig, final):
# extract object and path
ob = src._getOb(orig_name)
uid = '/'.join(ob.getPhysicalPath())
ob = ob.aq_base
# delete and uncatalog
src._delObject(orig_name, suppress_events=True)
catalog.uncatalog_object(uid)
# rename
ob._setId(final_name)
# assign to new container and catalog
dst._setObject(final_name, ob, set_owner=0, suppress_events=True)
ob = dst._getOb(final_name)
# catalog.catalog_object(ob) can't catalog due to indexers, need to do that in the website
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment