当前位置: 首页>>代码示例>>Python>>正文


Python EmptySearchQuerySet.has_next方法代码示例

本文整理汇总了Python中haystack.query.EmptySearchQuerySet.has_next方法的典型用法代码示例。如果您正苦于以下问题:Python EmptySearchQuerySet.has_next方法的具体用法?Python EmptySearchQuerySet.has_next怎么用?Python EmptySearchQuerySet.has_next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在haystack.query.EmptySearchQuerySet的用法示例。


在下文中一共展示了EmptySearchQuerySet.has_next方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: search

# 需要导入模块: from haystack.query import EmptySearchQuerySet [as 别名]
# 或者: from haystack.query.EmptySearchQuerySet import has_next [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),
    )
开发者ID:nceruchalu,项目名称:ycp,代码行数:65,代码来源:views.py


注:本文中的haystack.query.EmptySearchQuerySet.has_next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。