[Zope] restrictedTraverse without acquisition

Jonathan Hobbs toolkit at magma.ca
Tue Jul 13 13:51:59 EDT 2004


From: "R Karthick" <catchkarthick at yahoo.com>
> i have this directory structure
> 
>     /
>     |- clients/projects/abc/batches/001
>     |- wg/projects/cba/batches/100
> 
> now i am running a script python from 001 folder. now
> i want to check whether there is any folder called abc
> in wg/projects folder. i do this by a try statedment
> 
> try:
>    foo = context.restrictedTraverse("wg/projects/abc")
> catch:
>    ... # create the directory
> 
> It goes into the workgroup folder. But when it sees
> the project folder, through acquisition it finds the
> projects folder inside clients hierarchy first and
> finds that the folder abc is actually present.
> 
> I want context.restrictedTraverse to behave in a way
> that it acquire wg but after that projects should not
> be acquired but should follow the wg.

How about something like: (warning - untested)

foo = context.restrictedTraverse("wg/projects")
found = 0
for i in foo.objectItems():
   if str(i[0]) == 'abc':
      found = 1

if not found:
    ... # create the directory


HTH

Jonathan




More information about the Zope mailing list