fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Better management of manually-set members.
[wolnelektury.git]
/
src
/
search
/
views.py
diff --git
a/src/search/views.py
b/src/search/views.py
index
2fe94f4
..
da3a767
100644
(file)
--- a/
src/search/views.py
+++ b/
src/search/views.py
@@
-59,8
+59,8
@@
def did_you_mean(query, tokens):
@cache.never_cache
@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)
if len(prefix) < 2:
return JsonResponse([], safe=False)
@@
-92,8
+92,18
@@
def hint(request):
'id': b.id,
'url': b.get_absolute_url()
}
'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)),
callback = request.GET.get('callback', None)
if callback:
return HttpResponse("%s(%s);" % (callback, json.dumps(data)),
@@
-179,7
+189,7
@@
def search_books(query):
except Book.DoesNotExist:
return False
except Book.DoesNotExist:
return False
- results =
filter(ensure_exists, results)
+ results =
[r for r in results if ensure_exists(r)]
return results
return results
@@
-214,7
+224,7
@@
def search_pictures(query):
except Picture.DoesNotExist:
return False
except Picture.DoesNotExist:
return False
- results =
filter(ensure_exists, results)
+ results =
[r for r in results if ensure_exists(r)]
return results
return results