On Sun, Sep 7, 2008 at 10:28 AM, Emil <[EMAIL PROTECTED]> wrote:
>
> In controller xyz I create an object and pass it to the xyz.mako
> template as c.foo. When user submits the form created by that
> template, the controller xyz_action handles the form results. But I
> want the object that was passed to the template as c.foo to be
> available in xyz_action. I want xyz_action to be able to look at some
> information that was extracted from the database when the form was
> created, which may of course be different from the state of things
> when the form is submitted.
>
> In other words I want to be able to pass some information from the xyz
> controller instance to the <i>corresponding</i> xyz_action controller
> instance, and also have that information available in xyz.mako in
> between them.
>
> It appears that c.foo is destroyed when the template returns. It's
> not available in xyz_action.
>
> I tried something like "request.POST['foo']=c.foo" in python code in
> the template, but the value stored there is lost when the form is
> submitted.
>
> I thought about using g.foo, but each instantiation of the form has
> its own c.foo object, and there could be multiple instances of the
> form simultaneously being viewed by users. And the user may navigate
> away from the form page without hitting a submit button, in which case
> the c.foo object is no longer valid.
>
> Any suggestions?
The form display and the form submission are two separate requests.
'c' and 'request' are local to the request. There are four ways to
make data available to the submission request.
- Pass it as hidden form fields.
- Put it in the session in the first request and read it in the second
request. This is good for data you don't want the user to see
directory, or that is large. The second request should use
'session.get("the_key")' in case the data isn't there; i.e., if the
form was never requested.
- Pass it in a cookie. This is the most complex way unless you're
familiar with setting cookies directly.
- Store it in the database keyed by the session ID. This is
essentially the same as storing it in the session.
--
Mike Orr <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---