From 8a731e46293ea760b856462b9e82968451e8f36d Mon Sep 17 00:00:00 2001 From: Leif Johansson Date: Tue, 11 Oct 2011 23:20:32 +0200 Subject: support jsonp --- src/meetingtools/apps/room/views.py | 2 +- src/meetingtools/multiresponse.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/meetingtools/apps/room/views.py b/src/meetingtools/apps/room/views.py index 0cc6cbe..59acdba 100644 --- a/src/meetingtools/apps/room/views.py +++ b/src/meetingtools/apps/room/views.py @@ -412,7 +412,7 @@ def list_by_tag(request,tn): title = 'Rooms tagged with %s' % " and ".join(tags) return respond_to(request, {'text/html':'apps/room/list.html', - 'application/json': json_response([_room2dict(room) for room in rooms])}, + 'application/json': json_response([_room2dict(room) for room in rooms],request)}, {'title':title, 'description':title , 'edit':False, diff --git a/src/meetingtools/multiresponse.py b/src/meetingtools/multiresponse.py index 5c58774..077f446 100644 --- a/src/meetingtools/multiresponse.py +++ b/src/meetingtools/multiresponse.py @@ -34,8 +34,15 @@ def make_response_dict(request,d={}): return d -def json_response(data): - r = HttpResponse(simplejson.dumps(data),content_type='application/json') +def json_response(data,request=None): + response_data = None + if request and request.GET.has_key('callback'): + callback = request.GET['callback'] + json = simplejson.dumps(data) + response_data = "%s(%s)" % (callback, json) + else: + response_data = simplejson.dumps(data) + r = HttpResponse(response_data,content_type='application/json') r['Cache-Control'] = 'no-cache, must-revalidate' r['Pragma'] = 'no-cache' -- cgit v1.1