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.
63 lines
2.2 KiB
63 lines
2.2 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
|
|
from crispy_forms.layout import Layout, Field, Button
|
|
from django import forms
|
|
from crispy_forms.helper import FormHelper
|
|
from django.urls import reverse_lazy
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from .models import Product
|
|
|
|
|
|
class ProductFilterForm(forms.Form):
|
|
pass
|
|
|
|
class ProductSearchForm(forms.ModelForm):
|
|
field_template = 'bootstrap/forms/product_search.html'
|
|
form_action = reverse_lazy('products:product_search')
|
|
submit_css_class = None
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.submit_css_class = kwargs.pop('submit_css_class')
|
|
|
|
self.helper = FormHelper()
|
|
self.helper.form_action = self.form_action
|
|
self.helper.form_method = 'get'
|
|
self.helper.layout = Layout(
|
|
Field('name', template=self.field_template, placeholder="Поиск программы..."),
|
|
Button(_('search'),value="search", css_class=self.submit_css_class, template=self.field_template)
|
|
)
|
|
super().__init__(*args, **kwargs)
|
|
|
|
class Meta:
|
|
model = Product
|
|
fields = ['name']
|
|
|