[Zope] - newbie questions
Quinn Dunkan
quinn@challenge.calarts.edu
Mon, 25 Jan 1999 16:40:38 -0800
Well, I'm actually using Bobo right now, but this should be applicable to
ZPublisher (here's a question: I understand that bobo users encouraged to
switch to ZPublisher... are there any "issues" to be aware of? Is there a
document that describes how one might make such a switch as painless as
possible?). Anyway, I've been messing around with Bobo for a while now, and
have a few questions:
I have a few email forms that I want a method to pretty up and send to the
appropriate person. Here's how I'm doing it now, but I know there's a Right
Way that involves dtml and all that. I await enlightenment, RTFM, etc.
Unfortunately, I didn't know about REQUEST at the time (and still can't find
any real clear documentation on it...), and so I had to code up my own little
publisher that just calls a python object with a dictionary of the form
values. I have two methods, d_echo() and d_mail() which are called with a
function and a dictionary. They both call the underlying form method which
just prettifies the dictionary data (takes a dictionary and returns a string).
So I can write:
<form action=/cgi-bin/d_echo/mail_forms/mr_form>
and d_echo() will call mail_forms.mr_form(dict) and return whatever it
returns.
Similarly, /cgi-bin/d_mail/mail_forms/mr_form will return "mailed!" and mail
whatever mail_forms.mr_form(dict) returns.
Ok, now that's ugly enough. Now we get to the prettification methods:
My current approach is to say:
def mr_form(a):
msg = untab("""\
%(name)s
%(email)s
%(comments)s
""")
return msg % MsgDict(a)
Where MsgDict wraps a dictionary except returns "fieldname: value" when it
finds the value and "fieldname: (not given)" when it doesn't. Now this
doesn't work when things get marginally more complicated, so if I want
an address printed out right, and not like
address: 123 road
city: centerville (a great place to raise your kids up)
state: etc.
I did this:
def mr_form(a):
msg = untab("""\
%(name)s
Address:
%(adress)s
%(city)s, %(state)s %(zip code)s
""")
dict = {}
for i in "address", "city", "state", "zip code", "country":
if dict.has_key(i):
dict[i] = dict[i]
else:
dict[i] = "(no %s given)" % i
return format(msg % UnionDict(dict, MsgDict(a)))
which is worse yet, but works. UnionDict overlays dictionaries by looking in
each one successively, and format() breaks lines over 70 columns.
Ok, so what's the right way to do this? I may seem stupid for recreating all
sorts of functionality that may already exist in dtml, but I read and read and
read the docs and source-code (even the howto on zope.org for "Creating a Mail
Form", but it assumed I was using full-fledged zope, which I'm not (I'm just
the cgi programmer, I can't switch the whole site to zope even if I'd like
to)). I imagine there are a lot of people in my situation who aren't
designing a brand new site from scratch but would still like to use
ZPublisher/ZTemplate without all the other stuff. I think it would be useful
to have a clearly marked portion of the docs that say "These pertain to
ZP/ZT-only sites." The stuff in "Zope Developer Information" (basically the
old bobo docs) would be good there, perhaps with less scary names.
Here's another question: I know dtml supports both ssi-like and python
string-like syntax, but everyone seems to use the ssi-like. I prefer python
syntax since it looks less cluttered to me (and I think it's a good thing that
my dtmls don't resemble ssi)... is there any particular reason to use one
over the other, or is it purely personal preference?
One of the things Bobo/ZPublisher touts is the ease of using things like pcgi,
fcgi, etc. I've been using fcgi, but I wasn't able to find a cgi-template
style script for it, so I wrote my own. Granted, it was trivial (provided I
did it right), but it would still be nice if it was included, or the
documentation said where I could download it.
thanks!