Johan Carlsson
unread,Nov 7, 2009, 1:34:07 PM11/7/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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