[Zope] How to Defeat Acquisition

ender kthangavelu@earthlink.net
Sat, 10 Mar 2001 03:32:35 -0800


On Saturday 10 March 2001 07:59, Edmund Goppelt wrote:
>>I'd like to create a generic index_html for those folders that I
>>haven't gotten around to creating a custom index_html.
>>
>>So, create the default index_html in the root directory and let
>>acquisition do the heavy lifting, right?
>>
>>But, suppose I want to handle the inbetween case where there's
>>custom text I'd like a folder to display, but not enough to justify
>>writing a custom index_html?
>>
>>How can I get my generic index_html to display the contents of a DTML
>>method guts_html if it exists in a folder, *without* acquiring any
>>guts_html from parent folders?  How do I defeat acquisition and have
>>my generic index_html *only* look in the namespace of the folder it is
>>called on?

there is more than one way to do it.

i'll assume a tree

root
     index_html
     guts_html
    
     folder foo
                  folder bar
	      guts_html
                               folder dice
		       guts_html
    
i think the proper way to do it is going to require a external method,
you can't mess with acquisition in ttw zope because the security machinery 
depends on it, and it would cause problems. in an external method you can 
unwrap the object to get it without acquisition wrappers

something like (untested)
f = folder.aq_base
if hasattr(f, 'guts_html'):
	return f(None, namespace)
else:
	return ''

if the rendering folders have unique properties you can try messing around 
with things in dtml. admittedly this is much more ugly (but then logic in 
dtml always is).

<dtml-if "_.hasattr(this(), getId) and getId()=='foo')">
	
<dtml-else>


i'm haven't used python scripts enough to know of the best way to do it there 
(although i recommend doing the logic in one of them).

in python methods you can actually get at the unwrapped object, but again its 
a security hole.

i'm sure there are other ways to do it.

cheers

kapil

>>Here's the generic index_html I have in my root directory which
>>unfortunately acquires guts_html from folders higher up:
>>
>><dtml-var standard_html_header>
>><h2><dtml-var title></h2>
>>
>><dtml-var folderlist>
>>
>><dtml-var "PARENTS[0].guts_html" missing="">
>>
>><dtml-var standard_html_footer>