0

The five.intid documentation states the following pattern for retrieving the IntID for an object:

from five.intid import site
intids = site.get_intids(app.plone)
intid_obj = intids.getId(app.plone.restrictedTraverse('path/to/object')

Is this the canoncical way also in Plone or is there some helper/utility method available wrapping the code above?

  • Just to note: Are you sure you want to use intids? Last time I asked similar question I got answers intids are not totally supported and you should avoid them... – Mikko Ohtamaa Aug 15 '12 at 08:39
  • @MikkoOhtamaa: it's more that intids have, in the past, caused some problems for us, especially when used in combination with relationships. I've ironed out a few wrinkles since then. – Martijn Pieters Aug 15 '12 at 09:21
  • What is the alternative for using intids? –  Aug 15 '12 at 10:13
  • What is the usecase? IntIds were originally intended for Zope 3, where the object could be retrieved directly without destroying the acquisition chain; in Z2 it needs to store paths too just to be able to rebuild the context, so you could just use paths yourself instead of an intid. – Martijn Pieters Aug 15 '12 at 14:14

1 Answers1

2

I always use:

from zope.component import getUtility
from zope.intid.interfaces import IIntIds

intid = getUtility(IIntIds).getId(object)

as the intid utility is registered with the local component manager.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343