Django haystack - using the common Views function to search

I am trying to convert this code from haystack to urls.py by calling a generic view function, but I get a "function", the object does not have the status_code attribute . I think because it does not return a response object.

hay code:

from django.conf.urls.defaults import *
from haystack.forms import ModelSearchForm, HighlightedSearchForm
from haystack.query import SearchQuerySet
from haystack.views import SearchView

sqs = SearchQuerySet().filter(author='john')

# With threading...
from haystack.views import SearchView, search_view_factory

urlpatterns = patterns('haystack.views',
    url(r'^$', search_view_factory(
        view_class=SearchView,
        template='search/search.html',
        searchqueryset=sqs,
        form_class=HighlightedSearchForm
    ), name='haystack_search'),
)

My new urls.py just calls search () in views.py.

In views.py I have

def search(request):
    sqs = SearchQuerySet().all()
    return search_view_factory(
        view_class=SearchView,
        template='search/search.html',
        searchqueryset=sqs,
        form_class=HighlightedSearchForm
        )

I do this because I want to work a bit with sqs depending on user inputs and status.

Search_view_factory should not return the SearchView class above, it looks like it calls the create_response () function automatically, which returns render_to_response. I tried calling create_response () manually, but that didn't work either.

django-haystack code can be found here.

.

+3
1

search_view_factory HttpResponse, .

def search(request):
    sqs = SearchQuerySet().all()
    view = search_view_factory(
        view_class=SearchView,
        template='search/search.html',
        searchqueryset=sqs,
        form_class=HighlightedSearchForm
        )
    return view(request)

, .

+4

All Articles