Re: Methods in a Simple Class
Salut Olivier, Did you solve your issue below? If not, please reexplain what you are trying to achieve. If you want to render one of your ZClass with <dtml-var myClass> you may need to subclass "Renderable BaseClass" (available on the Zope site). Or I am barking up the wrong tree? Alexandre At 10:41 09/03/2000 -0800, you wrote:
From: "Olivier Deckmyn" <odeckmyn.list@teaser.fr> Subject: [Zope] Methods in a Simple Class Date: Thu, 9 Mar 2000 18:48:41 +0100
Hi all,
I have built a trivial ZClass : CD (from CDProduct, from the guides).
I try to add a DTML Method "render_short". This method would render the CD Instance on one short line.
My ZClass has simple attributes (artist : string, title : string, description : text)
I would like to be able to write this simple "render_short" DTML method like :
Artist : <dtml-var artist> Title : <dtml-var title> Descr : <dtml-var description fmt="structured-text" newline_to_br>
But when I insert a <dtml_var myCDInstance> in my index_html, I got a exception :
Error Type: KeyError Error Value: artist
There is no typo in my code... How can I access to my ZClass instance attribute from inside its methods ?
Please help me :)
Olivier
Hi Alex :) Nice to see that there is at least ONE good guy that looks at my contributions... So : Yes and No... I've seen the renderable ZClass... but...this is not exactly what I want : I have two (or more) rendering methods ... Sometimes I call one or another, depending on the page I want to render it in... I wanted to write : <dtml-var myClass.render_1> or <dtml-var "myClass.render_1()"> but never works :( The only thing I've found to be working is : <dtml-with myClass> <dtml-var render_1> </dtml-with> pas glop... ----- Message d'origine ----- De : Alexandre Ratti <alex@gabuzomeu.net> À : <zope@zope.org> Cc : Olivier Deckmyn <odeckmyn.list@teaser.fr> Envoyé : mardi 14 mars 2000 13:09 Objet : [Zope] Re: Methods in a Simple Class
Salut Olivier,
Did you solve your issue below? If not, please reexplain what you are trying to achieve.
If you want to render one of your ZClass with <dtml-var myClass> you may need to subclass "Renderable BaseClass" (available on the Zope site).
Or I am barking up the wrong tree?
Alexandre
At 10:41 09/03/2000 -0800, you wrote:
From: "Olivier Deckmyn" <odeckmyn.list@teaser.fr> Subject: [Zope] Methods in a Simple Class Date: Thu, 9 Mar 2000 18:48:41 +0100
Hi all,
I have built a trivial ZClass : CD (from CDProduct, from the guides).
I try to add a DTML Method "render_short". This method would render the CD Instance on one short line.
My ZClass has simple attributes (artist : string, title : string, description : text)
I would like to be able to write this simple "render_short" DTML method like :
Artist : <dtml-var artist> Title : <dtml-var title> Descr : <dtml-var description fmt="structured-text" newline_to_br>
But when I insert a <dtml_var myCDInstance> in my index_html, I got a exception :
Error Type: KeyError Error Value: artist
There is no typo in my code... How can I access to my ZClass instance attribute from inside its methods ?
Please help me :)
Olivier
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Hi Olivier, This sounds like a namespace issue. When using the Python quoted syntax I think you need to enclose the namespace: Could you try this: <dtml-var "myClass.render_1(_.None, _)"> Here are explainations straight from my Zope snippets:
When you call a DTML method in an expression from DTML, you must pass "_.None,_" as the first two parameters if you want the current namespace to pass through. Otherwise, [the DTML method you are calling] will not have access to any variables [or methods] other than 'title' and 'body', period.
Note you could also pass additional variables:
To pass variables to another DTML Method,
<dtml-call "mymethod(_.None, _, var1=5, var2='hello')">
The first two parameters pass along the namespace. After that, you can set other variables that are needed by the method.
Glop ? Alexandre At 15:24 14/03/2000 +0100, Olivier Deckmyn wrote: (...)
I have two (or more) rendering methods ... Sometimes I call one or another, depending on the page I want to render it in...
I wanted to write : <dtml-var myClass.render_1> or <dtml-var "myClass.render_1()">
but never works :( The only thing I've found to be working is : <dtml-with myClass> <dtml-var render_1> </dtml-with>
pas glop...
(...)
Hi Alex... thx again ! so, half glop... Strictly using what you gave me didn't work :( But, after seeking a little, the following works : <dtml-var "myClass.render_1(myClass,_)"> But I really don't like it ! Why doesn't Zope give "self" itself ? As normal python methods do ? Thanx all ! ----- Message d'origine ----- De : Alexandre Ratti <alex@gabuzomeu.net> À : <zope@zope.org> Cc : Olivier Deckmyn <odeckmyn.list@teaser.fr> Envoyé : mardi 14 mars 2000 21:18 Objet : Re: [Zope] Re: Methods in a Simple Class
Hi Olivier,
This sounds like a namespace issue.
When using the Python quoted syntax I think you need to enclose the namespace:
Could you try this:
<dtml-var "myClass.render_1(_.None, _)">
Here are explainations straight from my Zope snippets:
When you call a DTML method in an expression from DTML, you must pass "_.None,_" as the first two parameters if you want the current namespace to pass through. Otherwise, [the DTML method you are calling] will not have access to any variables [or methods] other than 'title' and 'body', period.
Note you could also pass additional variables:
To pass variables to another DTML Method,
<dtml-call "mymethod(_.None, _, var1=5, var2='hello')">
The first two parameters pass along the namespace. After that, you can set other variables that are needed by the method.
Glop ?
Alexandre
At 15:24 14/03/2000 +0100, Olivier Deckmyn wrote: (...)
I have two (or more) rendering methods ... Sometimes I call one or another, depending on the page I want to render it in...
I wanted to write : <dtml-var myClass.render_1> or <dtml-var "myClass.render_1()">
but never works :( The only thing I've found to be working is : <dtml-with myClass> <dtml-var render_1> </dtml-with>
pas glop...
(...)
participants (2)
-
Alexandre Ratti -
Olivier Deckmyn