On Sun, 2003-11-30 at 08:08, Brad Allen wrote:
This idea is a big help to me, and I'll probably restructure my current project as a result. I found a similar example of what you're talking about in the Zope book, p247 under "Calling DTML from Scripts". It fleshes out what arguments need to be passed to a dtml object.
# grab the method and the REQUEST from the context dtml_method = context.a_dtml_method REQUEST = context.REQUEST # call the dtml method, for parameters see below s = dtml_method(client=context, REQUEST=REQUEST, foo='bar') # s now holds the rendered html return s
The Zope book goes on to say that you can add any number of additional "keyword" arguments. In this case, I presume foo is a "keyword" argument.
Yes.
I've been wondering how to pass arguments to dtml documents, since the Zope Management Interface doesn't provide a way to explicitly do it.
That's one way. Another way is to modify the REQUEST object: ----- context.REQUEST['some_var'] = 'foo' return context.some_template(context, REQUEST) -----
So, this is how...I don't fully understand all the arguments, but it did work when I tried it.
It's a bit tricky. The first argument provides the template with a namespace, the second with the other with the request-specific information. Your namespace is essentially a stack of names you can "see" from the current context. It provides much of the information that allows Acquisition to work its magic. The REQUEST contains information specific to each client request: marshalled form/querystring variables, cookie values, etc.
This idea of using scripts to return DTML documents also helps me understand a naming convention I've seen others use: "filename_html" instead of the more traditional "filename.html" for web page files. I guess ".html" would cause a problem for a Python script, wouldn't it?
dtml_method = context.a_dtml_method.html
It causes *some* hassle, yes. But it's hardly that big a deal: In Python: ---- dtml_method = getattr(context, 'some_method.html') return dtml_method(context, REQUEST) ---- In DTML: ---- <dtml-var "_['some_method.html']"> ---- That underscore in the dtml tag is your namespace object... it's roughly the same as "context" in a Python script.
The Python script would interpret the "." in ".html" as a object hierarchy separator.
Normally, yes... that also explains why "-" is unacceptable in a name. Either issue can be resolved using the techniques above.
So what about naming conventions for graphics file types?
It's up to you. The same issues and workarounds apply. The only case where it seems to matter is when you're serving documents that require helper apps in IE (PDF, Word Docs, etc.). Apparently, IE has a nasty habit of opening auxiliary apps based on file suffixes rather than MIME types. Grr... Beyond that, you may wish to consider if you'll use Zope for graphics at all. I concluded a while ago that the benefit of having tags rendered on the fly just isn't worth the overhead. When I need to serve a decent number of static files, I prefer to serve them from Apache. HTH, Dylan