[Zope-CMF] ZPT object parent?

Joachim Werner joe@iuveno.de
Tue, 27 Aug 2002 20:20:43 +0200


Hi!

First of all, maybe you should try to get some of this out of ZPT and use a
Script (Python) for preparing the data.

You can get the parent of any object either with object.ac_parent or with
the XML-style object.getParentNode().

For a catalog query, this is a bit more complicated, because you need to get
the actual object first. The catalog only stores the metadata.

so if your object is labeled "object" in the repeat loop, this might work to
get the URL of your object's parent folder:

object.getObject().getParentNode().absolute_url()

If you really only want the link, it is probably more efficient to just
catalog the absolute_url of an object and then do some string operations
like

'/'.join(absolute_url().split('/')[:-1]) to cut off the last part of the
URL.

It is also possible to catalog the partent folder's URL in the catalog, so
you would not have to do any computing at the time of display (any method,
e.g. myParentFolderUrl()), can be written and cataloged by just adding a
corresponding index).

Joachim

----- Original Message -----
From: "J C Lawrence" <claw@kanga.nu>
To: <zope-cmf@zope.org>
Sent: Tuesday, August 27, 2002 7:07 PM
Subject: [Zope-CMF] ZPT object parent?


>
> How do I get the parent folder of an object under ZPT?
>
> I have a ZPT repeat structure that is picking up all the objects of a
> certain criteria in all the folders below a certain point.
>
>     <div tal:repeat="mytype python:here.portal_catalog (
>       Type='MyEntry',
>       path={'query':herePath},
>       sort_on='created',
>       sort_order='reverse')">
>
> When I then loop thru and display each one I want to give a link back to
> the parent folder that contained the object, not my current location
> (which could be many folder levels higher).
>
> (After this is getting the object of the owner of the object)
>
> --
> J C Lawrence
> ---------(*)                Satan, oscillate my metallic sonatas.
> claw@kanga.nu               He lived as a devil, eh?
> http://www.kanga.nu/~claw/  Evil is a name of a foeman, as I live.
>
>
> _______________________________________________
> Zope-CMF maillist  -  Zope-CMF@zope.org
> http://lists.zope.org/mailman/listinfo/zope-cmf
>
> See http://collector.zope.org/CMF for bug reports and feature requests
>
>