Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031
  1. from django import forms
  2. from django.utils.translation import ugettext_lazy as _
  3. from django.forms.widgets import Input
  4. from haystack.forms import FacetedSearchForm
  5. class SearchInput(Input):
  6. '''
  7. Defining a search type widget
  8. This is an HTML5 thing and works nicely with Safari, other browsers default
  9. back to using the default "text" type
  10. '''
  11. input_type = 'search'
  12. class MultiFacetedSearchForm(FacetedSearchForm):
  13. '''
  14. An extension of the regular faceted search form to alow for multiple facets
  15. '''
  16. q = forms.CharField(required=False, label=_('Search'), widget=SearchInput({"placeholder": _('Search')}))
  17. def search(self):
  18. '''
  19. Overriding the search method to allow for multiple facets
  20. '''
  21. sqs = super(FacetedSearchForm, self).search()
  22. if hasattr(self, 'cleaned_data') and 'selected_facets' in self.cleaned_data:
  23. for f in self.cleaned_data['selected_facets'].split("|"):
  24. sqs = sqs.narrow(f)
  25. return sqs