Re: getRawRelatedItems
Alec Mitchell <apm13-WLbs8XpHrcb2fBVCVOL8/[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.archetypes.devel |
|---|---|
| Message-ID | <[email protected]> |
On Wednesday 16 November 2005 12:18 pm, Paul Smith wrote:
> Hey Gang,
> The Related Items field in Plone 2.1 creates a KeywordIndex that
> contains a list of hash-y looking strings that represent the
> referenced objects.
> I'm working on a AT-based content type (a kind-of simple portlet
> manager). My users write TTW content for a portlet, then use a
> RelatedBrowserWidget to choose where in the site the portlet should
> go. I've added a KeywordIndex to the RelatedBrowserWidget field
> (which I call Placement), so now I have a getRawPlacement index in my
> catalog that has those same hash strings.
> Now I've written a portlet that shows up on every page. It looks
> in the catalog for any of my users' portlet-oids that should appear
> on the current page. I'd like to write a query that only returns the
> items that match the current context, and barring that, I'd like to
> be able to find matches from brains' getRawPlacement without having
> to wake up all the objects.
> So. Does anybody know where those strings come from? Can I do
> something with 'context' to see if it corresponds to one of the
> strings in my getRawPlacement index?
They are the UIDs of the referenced objects. You can get the UID for an
archetypes object by doing object.UID(). You can turn a uid into a catalog
brain referencing the acutal object by querying the uid_catalog
("uid_catalog(UID=[uid1, uid2])") (these are uid_catalog brains, so they
offer very little metadata). You can of course turn those into the objects
themselves by doing brain.getObject(). But, unless you want to filter your
references/back-references using some catalog query, you may just want to
use the references API (e.g. context.getRefs and context.getBRefs).
So for your usecase you could just do
"context.getBRefs('placement')" (provided your relationship type is called
'placement'), but that returns full objects (boo), not brains, which is
possibly bad. Because you have an index you can get brains instead by
doing, portal_catalog(getRawPlacement=context.UID()).
Alec
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click