Created
March 29, 2012 02:48
-
-
Save daltonmatos/2232726 to your computer and use it in GitHub Desktop.
A Simple decorator idea for django views
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
#!/usr/bin/env python | |
def requires_apikey(f): | |
def wrap(req, *args, **kwargs): | |
print "Searching fot an API Key inside {0}...".format(req) | |
return f(req, *args, **kwargs) | |
return wrap | |
def requires_permission(perm): | |
def _wrap(f): | |
def wrap(req, *args, **kwargs): | |
print "Checking permission {0}".format(perm) | |
return f(req, *args, **kwargs) | |
return wrap | |
return _wrap | |
@requires_apikey | |
@requires_permission('userview') | |
@requires_permission('otheruser-view') | |
def user_info(req, username): | |
print "req={0}, username={1}".format(req, username) | |
user_info('request', 'daltonmatos') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment