I have a ZClass (testclass) which subclasses DTMLDocument, and within this zclass, I have a script (python) called index_html. Obviously, this script is called each time an instance of testclass is requested. Based on the presence of a query string, I want to either return the document_src (although with a few modifications), or simply return the rendered instance... by this, I mean have all the dtml tags that are in the instance evaluated. So, my question is, how do I make Zope evaluate the dtml tags? Here is what I have so far in my script: ------------ if context.REQUEST.QUERY_STRING == 'editor': print context.raw else: print context return printed ------------ The 'else' statement simply gives me things like, <dtml-var standard_html_header> I also tried 'else: render(context)', which was simply a guess on my part, but I get a Zope error as follows: Error Type: AttributeError Error Value: validate Can anyone enlighten me? Cheers tim
Try this: (!! be careful with excessive recurssion !!) print context.index_html(context,ERQUEST) ----- Original Message ----- From: "Tim Hicks" <tim@sitefusion.co.uk> To: <zope@zope.org> Sent: Wednesday, June 13, 2001 3:39 PM Subject: [Zope] How to make a script return rendered dtml
I have a ZClass (testclass) which subclasses DTMLDocument, and within this zclass, I have a script (python) called index_html. Obviously, this script is called each time an instance of testclass is requested. Based on the presence of a query string, I want to either return the document_src (although with a few modifications), or simply return the rendered instance... by this, I mean have all the dtml tags that are in the instance evaluated. So, my question is, how do I make Zope evaluate the dtml tags?
Here is what I have so far in my script:
------------ if context.REQUEST.QUERY_STRING == 'editor': print context.raw else: print context
return printed ------------
The 'else' statement simply gives me things like,
<dtml-var standard_html_header>
I also tried 'else: render(context)', which was simply a guess on my part, but I get a Zope error as follows:
Error Type: AttributeError Error Value: validate
Can anyone enlighten me?
Cheers
tim
_______________________________________________ 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 )
----- Original Message ----- From: "Peter Bengtsson" <mail@peterbe.com> To: "Tim Hicks" <tim@sitefusion.co.uk> Cc: <zope@zope.org> Sent: Wednesday, June 13, 2001 3:59 PM Subject: Re: [Zope] How to make a script return rendered dtml
Try this:
(!! be careful with excessive recurssion !!)
print context.index_html(context,ERQUEST)
OK, I tried that and got a name error on REQUEST, so I did this instead: print context.index_html(context, context.REQUEST) But that gave me an error like: Error Type: TypeError Error Value: no arguments expected So I tried not supplying any arguments... context.index_html(), and got the 'excessive recursion error'. Any clues? Thanks tim
----- Original Message ----- From: "Tim Hicks" <tim@sitefusion.co.uk> To: <zope@zope.org> Sent: Wednesday, June 13, 2001 3:39 PM Subject: [Zope] How to make a script return rendered dtml
I have a ZClass (testclass) which subclasses DTMLDocument, and within this zclass, I have a script (python) called index_html. Obviously, this script is called each time an instance of testclass is requested. Based on the presence of a query string, I want to either return the document_src (although with a few modifications), or simply return the rendered instance... by this, I mean have all the dtml tags that are in the instance evaluated. So, my question is, how do I make Zope evaluate the dtml tags?
Here is what I have so far in my script:
------------ if context.REQUEST.QUERY_STRING == 'editor': print context.raw else: print context
return printed ------------
The 'else' statement simply gives me things like,
<dtml-var standard_html_header>
I also tried 'else: render(context)', which was simply a guess on my part, but I get a Zope error as follows:
Error Type: AttributeError Error Value: validate
Can anyone enlighten me?
Cheers
tim
_______________________________________________ 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 )
Try this: (!! be careful with excessive recurssion !!) print context.index_html(context,ERQUEST) OK, I tried that and got a name error on REQUEST, so I did this instead: print context.index_html(context, context.REQUEST)
ok. typo by me.
But that gave me an error like:
Error Type: TypeError Error Value: no arguments expected
Is it a DTML Method or DTML Document? I'm positivly sure that you have to pass something. But it could be awefully complicated what and when and why. Experts!? Help. I was working on a Python Script, and I remember that somedtmlobject() never worked but finally did later when I passed context and REQUEST. In mycase it was just a call, and I wasn't interested in what it returned.
So I tried not supplying any arguments... context.index_html(), and got the 'excessive recursion error'.
'excessive recursion error' is good. That means that your Python Script "DTMLcalling" works. It's just a matter of if it returns HTML or text. The excessive recurssion is because you're calling an object that calls the script. Do it with context.bloodyjavascript() or something instead. Peter
Any clues?
Thanks
tim
----- Original Message ----- From: "Tim Hicks" <tim@sitefusion.co.uk> To: <zope@zope.org> Sent: Wednesday, June 13, 2001 3:39 PM Subject: [Zope] How to make a script return rendered dtml
I have a ZClass (testclass) which subclasses DTMLDocument, and within this zclass, I have a script (python) called index_html. Obviously, this script is called each time an instance of testclass is requested. Based on the presence of a query string, I want to either return the document_src (although with a few modifications), or simply return the rendered instance... by this, I mean have all the dtml tags that are in the instance evaluated. So, my question is, how do I make Zope evaluate the dtml tags?
Here is what I have so far in my script:
------------ if context.REQUEST.QUERY_STRING == 'editor': print context.raw else: print context
return printed ------------
The 'else' statement simply gives me things like,
<dtml-var standard_html_header>
I also tried 'else: render(context)', which was simply a guess on my part, but I get a Zope error as follows:
Error Type: AttributeError Error Value: validate
Can anyone enlighten me?
Cheers
tim
_______________________________________________ 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 )
I've cracked it: ------------- print context() return printed ------------- this scriptlet rendered the dtml as I had wanted it to do, with the only problem being that when it came up against a <dtml-var> tag in the zclass (dtml documentish) instance, it looked within the zclass instead of the container of the actual instance. Therefore, I made a guess and found that this worked as I want: ------------- print context(context.aq_parent) return printed ------------- Using this, the acquisition behaves normally again and all is sweet. Thanks very much Peter and Eric for you help. tim ps If you (or anyone) could explain why the second version behaves as it does, that would just be a like having a 'cherry on top' :-).
I'm not sure if this is the best way to do it, but if you want to render a DTML method or DTML document inside a Python script, use the syntax: someDTMLMethod(_.None, _) Eric Balasbas Senior Developer eric@virtosi.com http://www.virtosi.com/ Virtosi Ltd. Design -- Branding -- Zope On Wed, 13 Jun 2001, Tim Hicks wrote:
I have a ZClass (testclass) which subclasses DTMLDocument, and within this zclass, I have a script (python) called index_html. Obviously, this script is called each time an instance of testclass is requested. Based on the presence of a query string, I want to either return the document_src (although with a few modifications), or simply return the rendered instance... by this, I mean have all the dtml tags that are in the instance evaluated. So, my question is, how do I make Zope evaluate the dtml tags?
Here is what I have so far in my script:
------------ if context.REQUEST.QUERY_STRING == 'editor': print context.raw else: print context
return printed ------------
The 'else' statement simply gives me things like,
<dtml-var standard_html_header>
I also tried 'else: render(context)', which was simply a guess on my part, but I get a Zope error as follows:
Error Type: AttributeError Error Value: validate
Can anyone enlighten me?
Cheers
tim
_______________________________________________ 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 )
----- Original Message ----- From: "Eric Balasbas" <ebalasba@bway.net> To: "Tim Hicks" <tim@sitefusion.co.uk> Cc: <zope@zope.org> Sent: Wednesday, June 13, 2001 4:33 PM Subject: Re: [Zope] How to make a script return rendered dtml
I'm not sure if this is the best way to do it, but if you want to render a DTML method or DTML document inside a Python script, use the syntax:
someDTMLMethod(_.None, _)
I tried this: print context(_.None, _) and got this error: Error Type: NameError Error Value: _ So I tried context.id(_.None,_) and got the same. So I tried 'print context(None,_)', with the same error resulting. Finally, I have tried: print context(None,) and got Error Type: KeyError Error Value: standard_html_header This last error at least seems like it's on the right track as it is parsing through the text of the file. What's going wrong, any idea? thanks tim
Eric Balasbas Senior Developer eric@virtosi.com
http://www.virtosi.com/ Virtosi Ltd. Design -- Branding -- Zope
On Wed, 13 Jun 2001, Tim Hicks wrote:
I have a ZClass (testclass) which subclasses DTMLDocument, and within this zclass, I have a script (python) called index_html. Obviously, this script is called each time an instance of testclass is requested. Based on the presence of a query string, I want to either return the document_src (although with a few modifications), or simply return the rendered instance... by this, I mean have all the dtml tags that are in the instance evaluated. So, my question is, how do I make Zope evaluate the dtml tags?
Here is what I have so far in my script:
------------ if context.REQUEST.QUERY_STRING == 'editor': print context.raw else: print context
return printed ------------
The 'else' statement simply gives me things like,
<dtml-var standard_html_header>
I also tried 'else: render(context)', which was simply a guess on my part, but I get a Zope error as follows:
Error Type: AttributeError Error Value: validate
Can anyone enlighten me?
Cheers
tim
_______________________________________________ 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 Tim, Tim Hicks writes:
... Based on the presence of a query string, I want to either return the document_src (although with a few modifications), or simply return the rendered instance ... if context.REQUEST.QUERY_STRING == 'editor': print context.raw else: print context
return printed ------------
The 'else' statement simply gives me things like,
<dtml-var standard_html_header> ... an FAQ. I answered similar questions at least 20 times....
Rendering a DTML object means calling it. If the DTML object needs access to other Zope objects, you must pass the namespace or a client in. Client and namespace are the first two positional arguments of the "__call__" method. More information: URL:http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html Dieter
participants (4)
-
Dieter Maurer -
Eric Balasbas -
Peter Bengtsson -
Tim Hicks