[Zope] How to pass parameter to TALES function?
Skip Montanaro
skip@pobox.com
Wed, 20 Nov 2002 09:48:21 -0600
Suppose I have a list of clients and a list of contacts. Each contact is
associated with a single client. Both the clients list and the possible
contacts lists can be long, though the contacts list will be longer.
I want to create and edit projects for a user-selected client, so I have an
initial selection form which displays all the possible clients. The user
selects one client from the list. That information is then validated in the
passed to the selection action. The overall structure of this part of my
Zope tree looks like so:
/project
/add
/select_form (Formulator
/index_html (ZPT)
/do_select (Python Script)
/add_template (ZPT)
/do_action (Python Script)
/edit
...
/form (Formulator)
The edit functionality isn't yet done. It's there to show that there are
two functions which will share information store in /project/form. Therein
lies the rub. The process goes like this:
1. .../add/index_html displays the contents of .../add/select_form.
2. User selects a client and pokes the submit button.
3. .../add/do_select validates the choice and returns
.../add/add_template, passing it the information it's calculated.
4. add_template displays the contents of .../form.
5. User enters other project information and pokes the submit button.
6. .../add/do_action validates request and creates the project.
I figured out that in step 3 I could stuff the client's id back into the
REQUEST with
container.REQUEST.set("client_id", client_id)
then in step 4 .../form can display a properly abbreviated list of contacts
using something like:
python:form.utils.get_contact_pairs(client=form.REQUEST['client_id'])
This is fine as far as it goes, though it does seem like a kludge to me.
(Is there a better way to pass that information?)
If the user does everything correctly in step 5, we're golden, however, if
he flubs I have a problem. The code to handle an error in step 6 looks like
so:
try:
d = context.form.validate_all(request)
except FormValidationError, errlist:
return context.add.add_template(errlist=errlist.errors)
This is in effect:
try:
validate inputs
except:
goto step 4
Unfortunately, when we get back to step 4 the new REQUEST object doesn't
have a client_id field. At the point where I return in the except clause is
is there a way to stuff the client_id into the new REQUEST object (which I
assume has yet to be created)?
Thanks,
--
Skip Montanaro - skip@pobox.com
http://www.mojam.com/
http://www.musi-cal.com/