Reaction not redirection

0 views
Skip to first unread message

Johan Carlsson

unread,
Nov 7, 2009, 1:34:07 PM11/7/09
to Google App Engine Oil
Hi fellow GAEO:ers,
I've made a patch to my local GAEO that I though might fit for
inclusion in the framework.

Background:

I have a custom to name my submit buttons in forms to something like
command_<what ever command this is>
and set the action of that for to "dispatcher".
"dispatcher" is a method on my controller that handles a set of
commands (by looking for them in the params using if statements).
To actually be able to dispatch different commands to different
actions in the controller I figured out I had to modify the template
being called (because regardless of which action method I call the
template "dispatch.html" would be used, and I didn't feel like calling
render manually but leave it up to each action I dispatched to (so fi
I called the action "index" from my dispatch action it would default
to the template "index.html" etc).

So I needed a way to change the template as well as calling the
action with the same name so in my controller base class I added the
following method:

def reaction(self, name):
self.params['action']=name #change the action (and template)
getattr(self, name)() # call the named action

Problem is that the template that gets called (in dispatcher.py) is
based on the route structured parsed in that method (before the
controller is created) and the controller only copies that information
to the params structure.

I solved this by changing the render call in dispatcher to use the
copy (params) instead of the route, both
structures are available in that context (but only params can be
accessed from the actions in the controller).

So in row 168-169 in dispatcher.py I changes this:

ctrl.render(template=route['action'],
values=ctrl.__dict__)

Into this:

ctrl.render(template=ctrl.params['action'],
values=ctrl.__dict__)

As far as I can see this should be backwards compatible, but also
gives me the ability I need.

/Johan

Johan Carlsson

unread,
Nov 7, 2009, 1:42:41 PM11/7/09
to Google App Engine Oil
Ok, I hate that Discard button right now (since it eat my last post).

To explain the subject line a bit.

The redirect method has a benifit over the usual redirect method use
frequently through out gaeo.
1. It doesn't require a round trip to the browser.
2. Any info written to the controller will be retained between call,
in a way redirect lets you chain actions at will.
3. For us that use flash message for error messages etc this can be
written to the controller in any action
and still turn up in the view's context. Using redirects this would
have to be added to a querystring which is
complicated, messy and a bit to public for my taste.

/Johan
Reply all
Reply to author
Forward
0 new messages