-def search(request):
- query = request.GET.get('q', '')
- tags = request.GET.get('tags', '')
- if tags == '':
- tags = []
-
- try:
- tag_list = models.Tag.get_tag_list(tags)
- tag = models.Tag.objects.get(name=query)
- except models.Tag.DoesNotExist:
- try:
- book = models.Book.objects.get(title=query)
- return HttpResponseRedirect(book.get_absolute_url())
- except models.Book.DoesNotExist:
- return HttpResponseRedirect(reverse('catalogue.views.main_page'))
+def _tags_starting_with(prefix, user):
+ books = models.Book.objects.filter(title__icontains=prefix)
+ tags = models.Tag.objects.filter(name__icontains=prefix)
+ if user.is_authenticated():
+ tags = tags.filter(~Q(category='set') | Q(user=user))