[Zope] Acquisition? Did I just lose my Zen?

Jim Fulton jim@digicool.com
Tue, 21 Sep 1999 12:25:10 +0000


Martijn Pieters wrote:
> 
> And I thougt I had it covered....
> 
> I have the following structure:
> 
> /
>    index_html    (checks a cookie, gives
>                   a frameset or a redirect
>                   to /noframes/home (frameset
>                   loads /home))
>    home          (content)
>    standard_html_header (together define my page
>    standard_html_footer  layout)
> 
>    frames/     <- Framesets
>      standard_html_header (define a frameset that
>      standard_html_footer  loads the same URL minus
>      index_html            the /frames prefix)
>      nav                   (navigational frame)
> 
>    noframes/   <- No framesets
>      standard_html_header (define a layout with
>      standard_html_footer  navigation in a table)
>      index_html
> 
> All objects are either Folders or DTML Methods. So far so good, this works
> like charm. With acquisition, the home document can be viewed with and
> without a frameset. See for yourself at:
> 
>    http://mj.antraciet.nl/
> 
> But then I make another Folder, lets say Personal, and define a index_html
> in that Folder:
> 
>    Personal/
>      index_html
> 
> Calling http://mj.antraciet.nl/Personal/ works fine, but when I call
> http://mj.antraciet.nl/frames/Personal/ the same layout appears as the
> previous URL. De standard_html_header and -_footer from the root are being
> used, not the ones in the frames/ Folder! The same goes for noframes/.
> 
> Now either I have to rethink my Zope Zen, or something is very wrong here.

You need to rethink your Zope Zen. :) Here's the explanation.  

When you acquire an object, the acquired object gets the context of
the aquirer *and* the context it was acquired from, with the source
context taking precedence over the destination context.  In the
example above, 'Personal' acquires from the top-level folder first,
and then from the 'frames' folder.

Lets walk through why this is so.  Suppose in Python, we have
a variable 'app' that is the top-level folder.

The expression: 

  app.Personal

Gets 'Personal' in the context of 'app'.

  app.frames

Gets 'frames' in the context if 'app'.  So far so good.

Now consider:

  app.frames.Personal

'Personal' is acquired from 'app'.  We have to get 'app.Personal', 
and then use it in the context of 'app.frames'.  This results in:

  (Personal of app) of (frames of app)

When searching for an attribute, we always search the
innermost contexts first.  In this example, we search
'Personal of app' before we search 'frames of app'.

Jim

--
Jim Fulton           mailto:jim@digicool.com
Technical Director   (888) 344-4332              Python Powered!
Digital Creations    http://www.digicool.com     http://www.python.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.