[Zope] Naming conventions
Brad Allen
bradallen at mac.com
Sun Nov 30 11:08:21 EST 2003
>On Sat, 2003-11-29 at 12:11, Brad Allen wrote:
>
>> This sounds interesting, but I'm a newbie and am not clear on what
>> you mean here. How do you wrap all non-Python script objects?
>
>*How* is easy. If you have an object my_object you want to "wrap" with
>the Python Script call_my_object, you'd do this:
>
>call_my_object:
>-----
># do other stuff
>return context.my_object(arguments)
>-----
>
>As for *why* you might do this, there any many possible reasons.
>Sometimes it's just cleaner to put scripts in charge of templates than
>vice versa. It's also a good way to ensure that templates are being
>passed sane/validated/correctly-typed arguments. It's much easier to do
>validation work in a script than a template.
>
>HTH,
>
>Dylan
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. 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. So, this is how...I don't fully understand all
the arguments, but it did work when I tried it.
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
The Python script would interpret the "." in ".html" as a object
hierarchy separator.
So what about naming conventions for graphics file types? Should we
still use names like "picture.gif" or "picture.jpg" in the context of
Zope? Web page templates can obviously still make use of files with
these names, but what if I want to refer to a picture from a Python
script? On the other hand, if we start using "picture_jpg" and
"picture_gif" will web browsers still "know" what graphics format is
in these files and how to process them?
More information about the Zope
mailing list