[Zope] Acquisition problem
Rik Hoekstra
hoekstra@fsw.leidenuniv.nl
Fri, 12 Nov 1999 21:47:33 +0100
From: "Tim Haines" <tim_haines@hotmail.com>
To: <zope@zope.org>
Subject: [Zope] Acquisition problem
Date sent: Fri, 12 Nov 1999 18:13:06 -0000
> Hi there,
>
> I'm having a problem with acquisition. This may have been covered before,
> but searching through the 2000 messages I have, I didn't find it.
>
Believe me, this has been covered many times.
> My problem basically involves the acquisition process not traversing the
> namespace all the way up once it has found a "semi-match". For example:
>
> I have the follow folder structure:
>
> /
> index_html
> show_images
> /images
> bob <image object>
> henry <image object>
> /subfolderhenry
> index_html
> /images
> henry <image object>
>
> My /index_html uses show_images to display /images/bob and /images/henry
>
> I want my /subfolderhenry/index_html to use show_images to show /images/bob
> and /subfolderhenry/images/henry.
>
> When /subfolderhenry/index_html is rendered, the acquisition method goes
> looking for <dtml-var images/bob>. What seems to be happening is that it
> looks in /subfolderhenry/images and doesn't find bob. The problem is that
> it returns an error instead of moving up the tree to look in /images (where
> it would find bob).
>
> Am I mis-understanding the way acquisition should work, or is this a
> problem?
I think you misunderstand acquisition. Generally speaking it builds a
namespace stack of the objects it acquires all the way through the
top. You can follow the general order of the namespace through the
url representation of the objects called. Please remember that what
you describe as directories are actually folder objects to Zope. So
when you call /subfolderhenry/images, internally to Zope you call a
stack of objects root.subfolderhenry.images. So much for theory
In your hierarchy, if asked for subfolderhenry/images/henry Zope goes
looking for an images folder in subfolderhenry and finds one. It does
not find the image (object) henry, because it's not there. However,
as it already found an object called images, it reports a not found
error.
There were people at work who (at first) also thought that
acquisition works in the way that Zope goes looking inside an object
called images, then if has one goes looking for an image (the object
called). If it does not find one, Zope steps back, it 'steps' back
and climbes up the acquisition hierarchy to go looking for other
images objects.
That is _not_ the case, and for many good reasons. If it did (even if
it were technically conceivable), it would produce inpredictable
results and make acquisition even more complicated than it is now
(and believe me, acquisition can be mind boggling at times).
>
> As a work-around I can drop the images directories, and host the images in
> the actual directories. Not a great solution though.
There are more solutions/workarounds, though.
- Ask yourself if you really need an images folder in each folder, or
whether you could do with one images folder somewhere high in the
hierarchy. Then a reference to images from below that point is always
be to the same images folder.
- you can refer to the images folder in the root explicitly:
<dtml-var "PARENTS[-1].images.henry">
(PARENTS[-1] always is the root folder)
- you could name you root images folder 'images' and the images
folder in the henry folder 'Images', as Zope is case sensitive, it
will distinguish them from each other. The only problem is that you
are likely to mix them up.
Hope this helps
Rik