Description
Different ids, UIDs, integer ids or whatever can identify your Plone content and give access to it.
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 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
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:
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.
This info only for Plone 3.x projects.
Use UID() accessor function
Example how to get UID of events folder:
>>> site.events.UID()
'ce380ef0f10a85beb864025928e1819b'
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).
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.
For basic information about updating this manual and Sphinx format please see Writing and updating the manual guide.