From 608e6d8048124bd547efca2ce65ea0b7907ff697 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Thu, 6 Oct 2011 12:48:53 +0200 Subject: [PATCH] search book list by chunk title, wider default book list --- apps/catalogue/templates/catalogue/document_list.html | 4 ++-- apps/catalogue/templatetags/book_list.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/catalogue/templates/catalogue/document_list.html b/apps/catalogue/templates/catalogue/document_list.html index d5343a7d..920f25a6 100644 --- a/apps/catalogue/templates/catalogue/document_list.html +++ b/apps/catalogue/templates/catalogue/document_list.html @@ -4,6 +4,6 @@ {% load catalogue book_list %} -{% block leftcolumn %} +{% block content %} {% book_list %} -{% endblock leftcolumn %} +{% endblock content %} diff --git a/apps/catalogue/templatetags/book_list.py b/apps/catalogue/templatetags/book_list.py index 15654be2..f5b7e647 100755 --- a/apps/catalogue/templatetags/book_list.py +++ b/apps/catalogue/templatetags/book_list.py @@ -71,10 +71,13 @@ def foreign_filter(qs, value, filter_field, model, model_field='slug', unset='-' return qs.filter(**{filter_field: obj}) -def search_filter(qs, value, filter_field): +def search_filter(qs, value, filter_fields): if not value: return qs - return qs.filter(**{"%s__icontains" % filter_field: value}) + q = Q(**{"%s__icontains" % filter_fields[0]: value}) + for field in filter_fields[1:]: + q |= Q(**{"%s__icontains" % field: value}) + return qs.filter(q) _states = [ @@ -106,7 +109,7 @@ def document_list_filter(request, **kwargs): chunks = foreign_filter(chunks, arg_or_GET('user'), 'user', User, 'username') chunks = foreign_filter(chunks, arg_or_GET('stage'), 'stage', Chunk.tag_model, 'slug') - chunks = search_filter(chunks, arg_or_GET('title'), 'book__title') + chunks = search_filter(chunks, arg_or_GET('title'), ['book__title', 'title']) return chunks -- 2.20.1