Renaming content

Description

How to programmatically rename Plone content items

Introduction

This page tells how to rename Plone content objects and change their ids.

  • This only concerns URL path ids
  • Archetypes' Unique ID (UID) is not affected by the rename operation
  • Title can be changed using setTitle() (Archetypes) or related mutator

Renaming objects

OFS interface has facilities to rename objects

Warning

Security warning: "Copy or Move" permission is needed on the object by the logged in user.

Warning

New id must be a 8-bit string, not unicode. The system might accept values in invalid format.

Example how to rename object lc to have -old suffix:

id = lc.getId()
if not lc.cb
parent = lc.aq_parent
parent.manage_renameObject(id, id + "-old")

These checks performed before rename by the manage_renameObject():

if not lc.cb_userHasCopyOrMovePermission():
    print "Does not have needed permission"
    return

if not lc.cb_isMoveable():
    # This makes sanity checks whether the object is
    # properly connected to the database
    print "Object problem"
    return

Warning

Testing warning: Rename mechanism relies of Persistent attribute called _p_jar to be present on the content object. By default, this is not the case on unit tests. You need to call transaction.savepoint() to make _p_jar appear on persistent objects.

Unit testing example:

import transaction


self.portal.invokeFactory("Document", doc")
doc = self.portal.doc

# Make sure all persistent objects have _p_jar attribute
transaction.savepoint(optimistic=True)

# Call manage_renameCode()...

Table Of Contents

About Plone

This is documentation for Plone®. Plone is a popular, open source, content management system written in Python programming language.




Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Go to Renaming content on GitHub.
  2. Press Fork and edit this file button.
  3. Edit file contents using GitHub's text editor in your web browserm
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on Github.

For basic information about updating this manual and Sphinx format please see Writing and updating the manual guide.