Skip to content

Instantly share code, notes, and snippets.

@shazow
Created December 17, 2009 01:44
Show Gist options
  • Save shazow/258443 to your computer and use it in GitHub Desktop.
Save shazow/258443 to your computer and use it in GitHub Desktop.
Insane idea to let plain function actions and more complex callable class actions co-exist. (Now with less profanity.)
class AccountController(BaseController):
class login(BaseAction):
def __call__(self):
if 'username' in request.params:
return self.do_login
# Otherwise...
return self.draw_login
def do_login(self):
# blah blah, try to do the login
if user.is_validated(request.params.get('password')):
# Oh crap, error... do we redirect? Nope. Just Render (tm)
c.errors += ['Wrong pasword. Try again.']
return render('login.mako')
# Otherwise all is good, ok now we can redirect, or render index, or anything.
return redirect_to('/')
def draw_login(self):
c.messages += ['Yo, log in.']
return render('login.mako')
# Callable classes and plain functions can co-exist
def logout(self):
# do logout, whatever
return redirect_to('/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment