@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)
'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)),
except Book.DoesNotExist:
return False
- results = filter(ensure_exists, results)
+ results = [r for r in results if ensure_exists(r)]
return results
except Picture.DoesNotExist:
return False
- results = filter(ensure_exists, results)
+ results = [r for r in results if ensure_exists(r)]
return results