Created
June 25, 2009 15:49
-
-
Save markng/135936 to your computer and use it in GitHub Desktop.
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 json_callback(view_func): | |
"""if the GET parameter callback is set, wrap response in a function with that name""" | |
def _decorator(request, *args, **kwargs): | |
try: | |
# check for callback, if it's there, modify the return | |
callback = request.GET.__getitem__('callback') | |
response = view_func(request, *args, **kwargs) | |
response.content = callback + '(%s);' % response.content | |
return response | |
except KeyError, e: | |
# callback not found, just return the original function | |
return view_func(request, *args, **kwargs) | |
return _decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment