How to pass parameter to TALES function?
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/
On Wed, Nov 20, 2002 at 09:48:21AM -0600, Skip Montanaro wrote: (snip)
try: d = context.form.validate_all(request) except FormValidationError, errlist: return context.add.add_template(errlist=errlist.errors)
(snip)
Unfortunately, when we get back to step 4 the new REQUEST object doesn't have a client_id field.
So pass it: return context.add.add_template(errlist=errlist.errors, client_id=client_id) ... and in your template, be more flexible about where you get client_id. something like: tal:define="client_id python:REQUEST.get('client_id') or options['client_id']" tal:content="client_id" -- Paul Winkler http://www.slinkp.com "Welcome to Muppet Labs, where the future is made - today!"
>> Unfortunately, when we get back to step 4 the new REQUEST object >> doesn't have a client_id field. Paul> So pass it: ... Paul> ... and in your template, be more flexible about where you get Paul> client_id. something like: ... Thanks. The whole "where things come from and how to get stuff where it needs to be in Zope" is still fairly new to me. Most solutions seem obvious once somebody describes them, but I have a difficult time figuring stuff out from first principles. -- Skip Montanaro - skip@pobox.com http://www.mojam.com/ http://www.musi-cal.com/
On Wed, Nov 20, 2002 at 12:55:48PM -0600, Skip Montanaro wrote:
Thanks. The whole "where things come from and how to get stuff where it needs to be in Zope" is still fairly new to me. Most solutions seem obvious once somebody describes them, but I have a difficult time figuring stuff out from first principles.
well, it is kinda opaque... things are not consistent. For example, you can call a dtml method from python and pass it a REQUEST, but a page template does not accept a REQUEST afaik. in general i'd rather do REQUEST.RESPONSE.redirect('some_url') instead of calling templates from a script, that just feels better... but it doesn't always work because you cannot pass a REQUEST when you do a redirect. I guess you could do something hackish like REQUEST.RESPONSE.redirect('some_url?arg1=foo'). -- Paul Winkler http://www.slinkp.com "Welcome to Muppet Labs, where the future is made - today!"
participants (3)
-
Dieter Maurer -
Paul Winkler -
Skip Montanaro