I want to be able to introduce the ability to use a callable object as an
action. Something like the following:
####################################################
# The base object makes this a callable. The __call__method on
ValidationActionBase
# will use the start/failure/success methods as needed.
####################################################
class PlayerAddAction(ValidationActionBase):
def start(self):
c.race_options = race_options
return render('/admin/player/edit.mako')
def failure(self, results, errors):
c.race_options = race_options
c.form = FormState(results, errors)
return render('/admin/player/edit.mako')
def success(self, results, errors):
p = models.Player(**results)
Session.add(p)
Session.commit()
h.flash('Player created.')
redirect_to(controller='player_admin', action='index')
class PlayerAdminController(BaseController):
@paginate()
def index(self):
query = player_repo.all()
if 'name' in request.GET:
c.name = request.GET['name']
query = player_repo.search_for_name(request.GET['name'])
c.page = self.pager(query, result_name='players')
return render('/admin/player/index.mako')
##############################
# Here the action is being added to the controller.
##############################
add = PlayerAddAction()
Right now, I'm using a wrapper function that just creates and calls the
method, but I'd really like to be able to use the syntax above. The problem
right now is that pylons assumes that the action will be a method on the
controller, and so when inspecting the arguments it uses the im_func, which
obviously fails on the callable. I was able to change a few lines in the
_inspect_call method of the WSGIController to use func.__class__.im_func
rather than func.im_func, but I'm not sure if this is the best way to go
about it (although it would pass my test).
If I submitted a patch to that effect, could it be done or are there a bunch
of other things that would possibly break?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---