Created
November 2, 2012 22:10
-
-
Save ccarpenterg/4004663 to your computer and use it in GitHub Desktop.
A Tornado decorator to display a customized UI for authenticated users.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def customized(default=None, template=None): | |
def decorator(method): | |
@functools.wraps(method) | |
def wrapper(self, *args, **kargs): | |
self.template = default | |
if self.current_user: | |
self.template = template | |
return method(self, *args, **kargs) | |
return wrapper | |
return decorator | |
# Usage example: | |
class MainHandler(tornado.web.RequestHandler): | |
@customized(default='index.html', template='user.index.html') | |
def get(self): | |
self.render(self.template) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment