Created
May 28, 2010 14:56
-
-
Save fredj/417252 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
from pylons.decorators.util import get_pylons | |
from decorator import decorator | |
from geojson import FeatureCollection, dumps | |
@decorator | |
def geojsonify(func, *args, **kwargs): | |
pylons = get_pylons(args) | |
pylons.response.content_type = 'application/json' | |
data = func(*args, **kwargs) | |
if isinstance(data, list): # sucks !! | |
return dumps(FeatureCollection(data)) | |
else: | |
return dumps(data) |
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
from pylons.decorators.util import get_pylons | |
from decorator import decorator | |
@decorator | |
def jsonp(func, *args, **kwargs): | |
pylons = get_pylons(args) | |
fn_name = pylons.request.params.get('jsonp') or \ | |
pylons.request.params.get('callback') or \ | |
pylons.request.params.get('cb') | |
body = func(*args, **kwargs) | |
pylons.response.charset = 'utf8' | |
if fn_name is not None: | |
response.content_type = 'application/javascript' | |
return "%s(%s);"%(fn_name, body) | |
else: | |
response.content_type = 'application/json' | |
return body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment