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.
31 lines
1.1 KiB
31 lines
1.1 KiB
from haystack.forms import FacetedSearchForm
|
|
|
|
|
|
class FacetedProductSearchForm(FacetedSearchForm):
|
|
def __init__(self, *args, **kwargs):
|
|
data = dict(kwargs.get("data", []))
|
|
self.categories = data.get('category', [])
|
|
self.producers = data.get('producer', [])
|
|
super(FacetedProductSearchForm, self).__init__(*args, **kwargs)
|
|
|
|
def search(self):
|
|
sqs = super(FacetedProductSearchForm, self).search()
|
|
if self.categories:
|
|
query = None
|
|
for category in self.categories:
|
|
if query:
|
|
query += u' OR '
|
|
else:
|
|
query = u''
|
|
query += u'"%s"' % sqs.query.clean(category)
|
|
sqs = sqs.narrow(u'category_exact:%s' % query)
|
|
if self.producers:
|
|
query = None
|
|
for producer in self.producers:
|
|
if query:
|
|
query += u' OR '
|
|
else:
|
|
query = u''
|
|
query += u'"%s"' % sqs.query.clean(producer)
|
|
sqs = sqs.narrow(u'brand_exact:%s' % query)
|
|
return sqs |