I am trying to export the results of a user's search. I am using Django + Haystack + Solr to produce the search results. Currently, to create the SearchQuerySet
to write out the CSV, I am passing the query parameters from the search results page to the view that produces the CSV and rebuilding the SearchQuerySet
there. This is a real pain because the search is pretty complicated, with facets, multiple models, etc, and there are constantly bugs when I make modifications to the SearchForm
. It seems like there should be an easy way to just pass the results directly to the export view. Any suggestions?
EDIT
I figured out my own solution and put all the modified code in the answer. Please see below. Hopefully this prevents someone else from banging their head against the wall for a week!
Okay, I finally figured this out myself. I basically had to add a second submit button to the html for my
SearchForm
and then used javascript to redirect the action to my "search_export" view. Since facets aren't passed along when the form is submitted, I had to get the facets from the request (in the search page template) and pass those to view rather hackishly through the url. The facets then have to be re-evaluated in the view. I will paste all of my code below:search.html
urls.py
base_tags.py
views.py