diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-12-09 15:06:40 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2014-12-09 15:06:40 +0100 |
commit | a0210159c9ae7463402b2f2dd02af6e738a28d78 (patch) | |
tree | 56e4a0a36a80d129cf24eb4c7a6d7a8383c13007 /chimere/views.py | |
parent | 50a0f76b1e5a587f5771e88173f0a3796d9b45b1 (diff) | |
download | Chimère-a0210159c9ae7463402b2f2dd02af6e738a28d78.tar.bz2 Chimère-a0210159c9ae7463402b2f2dd02af6e738a28d78.zip |
Work on autocomplete
Diffstat (limited to 'chimere/views.py')
-rw-r--r-- | chimere/views.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/chimere/views.py b/chimere/views.py index 5999af7..0afb6fa 100644 --- a/chimere/views.py +++ b/chimere/views.py @@ -938,8 +938,20 @@ def rss(request, area_name=''): from django.core.paginator import Paginator, InvalidPage SearchView = None +autocomplete = None if hasattr(settings, 'CHIMERE_SEARCH_ENGINE') \ and settings.CHIMERE_SEARCH_ENGINE: from haystack.views import SearchView as HaystackSearchView + from haystack.query import SearchQuerySet class SearchView(HaystackSearchView): pass + def autocomplete(request): + sqs = SearchQuerySet().autocomplete( + content_auto=request.GET.get('q', ''))[:5] + suggestions = [result.object.name for result in sqs] + # make sure it returns a JSON object, not a bare list. + # otherwise, it could be vulnerable to an XSS attack. + the_data = json.dumps({ + 'results': suggestions + }) + return HttpResponse(the_data, content_type='application/json') |