fusionbox/django-fusionbox — pull request #23 by chroto (2012-03-07 20:07:38+00:00)
Title: View Decorators

Wrote 2 view wrappers.

`@json_response` takes an iterable and packages a json response. you can also pass custom decoder classes to the decorator `@json_response(MyDatetimeDecoder)`

~~~

@json_response
def myview(request):
return {"a": 1}

=>

HttpResponse(json.dumps({"a": 1}), content_type="application/json")

~~~

`@jsonp` takes an indexable obj (but just use a 2 val tuple ) and packages a jsonp response

~~~
@jsonp
def myview(request):
return "console.log", {"a": 1}

=>

HttpResponse("console.log("+json.dumps({"a": 1})+");", content_type="text/javascript")