本文整理汇总了Python中haystack.views.SearchView类的典型用法代码示例。如果您正苦于以下问题:Python SearchView类的具体用法?Python SearchView怎么用?Python SearchView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SearchView类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_initial_data
def test_initial_data(self):
sv = SearchView(form_class=InitialedSearchForm)
sv.request = HttpRequest()
form = sv.build_form()
self.assert_(isinstance(form, InitialedSearchForm))
self.assertEqual(form.fields['q'].initial, 'Search for...')
self.assertEqual(form.as_p(), u'<p><label for="id_q">Search:</label> <input type="text" name="q" value="Search for..." id="id_q" /></p>')
示例2: test_initial_data
def test_initial_data(self):
sv = SearchView(form_class=InitialedSearchForm)
sv.request = HttpRequest()
form = sv.build_form()
self.assertTrue(isinstance(form, InitialedSearchForm))
self.assertEqual(form.fields['q'].initial, 'Search for...')
para = form.as_p()
self.assertTrue(u'<label for="id_q">Search:</label>' in para)
self.assertTrue(u'value="Search for..."' in para)
示例3: test_spelling
def test_spelling(self):
# Stow.
from django.conf import settings
old = settings.HAYSTACK_CONNECTIONS['default'].get('INCLUDE_SPELLING', None)
sv = SearchView()
sv.query = 'Nothing'
sv.results = []
sv.build_page = lambda: (None, None)
output = sv.create_response()
# Restore
settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING'] = old
if old is None:
del settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING']
示例4: test_spelling
def test_spelling(self):
# Stow.
from django.conf import settings
old = settings.HAYSTACK_CONNECTIONS["default"].get("INCLUDE_SPELLING", None)
settings.HAYSTACK_CONNECTIONS["default"]["INCLUDE_SPELLING"] = True
sv = SearchView()
sv.query = "Nothing"
sv.results = []
sv.build_page = lambda: (None, None)
sv.create_response()
context = sv.get_context()
self.assertIn(
"suggestion",
context,
msg="Spelling suggestions should be present even if"
" no results were returned",
)
self.assertEqual(context["suggestion"], None)
# Restore
settings.HAYSTACK_CONNECTIONS["default"]["INCLUDE_SPELLING"] = old
if old is None:
del settings.HAYSTACK_CONNECTIONS["default"]["INCLUDE_SPELLING"]
示例5: __call__
def __call__(self, request, slug):
self.slug = slug
try:
return SearchView.__call__(self, request)
except PermissionDenied:
if request.user.is_authenticated():
raise
path = request.build_absolute_uri()
return redirect_to_login(path)
示例6: test_spelling
def test_spelling(self):
# Stow.
from django.conf import settings
old = settings.HAYSTACK_CONNECTIONS['default'].get('INCLUDE_SPELLING', None)
settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING'] = True
sv = SearchView()
sv.query = 'Nothing'
sv.results = []
sv.build_page = lambda: (None, None)
sv.create_response()
context = sv.get_context()
self.assertIn('suggestion', context,
msg='Spelling suggestions should be present even if'
' no results were returned')
self.assertEqual(context['suggestion'], None)
# Restore
settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING'] = old
if old is None:
del settings.HAYSTACK_CONNECTIONS['default']['INCLUDE_SPELLING']
示例7: __call__
def __call__(self, request, slug):
self.slug = slug
return SearchView.__call__(self, request)
示例8: __init__
def __init__(self):
SearchView.__init__(self, form_class=ProjectSearchForm, template='docs/search.html')
示例9: test_empty_results
def test_empty_results(self):
sv = SearchView()
self.assert_(isinstance(sv.get_results(), EmptySearchQuerySet))
示例10: test_empty_results
def test_empty_results(self):
sv = SearchView()
sv.request = HttpRequest()
sv.form = sv.build_form()
self.assertTrue(isinstance(sv.get_results(), EmptySearchQuerySet))