示例#1
0
文件: views.py 项目: lidel/mmda
def show_search_result(request, query_type, query_string, query_id):
    """
    Display CachedSearchResult.

    If document is missing create new one using RESTful query redirect.

    @param query_type: a string containing query type
    @param query_string: a string containing query
    @param query_id: a string containing an ID of a CachedSearchResult document

    @return: a HttpResponseRedirect object or rendered search result page
    """
    # TODO: add meta-header for robots: nocahe, norobots etc
    try:
        search_result = CachedSearchResult.get(query_id)
    except ResourceNotFound:
        return HttpResponseRedirect(reverse("create-search-result", args=(query_type, query_string)))

    # SEO check
    seo_query_type = slugify2(search_result.query_type)
    seo_query_string = slugify2(search_result.query_string)
    if query_type != seo_query_type or query_string != seo_query_string:
        return HttpResponseRedirect(reverse("show-search-result", args=(seo_query_type, seo_query_string, query_id)))
    # TODO: if only 1 result, redirect to it directly
    return render_to_response("search/%s_results.html" % search_result.query_type, locals())