本文整理汇总了Python中haystack.query.EmptySearchQuerySet.previous_page_number方法的典型用法代码示例。如果您正苦于以下问题:Python EmptySearchQuerySet.previous_page_number方法的具体用法?Python EmptySearchQuerySet.previous_page_number怎么用?Python EmptySearchQuerySet.previous_page_number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类haystack.query.EmptySearchQuerySet
的用法示例。
在下文中一共展示了EmptySearchQuerySet.previous_page_number方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search
# 需要导入模块: from haystack.query import EmptySearchQuerySet [as 别名]
# 或者: from haystack.query.EmptySearchQuerySet import previous_page_number [as 别名]
def search(request):
"""
Description: Handles requests from site's search bar
Based off haystack.views.basic_search()
Arguments: request: HttpRequest object
Return: HttpResponse object showing search results with following
additional details
- query: search query
- suggestion: backend-suggested search query
Author: Nnoduka Eruchalu
"""
query = ""
results = EmptySearchQuerySet()
suggestion = False
if request.GET.get("q"):
form = SearchForm(request.GET, searchqueryset=None, load_all=True)
if form.is_valid():
query = form.cleaned_data["q"]
results = form.search()
if results.query.backend.include_spelling:
suggestion = form.get_suggestion()
search_list = [r.object for r in results]
paginator = Paginator(search_list, settings.RESULTS_PER_PAGE)
page = request.GET.get("page")
try:
results = paginator.page(page)
except PageNotAnInteger:
# if page is not an integer, deliver first page.
results = paginator.page(1)
except EmptyPage:
# if page is out of range (e.g. 999), deliver last page of results
results = paginator.page(paginator.num_pages)
if results.has_next():
next_page_num = results.next_page_number()
else:
next_page_num = 0 # way of indicating no more pages... 1 index'd helped!
if results.has_previous():
prev_page_num = results.previous_page_number()
else:
prev_page_num = 0
results = results.object_list
return render_to_response(
"search/search.html",
{
"query": query,
"suggestion": suggestion,
"results": results,
"next_page": next_page_num,
"prev_page": prev_page_num,
},
context_instance=RequestContext(request),
)