X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/05d3db941311f20a7131fab8118418c351ba5d3c..0f494f6c2a109155bcdc7057d0e35757cc9cbfb7:/apps/search/views.py?ds=sidebyside diff --git a/apps/search/views.py b/apps/search/views.py index 56eef0976..881815da1 100644 --- a/apps/search/views.py +++ b/apps/search/views.py @@ -18,6 +18,7 @@ from suggest.forms import PublishingSuggestForm from time import sleep import re import enchant +import json dictionary = enchant.Dict('pl_PL') @@ -108,17 +109,23 @@ def hint(request): c = c[len('pd_'):] return _(c) - return JSONResponse( - [{'label': t.name, - 'category': category_name(t.category), - 'id': t.id, - 'url': t.get_absolute_url()} - for t in tags] + \ - [{'label': b.title, - 'category': _('book'), - 'id': b.id, - 'url': b.get_absolute_url()} - for b in books]) + callback = request.GET.get('callback', None) + data = [{'label': t.name, + 'category': category_name(t.category), + 'id': t.id, + 'url': t.get_absolute_url()} + for t in tags] + \ + [{'label': b.title, + 'category': _('book'), + 'id': b.id, + 'url': b.get_absolute_url()} + for b in books] + if callback: + return HttpResponse("%s(%s);" % (callback, json.dumps(data)), + content_type="application/json; charset=utf-8") + else: + return JSONResponse(data) + def main(request):