Skip to content

Instantly share code, notes, and snippets.

@daltonmatos
Created March 29, 2012 02:48
Show Gist options
  • Save daltonmatos/2232726 to your computer and use it in GitHub Desktop.
Save daltonmatos/2232726 to your computer and use it in GitHub Desktop.
A Simple decorator idea for django views
#!/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