Initial changes to support advanced search via haystack
This commit is contained in:
@@ -1,19 +1,14 @@
|
|||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from dynamic_search.api import registered_search_dict
|
from haystack.forms import SearchForm
|
||||||
|
|
||||||
|
from .api import registered_search_dict
|
||||||
|
|
||||||
|
|
||||||
class SearchForm(forms.Form):
|
class AdvancedSearchForm(SearchForm):
|
||||||
q = forms.CharField(max_length=128, label=_(u'Search terms'))
|
|
||||||
source = forms.CharField(
|
|
||||||
max_length=32,
|
|
||||||
required=False,
|
|
||||||
widget=forms.widgets.HiddenInput()
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class AdvancedSearchForm(forms.Form):
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(AdvancedSearchForm, self).__init__(*args, **kwargs)
|
super(AdvancedSearchForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
@@ -23,3 +18,22 @@ class AdvancedSearchForm(forms.Form):
|
|||||||
label=field['title'],
|
label=field['title'],
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def search(self):
|
||||||
|
if not self.is_valid():
|
||||||
|
return self.no_query_found()
|
||||||
|
|
||||||
|
#if not self.cleaned_data.get('q'):
|
||||||
|
# return self.no_query_found()
|
||||||
|
for field in self.fields:
|
||||||
|
print 'field', field
|
||||||
|
#sqs = self.searchqueryset.auto_query(self.cleaned_data['q'])
|
||||||
|
|
||||||
|
if self.load_all:
|
||||||
|
sqs = sqs.load_all()
|
||||||
|
|
||||||
|
return sqs
|
||||||
|
|
||||||
|
def search(self):
|
||||||
|
sqs = super(ModelSearchForm, self).search()
|
||||||
|
return sqs.models(*self.get_models())
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ from django.conf.urls.defaults import patterns, url
|
|||||||
from haystack.forms import SearchForm
|
from haystack.forms import SearchForm
|
||||||
|
|
||||||
from .views import CustomSearchView
|
from .views import CustomSearchView
|
||||||
|
from .forms import AdvancedSearchForm
|
||||||
|
|
||||||
urlpatterns = patterns('dynamic_search.views',
|
urlpatterns = patterns('dynamic_search.views',
|
||||||
url(r'^$', CustomSearchView(form_class=SearchForm), (), 'search'),
|
url(r'^$', CustomSearchView(form_class=SearchForm), (), 'search'),
|
||||||
url(r'^advanced/$', 'search', {'advanced': True}, 'search_advanced'),
|
url(r'^advanced/$', CustomSearchView(form_class=AdvancedSearchForm), (), 'search_advanced'),
|
||||||
url(r'^again/$', 'search_again', (), 'search_again'),
|
url(r'^again/$', 'search_again', (), 'search_again'),
|
||||||
url(r'^results/$', 'results', (), 'results'),
|
url(r'^results/$', 'results', (), 'results'),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user