[Zope] setting a DTML method's namespace from a product method

Guido A.J. Stevens gyst@nfg.nl
04 Mar 2000 18:40:28 +0100


I'm having some troubles with manipulating the namespace of DTML
methods that are called from methods of product instances.

Some questions:

- How do I provide a DTML method with a full acquisition namespace, as 
if it were called in DTML, when I call it from a product class method?

- Does a REQUEST.set(somevar, somevalue) operation add a variable to
the namespace, or does it re-initialize a new request? I can hardly
imagine the latter.

- Does the local scope of a class method in a product somehow
propagate itself to external DTML methods that are called from that
class method?

Context of my problem:

My product has the following class:

class NFGnav(
	OFS.SimpleItem.Item, 
	Persistent,
	Acquisition.Implicit,
	AccessControl.Role.RoleManager
	): 

which ultimately calls a DTML method:

	  return self.NFGnav_ActiveMapItem(REQUEST)

I can set arguments for the DTML method, no problem:
	  REQUEST.set('NFGnav_ItemTitle', object.title_or_id())
before calling the DTML method works just fine.

However, the DTML method seems to lose it's acquisition context in the 
process. That is, if I define an 'myimage' instance somewhere higher up in
the site hierarchy, I get KeyErrors if I try to call
	<dtml-var myimage>
from the DTML method.

Funny thing is, if I request the URL of the product instance with the
'myimage' appended, this seems to have no problem:
		  /mysite/somefolder/ProductInstance/myimage
returns the image, whereas
		/mysite/somefolder/ProductInstance/someMethod/myimage
gives a KeyError. So the aquisition context seems to be intact at the
product class level, but not at the product class method level. 

I took care to provide (PARENTS, REQUEST) parameters for every class
method invocation, by the way.

I'd appreciate any suggestions in tackling this problem. Is this
question more suited for the zope list or for the zope-dev list, by
the way?


Source for the product is available at
http://www.zope.org/Members/gyst/NFGnav

:*CU#
-- 
***    Guido A.J. Stevens      ***    mailto:gyst@nfg.nl    ***
***    Net Facilities Group    ***    tel:+31.43.3618933    ***
***    http://www.nfg.nl       ***    fax:+31.43.3560502    ***

Communication is not simply imparting information or influence
but creating, representing, and celebrating shared beliefs.
[Coyne, ISBN 0-262-03228-7, p.163]