Created
October 25, 2011 11:09
-
-
Save atkinson/1312323 to your computer and use it in GitHub Desktop.
Keep top level facet counts when drilling down in haystack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from haystack.views import FacetedSearchView | |
| class StickyFacetedSearchView (FacetedSearchView): | |
| def top_level_facets(self): | |
| """ | |
| When selecting a facet to drill down the results, | |
| we need to keep the top level facet counts | |
| """ | |
| stored_query = self.request.session.get('query', None) | |
| if stored_query != self.query: | |
| self.request.session['query'] = self.query | |
| self.request.session['facet_counts'] = self.results.facet_counts() | |
| return self.request.session['facet_counts'] # Fail loudly | |
| def extra_context(self): | |
| """ add base_facets to extra_context""" | |
| extra = super(StickyFacetedSearchView, self).extra_context() | |
| extra['base_facets'] = self.top_level_facets() | |
| return extra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment