The old dmtl namespace question
I am sorry to ask the same question again, but I am still completely stumped after many hours of trying and reading. I have:- Folder1 - method1 Folder2 - method2 <- this method calls method3 - method3 When I call an object like this...
From method1 <dtml-call "REQUEST.set('variable','value')"> <- I want to set some variables too <dtml-var "folder2.method2">
The method works perfectly, except that it does not render. When I call it like this....
From method1 <dtml-call "REQUEST.set('variable','value')"> <dtml-var "folder2.method2()">
It seems to have no namespace at all and causes an error (method2 is calling method3 and cant find it.) I have found a few similar posts to the mailing lists and most responses point to.. http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html which I have read over and over and still dont understand. It mentions _.None, and _ but I cant work out how they work. Basically I want method2 to have access to all the methods in folder2 as well as all REQUEST variables. Can someone please show some examples of how to do this. Thanks Tom
On 6/6/01, Tom enlightened me with:
I am sorry to ask the same question again, but I am still completely stumped after many hours of trying and reading.
I have:-
Folder1 - method1 Folder2 - method2 <- this method calls method3 - method3
When I call an object like this...
From method1 <dtml-call "REQUEST.set('variable','value')"> <- I want to set some variables too <dtml-var "folder2.method2">
The method works perfectly, except that it does not render.
When I call it like this....
From method1 <dtml-call "REQUEST.set('variable','value')"> <dtml-var "folder2.method2()">
It seems to have no namespace at all and causes an error (method2 is calling method3 and cant find it.)
here are different ways to call methods: 1. <dtml-var method> 2. <dtml-var "method( _.None, _ )"> 3. <dtml-var "method()"> 4. <dtml-var "method"> 1 and 2 are the same: if you don't put quotes or parens, zope will pass _.None and _ for you. 99.99999% of the time you want to use these. 3 is calling the method, but drops the namespace stuff because the namespace variables are not explicitly included in the args. the parameter list is empty. 4 is well, number 4. watch out for number 4. like you said, it calls, but doesn't render.
I have found a few similar posts to the mailing lists and most responses point to.. http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html which I have read over and over and still dont understand.
It mentions _.None, and _ but I cant work out how they work.
Basically I want method2 to have access to all the methods in folder2 as well as all REQUEST variables.
Can someone please show some examples of how to do this.
do this: <dtml-var "your_method( _.None, _, param='value', param2='value2' )"> my previous reply to "passing parameters to DTML methods" has some discussions and a pointer in the ZDP which i thought were good. check this from dieter: <dtml-let param1="value1" param2="value2" ....> <dtml-XXX method> </dtml-let> david -- David McCuskey david.mccuskey@bigfoot.com
David, Thanks for the help, but I am still stuck. Since I am calling a method in another folder I am a bit stuck. If I use 1. <dtml-var folder2.method2> I get a KeyError error on folder2.method2 So I try 2. <dtml-var "folder2.method2"> But it does not render So I try 3. <dtml-var "folder2.method2()"> But it looses the namespace and I get a KeyError on method3 So I try 4. <dtml-var "folder2.method2( _.None, _ )"> But it behaves the same as 1. So I knock my head on the table and scream! How do I call a method in another folder and have access to its namespace? Tom => -----Original Message----- => From: David McCuskey [mailto:david.mccuskey@bigfoot.com] => Sent: Wednesday, 6 June 2001 1:17 PM => To: tom@mooball.com; Zope Mailing List => Subject: Re: [Zope] The old dmtl namespace question => => => On 6/6/01, Tom enlightened me with: => => >I am sorry to ask the same question again, but I am still => completely stumped => >after many hours of trying and reading. => > => >I have:- => > => >Folder1 => > - method1 => >Folder2 => > - method2 <- this method calls method3 => > - method3 => > => >When I call an object like this... => >>From method1 => ><dtml-call "REQUEST.set('variable','value')"> <- I want to set some => >variables too => ><dtml-var "folder2.method2"> => > => >The method works perfectly, except that it does not render. => > => >When I call it like this.... => >>From method1 => ><dtml-call "REQUEST.set('variable','value')"> => ><dtml-var "folder2.method2()"> => > => >It seems to have no namespace at all and causes an error => (method2 is calling => >method3 and cant find it.) => > => => => here are different ways to call methods: => 1. <dtml-var method> => 2. <dtml-var "method( _.None, _ )"> => 3. <dtml-var "method()"> => 4. <dtml-var "method"> => => => 1 and 2 are the same: if you don't put quotes or parens, zope will pass => _.None and _ for you. 99.99999% of the time you want to use these. => => 3 is calling the method, but drops the namespace stuff because the => namespace variables are not explicitly included in the args. the => parameter list is empty. => => 4 is well, number 4. watch out for number 4. like you said, it calls, but => doesn't render. => => => => => >I have found a few similar posts to the mailing lists and most responses => >point to.. => >http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html => >which I have read over and over and still dont understand. => > => >It mentions _.None, and _ but I cant work out how they work. => > => >Basically I want method2 to have access to all the methods in folder2 as => >well as all REQUEST variables. => > => >Can someone please show some examples of how to do this. => => do this: => => <dtml-var "your_method( _.None, _, param='value', param2='value2' )"> => => => my previous reply to "passing parameters to DTML methods" has some => discussions and a pointer in the ZDP which i thought were good. => => check this from dieter: => => <dtml-let param1="value1" => param2="value2" => ....> => <dtml-XXX method> => </dtml-let> => => david => => -- => David McCuskey => david.mccuskey@bigfoot.com => =>
try: <dtml-with folder2> <dtml-var method2> </dtml-with> then you can also do: <dtml-with folder2> <dtml-var "method2( _.None, _, other=params )"> </dtml-with> the dtml-with ought to work. you're putting folder2 on the namespace stack, and all methods contained within the dtml-with will be called on folder2... which is what you want. sorry i didn't catch that before. let me know if this helps. good thing about the pain is that you'll never forget the lesson. :) i've done this one a lot myself. david On 6/6/01, Tom enlightened me with:
David, Thanks for the help, but I am still stuck. Since I am calling a method in another folder I am a bit stuck.
If I use 1. <dtml-var folder2.method2> I get a KeyError error on folder2.method2 So I try 2. <dtml-var "folder2.method2"> But it does not render So I try 3. <dtml-var "folder2.method2()"> But it looses the namespace and I get a KeyError on method3 So I try 4. <dtml-var "folder2.method2( _.None, _ )"> But it behaves the same as 1. So I knock my head on the table and scream!
How do I call a method in another folder and have access to its namespace?
Tom
=> -----Original Message----- => From: David McCuskey [mailto:david.mccuskey@bigfoot.com] => Sent: Wednesday, 6 June 2001 1:17 PM => To: tom@mooball.com; Zope Mailing List => Subject: Re: [Zope] The old dmtl namespace question => => => On 6/6/01, Tom enlightened me with: => => >I am sorry to ask the same question again, but I am still => completely stumped => >after many hours of trying and reading. => > => >I have:- => > => >Folder1 => > - method1 => >Folder2 => > - method2 <- this method calls method3 => > - method3 => > => >When I call an object like this... => >>From method1 => ><dtml-call "REQUEST.set('variable','value')"> <- I want to set some => >variables too => ><dtml-var "folder2.method2"> => > => >The method works perfectly, except that it does not render. => > => >When I call it like this.... => >>From method1 => ><dtml-call "REQUEST.set('variable','value')"> => ><dtml-var "folder2.method2()"> => > => >It seems to have no namespace at all and causes an error => (method2 is calling => >method3 and cant find it.) => > => => => here are different ways to call methods: => 1. <dtml-var method> => 2. <dtml-var "method( _.None, _ )"> => 3. <dtml-var "method()"> => 4. <dtml-var "method"> => => => 1 and 2 are the same: if you don't put quotes or parens, zope will pass => _.None and _ for you. 99.99999% of the time you want to use these. => => 3 is calling the method, but drops the namespace stuff because the => namespace variables are not explicitly included in the args. the => parameter list is empty. => => 4 is well, number 4. watch out for number 4. like you said, it calls, but => doesn't render. => => => => => >I have found a few similar posts to the mailing lists and most responses => >point to.. => >http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html => >which I have read over and over and still dont understand. => > => >It mentions _.None, and _ but I cant work out how they work. => > => >Basically I want method2 to have access to all the methods in folder2 as => >well as all REQUEST variables. => > => >Can someone please show some examples of how to do this. => => do this: => => <dtml-var "your_method( _.None, _, param='value', param2='value2' )"> => => => my previous reply to "passing parameters to DTML methods" has some => discussions and a pointer in the ZDP which i thought were good. => => check this from dieter: => => <dtml-let param1="value1" => param2="value2" => ....> => <dtml-XXX method> => </dtml-let> => => david => => -- => David McCuskey => david.mccuskey@bigfoot.com => =>
-- David McCuskey david.mccuskey@bigfoot.com
David, Both work, Thanks. The Bruising is settling down now :) Tom => -----Original Message----- => From: David McCuskey [mailto:david.mccuskey@bigfoot.com] => Sent: Wednesday, 6 June 2001 1:58 PM => To: tom@cameron.to; Zope Mailing List => Subject: Re(2): [Zope] The old dmtl namespace question => => => try: => => <dtml-with folder2> => <dtml-var method2> => </dtml-with> => => then you can also do: => <dtml-with folder2> => <dtml-var "method2( _.None, _, other=params )"> => </dtml-with> => => the dtml-with ought to work. you're putting folder2 on the namespace => stack, and all methods contained within the dtml-with will be called on => folder2... which is what you want. => => sorry i didn't catch that before. let me know if this helps. => => => good thing about the pain is that you'll never forget the lesson. :) i've => done this one a lot myself. => => david => => => => On 6/6/01, Tom enlightened me with: => => >David, => >Thanks for the help, but I am still stuck. => >Since I am calling a method in another folder I am a bit stuck. => > => >If I use => >1. <dtml-var folder2.method2> => > I get a KeyError error on folder2.method2 => > So I try => >2. <dtml-var "folder2.method2"> => > But it does not render => > So I try => >3. <dtml-var "folder2.method2()"> => > But it looses the namespace and I get a KeyError on method3 => > So I try => >4. <dtml-var "folder2.method2( _.None, _ )"> => > But it behaves the same as 1. => > So I knock my head on the table and scream! => > => >How do I call a method in another folder and have access to its => namespace? => > => >Tom => > => > => >=> -----Original Message----- => >=> From: David McCuskey [mailto:david.mccuskey@bigfoot.com] => >=> Sent: Wednesday, 6 June 2001 1:17 PM => >=> To: tom@mooball.com; Zope Mailing List => >=> Subject: Re: [Zope] The old dmtl namespace question => >=> => >=> => >=> On 6/6/01, Tom enlightened me with: => >=> => >=> >I am sorry to ask the same question again, but I am still => >=> completely stumped => >=> >after many hours of trying and reading. => >=> > => >=> >I have:- => >=> > => >=> >Folder1 => >=> > - method1 => >=> >Folder2 => >=> > - method2 <- this method calls method3 => >=> > - method3 => >=> > => >=> >When I call an object like this... => >=> >>From method1 => >=> ><dtml-call "REQUEST.set('variable','value')"> <- I want to set some => >=> >variables too => >=> ><dtml-var "folder2.method2"> => >=> > => >=> >The method works perfectly, except that it does not render. => >=> > => >=> >When I call it like this.... => >=> >>From method1 => >=> ><dtml-call "REQUEST.set('variable','value')"> => >=> ><dtml-var "folder2.method2()"> => >=> > => >=> >It seems to have no namespace at all and causes an error => >=> (method2 is calling => >=> >method3 and cant find it.) => >=> > => >=> => >=> => >=> here are different ways to call methods: => >=> 1. <dtml-var method> => >=> 2. <dtml-var "method( _.None, _ )"> => >=> 3. <dtml-var "method()"> => >=> 4. <dtml-var "method"> => >=> => >=> => >=> 1 and 2 are the same: if you don't put quotes or parens, => zope will pass => >=> _.None and _ for you. 99.99999% of the time you want to use these. => >=> => >=> 3 is calling the method, but drops the namespace stuff because the => >=> namespace variables are not explicitly included in the args. the => >=> parameter list is empty. => >=> => >=> 4 is well, number 4. watch out for number 4. like you said, => it calls, but => >=> doesn't render. => >=> => >=> => >=> => >=> => >=> >I have found a few similar posts to the mailing lists and => most responses => >=> >point to.. => >=> >http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html => >=> >which I have read over and over and still dont understand. => >=> > => >=> >It mentions _.None, and _ but I cant work out how they work. => >=> > => >=> >Basically I want method2 to have access to all the methods => in folder2 as => >=> >well as all REQUEST variables. => >=> > => >=> >Can someone please show some examples of how to do this. => >=> => >=> do this: => >=> => >=> <dtml-var "your_method( _.None, _, param='value', param2='value2' )"> => >=> => >=> => >=> my previous reply to "passing parameters to DTML methods" has some => >=> discussions and a pointer in the ZDP which i thought were good. => >=> => >=> check this from dieter: => >=> => >=> <dtml-let param1="value1" => >=> param2="value2" => >=> ....> => >=> <dtml-XXX method> => >=> </dtml-let> => >=> => >=> david => >=> => >=> -- => >=> David McCuskey => >=> david.mccuskey@bigfoot.com => >=> => >=> => => -- => David McCuskey => david.mccuskey@bigfoot.com => =>
You know, I just caught that, and was already starting to write about the context of which he was calling method2 wouldn't work. I had just wrote the code with a dtml-with, but decided to check the list - and here was your message! I'm sure he's grateful for your quicker response though, because that frustrated me the first time I learned that lesson too. Tommy
try:
<dtml-with folder2> <dtml-var method2> </dtml-with>
then you can also do: <dtml-with folder2> <dtml-var "method2( _.None, _, other=params )"> </dtml-with>
the dtml-with ought to work. you're putting folder2 on the namespace stack, and all methods contained within the dtml-with will be called on folder2... which is what you want.
sorry i didn't catch that before. let me know if this helps.
Is there a How-To, or are there some code fragments that will help me use a ZMySQL (or a psycopg) database connection object in an external method? Given that mysql_connection is a ZMySQL database connection object, I expected mysql_connection.db.select_db('database') to work. But I got Error Type: ProgrammingError Error Value: (2014, "Commands out of sync; You can't run this command now") Any help is appreciated. cheers, Luby
On Wed, 6 Jun 2001, Luby Liao wrote:
Is there a How-To, or are there some code fragments that will help me use a ZMySQL (or a psycopg) database connection object in an external method? Given that mysql_connection is a ZMySQL database connection object, I expected
mysql_connection.db.select_db('database')
to work. But I got
Error Type: ProgrammingError Error Value: (2014, "Commands out of sync; You can't run this command now")
This error is generated by either the MySQL client library or perhaps the server itself. Why it failed depends on what you did before-hand. Also, possibly another thread is using the connection at the same time. I suspect that an External Method does not automatically respect any sort of locks that Zope may put on a Connection Object to prevent it's simultaneous use by multiple threads. -- Andy Dustman PGP: 0xC72F3F1D @ .net http://dustman.net/andy "I'd rather listen to Newton than to Mundie. He may have been dead for almost three hundred years, but despite that he stinks up the room less." -- Linus T.
4. <dtml-var "method">
4 is well, number 4. watch out for number 4. like you said, it calls, but doesn't render.
...err, it doesn't call it at all. Anything between double quotes is just normal python. dtml-var dumps a string rendering of whatever the expression evaulates to. In the above example, that's a string representation of a DTML Method object, something like: <DTMLMethod instance at #####> ...which of course looks like a crap HTML tag and so isn't rendered by your web browser, but check the source, it is there... cheers, Chris
participants (7)
-
Andy Dustman -
Chris Withers -
David McCuskey -
Luby Liao -
Tom Cameron -
Tom Cameron -
Tommy Johnson