[Zope-dev] DTML<->Python confusion (RE: [Zope] How to make a script return rendered dtml)

Bjorn Stabell bjorn@exoweb.net
Thu, 14 Jun 2001 10:28:53 +0800


I've spent hours, maybe days, being confused about this as well.
According to the Zope API documentation and ZDP at

	http://zdp.zope.org/projects/zfaq/faq/DTML/959888072
=09
http://zdp.zope.org/projects/zsnippet/snippets/DTMLTags/CallingDTMLMetho
ds

someDTMLMethod(_.None, _) should work.  Because of the unclear/complex
calling conventions and integration between DTML and Python I've had to
keep some code in DTML.  Other related questions are:

	How do you do dtml-with and dtml-let in a Python script?  (I.e.
put something on the namespace)

	How do you give positional (not keyword) arguments to a DTML
method; is there any difference?

	When is __call__ called, when is __str__ called, and when is
index_html called?  Other basic functions
	worth knowing about for a class/object to be a good-behaving
Zope object?

	When does RESPONSE need to be passed; it can always be gotten
from the REQUEST, right?

	Calling a DTML method, when to use client and when to use
REQUEST?  Is calling with client and
	REQUEST the same as adding client to the namespace (REQUEST) and
calling it with an
	client=3DNone?

	Are namespace, _, REQUEST, and context just different names for
the same thing?

I've been dreaming about a FAQ answering all of this (and a bunch of
ZClasses questions I have).  Me thinks the ZDP should be integrated with
Zope.org, and all Zope.org members given access to add FAQs (I am not
allowed to add FAQs now).  Ideally, somebody should be adding FAQs all
the time, and the FAQ index should be posted regularly to zope-dev...

Btw, I think http://zdp.zope.org/projects/zfaq/faq/DTML/959888072 gets
the order of aMappingObject and aClient wrong in the first code line.

Bye,
--=20
Bjorn


-----Original Message-----
From: Tim Hicks [mailto:tim@sitefusion.co.uk]
Posted At: Thursday, June 14, 2001 00:15
Posted To: Zope List
Conversation: [Zope] How to make a script return rendered dtml
Subject: Re: [Zope] How to make a script return rendered dtml


----- 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 =3D=3D 'editor':
> >     print context.raw
> > else:
> >     print context
> >
> > return printed
> > ------------
> >
> > The 'else' statement simply gives me things like,
> >
> > &lt;dtml-var standard_html_header&gt;
> >
> > 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