Content identification (ids)

Description

Different ids, UIDs, integer ids or whatever can identify your Plone content and give access to it.

Id

Content id generally refers the item id within the folder. Together with folder path this identifies the content in unique way.

Naturally, this id changes when the content is renamed or moved.

Use traversing to resolve object by path+id.

UID and UUID

UID is a unique, non-human-readable identifier for a content object which stays on the object even if the object is moved.

Plone uses UUIDs for

  • Storing content-to-content references (Archetypes, ReferenceField)
  • Linking by UIDs (Kupu) - this enables persistent links even though the object is moved
  • Plain UID is supported by Archetypes only and is based on reference_catalog
  • UUID is supported by Archetypes and Dexterity both and you should use this for new projects

UIDs are available for Archetypes content and unified UUIDs for both Archetypes and Dexterity content items since plone.app.dexterity version 1.1.

Note

If you have pre-Dexterity 1.1 content items you must run a migration step in portal_setup to give them UUIDs.

To get object UUID you can use plone.app.uuid package.

Getting object UUID:

from plone.uuid.interfaces import IUUID

# BrowserView helper method
def getUID(self):
    """ AT and Dexterity compatible way to extract UID from a content item """
    # Make sure we don't get UID from parent folder accidentally
    context = self.context.aq_base
    # Returns UID of the context or None if not available
    # Note that UID is always available for all Dexterity 1.1+
    # content and this only can fail if the content is old not migrated
    uuid = IUUID(context, None)
    return uuid

Looking up object by UUID:

Use plone.app.uuid.utils.uuidToObject:

from plone.app.uuid.utils import uuidToObject

...
obj = uuidToObject(uuid)
if not obj:
    # Could not find object
    raise RuntimeError(u"Could not look-up UUID:", uuid)

More info:

intids

Integer ids ("intids") are fast look-up ids provided by plone.app.intid and five.intid packages. Instead of relying on globally unique identifier strings (UIDs) they use 64-bit integers, making low-level resolution faster.

Archetypes

This info only for Plone 3.x projects.

Getting the object's UID

Use UID() accessor function

Example how to get UID of events folder:

>>> site.events.UID()
'ce380ef0f10a85beb864025928e1819b'

Looking up object by UID

Use lookupObject() in reference catalog.

>>> site.reference_catalog.lookupObject('ce380ef0f10a85beb864025928e1819b')
<ATBTreeFolder at /test/events>

None will be returned if there is content item with matching UID (the item has been deleted).




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 Content identification (ids) 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.