[Zope] object acquisition via python scripts

Jon Bowlas me at jonbowlas.com
Fri Jul 22 11:43:10 EDT 2005


Many thanks for your help, worked a treat.

Also thanks going out to Malcolm, although he got beat to the solution by
Paul.

-----Original Message-----
From: zope-bounces at zope.org [mailto:zope-bounces at zope.org] On Behalf Of Paul
Winkler
Sent: 22 July 2005 16:21
To: zope at zope.org
Subject: Re: [Zope] object acquisition via python scripts

On Fri, Jul 22, 2005 at 04:10:03PM +0100, Jon Bowlas wrote:
> And my get_attobject script contains the following code:
> 
>  
> 
>       attobjects = context.objectValues('Attributes object')
> 
>       if attobjects:
> 
>             return attobjects[0]
> 
>       return None
> 
(snip)
> But what I'd like to do in this situation is use acquisition to retrieve
the
> values from the parent 'Attributes object' located in the site root. So
> could someone please explain how I could achieve this?

As you've discovered, objectValues() does not use acquisition, it
only looks for real sub-objects of the folder you call it on.
Same is true for objectItems() and objectIds().

This kind of thing is typically done by always using the same id for
your "attributes object". Then just acquire that id.
In a sense, the id becomes part of your API.

Your script would become:
 
attrobject = getattr(context, 'some_id', None)
return attrobject

-- 

Paul Winkler
http://www.slinkp.com
_______________________________________________
Zope maillist  -  Zope at zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )



More information about the Zope mailing list