From: Radek Czajka Date: Thu, 6 Oct 2011 10:48:53 +0000 (+0200) Subject: search book list by chunk title, X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/608e6d8048124bd547efca2ce65ea0b7907ff697?ds=inline search book list by chunk title, wider default book list --- 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