I have a simple test Zope product inheriting from Cacheable, PropertyManager and SimpleItem. Say I have a dtml method at http://myzopeinstance.com/testdtml with contents <dtml-let myvar="'hello world'"><dtml-var testproduct></dtml-let> I'd like "myvar" to be available in the__call__ method of testproduct. I don't know how to do that. Here's my testproduct __call__ method: def __call__(self, client=None, REQUEST=None, **kw): foo="1. client:"+str(client)+"<BR>" \ +"2. REQUEST:"+str(REQUEST)+"<BR>" \ +"3. kw:"+str(kw)+"<BR>" \ +"4. getattr(..REQUEST..):"+str(getattr(self, "REQUEST", None))+"<BR>" \ +"5. getattr(..client..):"+str(getattr(self, "client", None))+"<BR>" \ +"6. getattr(self, myvar...):"+str(getattr(self, "myvar", None))+ "<BR>" \ +"7. aq_get(self, myvar...):"+str(aq_get(self, "myvar", None))+ "<BR>" return foo
From poking around I was expecting "myvar" to be accessible somewhere from that list either directly or as an attribute of one of the objects, but it's not. Every call (via a web browser) displays None for every line except #4, the getattr(self, "REQUEST", None) statement.
Containment acquisition works more or less the way I would expect, i.e. if myvar is a dtml method in the same folder then the text "hello world" shows up on lines 6 and 7. (I don't understand though why the REQUEST object is always None; I thought when a DTML method calls another object the client and REQUEST parameters are passed in.) I'd appreciate it if someone can explain to me how things work and what I'm doing wrong. ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Wayne Volkmuth wrote:
I have a simple test Zope product inheriting from Cacheable, PropertyManager and SimpleItem.
Say I have a dtml method at http://myzopeinstance.com/testdtml with contents <dtml-let myvar="'hello world'"><dtml-var testproduct></dtml-let>
I'd like "myvar" to be available in the__call__ method of testproduct. I don't know how to do that.
Here's my testproduct __call__ method:
def __call__(self, client=None, REQUEST=None, **kw): foo="1. client:"+str(client)+"<BR>" \ +"2. REQUEST:"+str(REQUEST)+"<BR>" \ +"3. kw:"+str(kw)+"<BR>" \ +"4. getattr(..REQUEST..):"+str(getattr(self, "REQUEST", None))+"<BR>" \ +"5. getattr(..client..):"+str(getattr(self, "client", None))+"<BR>" \ +"6. getattr(self, myvar...):"+str(getattr(self, "myvar", None))+ "<BR>" \ +"7. aq_get(self, myvar...):"+str(aq_get(self, "myvar", None))+ "<BR>" return foo
From poking around I was expecting "myvar" to be accessible somewhere from that list either directly or as an attribute of one of the objects, but it's not. Every call (via a web browser) displays None for every line except #4, the getattr(self, "REQUEST", None) statement.
Two things: - 'myvar' is not defined as an attribute of your object: it is a name in one layer of the DTML namespace, created by the '<dtml-let>'. - Callables referenced by name in a var (e.g., your '<dtml-var testproduct>') are called *without* arguments. To get the mapping passed, you need to implement the method, '__render_with_namespace__', which will then be passed the multi-mapping as an argument. E.g.:: def __render_with_namespace__(self, md): myvar = md['myvar'] # .... Tres. - -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHvle8+gerLs4ltQ4RAmJrAKCV7k8t/9kLzMxNJlqX/uQ7bSDnHwCfdN6i 7bRTszqprybjxx6IgxaK2J8= =atpX -----END PGP SIGNATURE-----
participants (2)
-
Tres Seaver -
Wayne Volkmuth