X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d1d6ea8ed2889f871b6d89d4fae6021f286f921a..a409c6cc6901eea44c2cbe3a49038eb21f2db18d:/src/search/views.py diff --git a/src/search/views.py b/src/search/views.py index 3bbe720b0..da3a767f8 100644 --- a/src/search/views.py +++ b/src/search/views.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # @@ -60,8 +59,8 @@ def did_you_mean(query, tokens): @cache.never_cache -def hint(request): - prefix = request.GET.get('term', '') +def hint(request, mozhint=False, param='term'): + prefix = request.GET.get(param, '') if len(prefix) < 2: return JsonResponse([], safe=False) @@ -93,8 +92,18 @@ def hint(request): 'id': b.id, 'url': b.get_absolute_url() } - for b in Book.objects.filter(title__iregex='\m' + prefix)[:limit-len(data)] + for b in Book.objects.filter(findable=True, title__iregex='\m' + prefix)[:limit-len(data)] ] + + if mozhint: + data = [ + prefix, + [ + item['label'] + for item in data + ] + ] + callback = request.GET.get('callback', None) if callback: return HttpResponse("%s(%s);" % (callback, json.dumps(data)), @@ -119,7 +128,7 @@ def main(request): pd_authors = search_pd_authors(query) books = search_books(query) pictures = search_pictures(query) - suggestion = u'' + suggestion = '' if not (books or pictures or pd_authors): form = PublishingSuggestForm(initial={"books": query + ", "}) @@ -180,7 +189,7 @@ def search_books(query): except Book.DoesNotExist: return False - results = filter(ensure_exists, results) + results = [r for r in results if ensure_exists(r)] return results @@ -215,7 +224,7 @@ def search_pictures(query): except Picture.DoesNotExist: return False - results = filter(ensure_exists, results) + results = [r for r in results if ensure_exists(r)] return results