Transfer request to HTTPFound

20 views
Skip to first unread message

neurino

unread,
Sep 29, 2011, 11:33:55 AM9/29/11
to pylons-discuss
Quickly my need:

each user has a *profile* view (`/profile`) with its _items_ listed in
it.

The list is no more than a POST form with a checkboxes list and
several submit buttons:

- Create new
- Delete selected items
- Compare selected items

While I can:

- Redirect user to *new* view (`/new`) using HTTPFound
- Delete selected items and show again *profile* view

I wish I can accomplish last task in a *compare* view (`/compare`)
without the need to change the form action from `/profile` (or having
two identical forms with just different submit buttons and actions).

Kind of transferring request to the new location.

Is it possible?

Any advice?

Thanks for your support

Mengu

unread,
Sep 29, 2011, 11:54:34 AM9/29/11
to pylons-discuss
can't you do it with AJAX?

Wyatt Baldwin

unread,
Sep 29, 2011, 12:55:27 PM9/29/11
to pylons-...@googlegroups.com
I'm not sure I follow this exactly, but could you create a template fragment (a %def in Mako) that contains the form and then call it with the differentiating args? Something like this:

<%def name="make_form(action, submit_value)">
    <form method="POST" action="${action}">
        <!-- form controls here -->
        <input type="submit" value="${submit_value}" />
    </form>
</%def>

neurino

unread,
Sep 30, 2011, 5:32:15 AM9/30/11
to pylons-discuss
Thanks for replies.

@Mengu:

Well I could simply do it with javascript and change form action on
submit to '/compare' if the submit button clicked is [Compare
selected].

But what about users with js disabled?

@Wyatt:

Consider this sample HTML produced by my already existing template
(beside note: I'm using pyramid_simpleform):

http://jsfiddle.net/AMyjJ/

* Consider New action, when user clicks [New] submit button:

request hits *profile* view ('/profile') and I simply redirect user to
'/new' like this:

if 'new' in request.params:
return HTTPFound(location=request.route_url('new'))

So user can create his new item in *new* view.

* With Compare action things get harder since I cannot only redirect
to *compare* view, I also need to pass ids of selected checkboxes.

Javascript solution I mentioned above is neat (see http://jsfiddle.net/AMyjJ/
) and I could force users with js disabled to go to '/compare' and
make their selections on that page.

What I was wondering is if there's a way to transfer a request to
another **along with redirection from one URI ('/profile') to another
('/compare')**

Thanks for your interest
neurino
Reply all
Reply to author
Forward
0 new messages