You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.py 1.2KB

1234567891011121314151617181920212223242526272829303132
  1. from django.conf.urls.defaults import patterns, url
  2. from django.contrib.admin.views.decorators import staff_member_required
  3. from haystack.query import SearchQuerySet
  4. from oscar.core.application import Application
  5. from oscar.apps.search.views import SuggestionsView, MultiFacetedSearchView
  6. from oscar.apps.search.search_indexes import ProductIndex
  7. from oscar.apps.search.forms import MultiFacetedSearchForm
  8. class SearchApplication(Application):
  9. name = 'search'
  10. suggestions_view = SuggestionsView
  11. search_view = MultiFacetedSearchView
  12. def get_urls(self):
  13. sqs = SearchQuerySet()
  14. for field_name, field in ProductIndex.fields.items():
  15. if field.faceted is True:
  16. # Ensure we facet the results set by the defined facetable fields
  17. sqs.facet(field_name)
  18. urlpatterns = patterns('',
  19. url(r'^suggest/$', self.suggestions_view.as_view(), name='suggest'),
  20. url(r'^$', self.search_view(form_class=MultiFacetedSearchForm,
  21. searchqueryset=sqs), name='search'),
  22. )
  23. return self.post_process_urls(urlpatterns)
  24. application = SearchApplication()