Hi, some days ago I've posted a message asking for help wrt a Python product : dtml-with didn't work with instances of this product. Toby Dickenson answered and gave me what I thought to be the solution : rename the "__call__" method I had defined to "index_html" Now dtml-with works, but dtml-var doesn't (it worked before). In other terms : if I put this in my product class definition : def __call__(self) : ... index_html = None this gives me : <dtml-var MyInstance> ==> renders correctly <dtml-in "objectValues(['MyClass'])"> <dtml-var oneMethod> ==> works correctly </dtml-in> <dtml-with MyInstance> <dtml-var oneMethod> ==> searches oneMethod in the container </dtml-with> and doesn't find it so doesn't work and if I put this instead : def index_html(self) : ... it gives me : <dtml-var MyInstance> ==> renders incorrectly as <MyClass instance at ffeeddcc> <dtml-in "objectValues(['MyClass'])"> <dtml-var oneMethod> ==> works correctly </dtml-in> <dtml-with MyInstance> <dtml-var oneMethod> ==> works correctly </dtml-with> So my question is : is it possible to have the best of both worlds ? I want <dtml-var MyInstance> to render it as HTML, and I want to be able to call some instances methods inside a <dtml-with>. Toby also told me to double quote my instance's id, which works but how can I delete these double quotes and make it still work ? Thanks in advance for any help or pointer. Jerome Alet
On Thursday 25 Jul 2002 9:18 am, Jerome Alet wrote:
Hi,
some days ago I've posted a message asking for help wrt a Python product : dtml-with didn't work with instances of this product.
Toby Dickenson answered and gave me what I thought to be the solution : rename the "__call__" method I had defined to "index_html"
Now dtml-with works, but dtml-var doesn't (it worked before).
Both dtml-with and dtml-var use the same mechanism to compute the value on which they operate. dtml-var stuffs the value into its output, and dtml-with stuffs the value onto the stack. If you need <dtml-var x> to give a string prestentation of the object, and <dtml-with x> to give you access to the object's properties (rather than those of the string) then x needs a __str__ Another option is to add a method which returns the string, so you have to render it as <dtml-var myinstance fmt=mymethod>. You havent really explained that this class is, and what behaviour you want from these different operations, so its hard to give overall good advice.
On Thu, Jul 25, 2002 at 09:43:37AM +0100, Toby Dickenson wrote:
On Thursday 25 Jul 2002 9:18 am, Jerome Alet wrote:
If you need <dtml-var x> to give a string prestentation of the object, and <dtml-with x> to give you access to the object's properties (rather than those of the string) then x needs a __str__
OK, now it really works like I wanted it to work : index_html ==> renders as HTML <dtml-with> ==> access to the object's methods and properties <dtml-var obj> ==> same as index_html For those who might be interested, I've just defined a __str__ method which renders my object as HTML, then defined an index_html method which just returns str(self), and no need for a __call__ method.
Another option is to add a method which returns the string, so you have to render it as <dtml-var myinstance fmt=mymethod>.
No, I wanted to keep it simple to use
You havent really explained that this class is, and what behaviour you want from these different operations, so its hard to give overall good advice.
Yours was very good ! Thank you Jerome Alet
participants (2)
-
Jerome Alet -
Toby Dickenson