[Zope] Avoiding acquisition aka testing for contained objects

Johan Carlsson johanc@torped.se
Wed, 15 Nov 2000 14:48:43 +0100


> If I want to know whether a certain object is contained in 
> the current folder I do this:
> 
> <dtml-if "'index_html' in this().objectIds()">
>   yes it's here
> <dtml-else>
>   not here
> </dtml-if>
> 
> Id like to know whether this is the best/most efficient way to do it.
> Things like hasattr() are subject to aquisition i.e. they would find
> an index_html method along the acquisition path; something I do not 
> want. I also cannot bracket everything in a <dtml-with ... only> because
> chopping my namespace is not what I want either.
> 

Stefan,

hasattr(self.aq_base, 'index_html') should probably work.

aq_base returns the unwrapped base object.

There is other aq_wrapper methods as well:
aq_parent (returns the parent wrapper) and aq_self.
I don't really know (of the top of my brain) the differens
between aq_base and aq_self. 
There is however a wiki some where in the Interface section
on Zope.org that tells you more, no link pops in to my mind 
at the moment so you just have to search for it.

I think hasattr() is a better way to look upp attributes but
that's just my 5 cents.

Regards,
Johan Carlsson