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


Python Query.get方法代码示例

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


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

示例1: auth_get

# 需要导入模块: from wagtail.wagtailsearch.models import Query [as 别名]
# 或者: from wagtail.wagtailsearch.models.Query import get [as 别名]
def auth_get(request):
    # If user is using SSO, do a normal auth check.
    if request.user.is_authenticated():
        return auth(request)

    if 'sso_user' in request.GET and 'sso_shared_id' in request.GET:
        user = shared_id_authenticate(request.GET.get('sso_user'),
            request.GET.get('sso_shared_id'))
        if user:
            response = HttpResponse(json.dumps(
                {'email': user.email, 'shared_id': request.GET.get('sso_shared_id')
                }), content_type='application/json')
            response["X-email"] = user.email
            response["X-shared-id"] = request.GET.get('sso_shared_id')
            return response

    return HttpResponseForbidden() 
开发者ID:parksandwildlife,项目名称:oim-cms,代码行数:19,代码来源:views.py

示例2: draft

# 需要导入模块: from wagtail.wagtailsearch.models import Query [as 别名]
# 或者: from wagtail.wagtailsearch.models.Query import get [as 别名]
def draft(request, path):
    if len(path) > 1:
        if path[-1] == "/":
            path = path[:-1]
        path = "/" + path + "/"
    else:
        path = "/"
    revisions = PageRevision.objects.filter(
        content_json__icontains='"url_path": "/home{}"'.format(path)).order_by("-created_at")
    if revisions.exists() and revisions[
            0].page.get_latest_revision().pk == revisions[0].pk:
        return HttpResponseRedirect("/admin/pages/{}/view_draft/{}".format(
            revisions[0].page.pk, request.META.get("QUERY_STRING")))
    elif revisions.exists():
        return HttpResponse(
            "No current draft ({} old) exists for url: {}".format(revisions.count(), path))
    else:
        return HttpResponse("No draft exists for url: {}".format(path)) 
开发者ID:parksandwildlife,项目名称:oim-cms,代码行数:20,代码来源:views.py

示例3: search

# 需要导入模块: from wagtail.wagtailsearch.models import Query [as 别名]
# 或者: from wagtail.wagtailsearch.models.Query import get [as 别名]
def search(request):
    search_query = request.GET.get('query', None)
    page = request.GET.get('page', 1)

    # Search
    if search_query:
        search_results = Page.objects.live().search(search_query)
        query = Query.get(search_query)

        # Record hit
        query.add_hit()
    else:
        search_results = Page.objects.none()

    # Pagination
    paginator = Paginator(search_results, 10)
    try:
        search_results = paginator.page(page)
    except PageNotAnInteger:
        search_results = paginator.page(1)
    except EmptyPage:
        search_results = paginator.page(paginator.num_pages)

    return render(request, 'search/search.html', {
        'search_query': search_query,
        'search_results': search_results,
    }) 
开发者ID:JuanjoA,项目名称:wagtail-news-time,代码行数:29,代码来源:views.py

示例4: search

# 需要导入模块: from wagtail.wagtailsearch.models import Query [as 别名]
# 或者: from wagtail.wagtailsearch.models.Query import get [as 别名]
def search(request):
    # Search
    search_query = request.GET.get('query', None)
    if search_query:
        search_results = Page.objects.live().search(search_query)
        query = Query.get(search_query)

        # Record hit
        query.add_hit()

        # Get search picks
        search_picks = query.editors_picks.all()
    else:
        search_results = Page.objects.none()
        search_picks = SearchPromotion.objects.none()

    # Pagination
    page = request.GET.get('page', 1)
    paginator = Paginator(search_results, 10)
    try:
        search_results = paginator.page(page)
    except PageNotAnInteger:
        search_results = paginator.page(1)
    except EmptyPage:
        search_results = paginator.page(paginator.num_pages)

    return render(request, 'demo/search_results.html', {
        'search_query': search_query,
        'search_results': search_results,
        'search_picks': search_picks,
    }) 
开发者ID:pgovers,项目名称:oscar-wagtail-demo,代码行数:33,代码来源:views.py

示例5: search

# 需要导入模块: from wagtail.wagtailsearch.models import Query [as 别名]
# 或者: from wagtail.wagtailsearch.models.Query import get [as 别名]
def search(request):
    search_query = request.GET.get('query', None)
    page = request.GET.get('page', 1)

    # Search
    if search_query:
        search_results = Page.objects.live().search(search_query)
        query = Query.get(search_query)

        # Record hit
        query.add_hit()
    else:
        search_results = Page.objects.none()

    # Pagination
    paginator = Paginator(search_results, 10)
    try:
        search_results = paginator.page(page)
    except PageNotAnInteger:
        search_results = paginator.page(1)
    except EmptyPage:
        search_results = paginator.page(paginator.num_pages)

    menus = Menu.objects.all()
    url = WikiHome.objects.first().url

    return render(request, 'search/search.html', {
        'search_query': search_query,
        'search_results': search_results,
        'menus': menus,
        'top_url': url,
    }) 
开发者ID:zr777,项目名称:school-wiki,代码行数:34,代码来源:views.py

示例6: search

# 需要导入模块: from wagtail.wagtailsearch.models import Query [as 别名]
# 或者: from wagtail.wagtailsearch.models.Query import get [as 别名]
def search(request):
    search_query = request.GET.get('query', None)
    page = request.GET.get('page', 1)

    # Search
    if search_query:
        search_results = Page.objects.live().search(search_query)
        query = Query.get(search_query)

        # Record hit
        query.add_hit()
    else:
        search_results = Page.objects.none()

    # Pagination
    paginator = Paginator(search_results, 25)
    try:
        search_results = paginator.page(page)
    except PageNotAnInteger:
        search_results = paginator.page(1)
    except EmptyPage:
        search_results = paginator.page(paginator.num_pages)

    return render(request, 'search/search.html', {
        'search_query': search_query,
        'search_results': search_results,
    }) 
开发者ID:UTNkar,项目名称:moore,代码行数:29,代码来源:views.py

示例7: search_content

# 需要导入模块: from wagtail.wagtailsearch.models import Query [as 别名]
# 或者: from wagtail.wagtailsearch.models.Query import get [as 别名]
def search_content(search_query):
    # Search
    search_results = Content.objects.live().exclude(
        url_path__startswith="/home/snippets/").search(search_query)
    query = Query.get(search_query)
    # Record hit
    query.add_hit()
    return search_results 
开发者ID:parksandwildlife,项目名称:oim-cms,代码行数:10,代码来源:views.py

示例8: search

# 需要导入模块: from wagtail.wagtailsearch.models import Query [as 别名]
# 或者: from wagtail.wagtailsearch.models.Query import get [as 别名]
def search(request):
    search_query = request.GET.get('q', None)
    if search_query:
        search_results = search_content(search_query)
    else:
        search_results = Content.objects.none()

    return render(request, 'core/search_results.html', {
        'search_results': search_results,
    }) 
开发者ID:parksandwildlife,项目名称:oim-cms,代码行数:12,代码来源:views.py

示例9: search

# 需要导入模块: from wagtail.wagtailsearch.models import Query [as 别名]
# 或者: from wagtail.wagtailsearch.models.Query import get [as 别名]
def search(request):
    # Search
    search_query = request.GET.get('q', None)
    if search_query:
        if 'elasticsearch' in settings.WAGTAILSEARCH_BACKENDS['default']['BACKEND']:
            # In production, use ElasticSearch and a simplified search query, per
            # http://docs.wagtail.io/en/v1.12.1/topics/search/backends.html
            # like this:
            search_results = Page.objects.live().search(search_query)
        else:
            # If we aren't using ElasticSearch for the demo, fall back to native db search.
            # But native DB search can't search specific fields in our models on a `Page` query.
            # So for demo purposes ONLY, we hard-code in the model names we want to search.
            blog_results = BlogPage.objects.live().search(search_query)
            blog_page_ids = [p.page_ptr.id for p in blog_results]

            bread_results = BreadPage.objects.live().search(search_query)
            bread_page_ids = [p.page_ptr.id for p in bread_results]

            location_results = LocationPage.objects.live().search(search_query)
            location_result_ids = [p.page_ptr.id for p in location_results]

            page_ids = blog_page_ids + bread_page_ids + location_result_ids
            search_results = Page.objects.live().filter(id__in=page_ids)

        query = Query.get(search_query)

        # Record hit
        query.add_hit()

    else:
        search_results = Page.objects.none()

    # Pagination
    page = request.GET.get('page', 1)
    paginator = Paginator(search_results, 10)
    try:
        search_results = paginator.page(page)
    except PageNotAnInteger:
        search_results = paginator.page(1)
    except EmptyPage:
        search_results = paginator.page(paginator.num_pages)

    return render(request, 'search/search_results.html', {
        'search_query': search_query,
        'search_results': search_results,
    }) 
开发者ID:wagtail,项目名称:bakerydemo,代码行数:49,代码来源:views.py

示例10: auth_ip

# 需要导入模块: from wagtail.wagtailsearch.models import Query [as 别名]
# 或者: from wagtail.wagtailsearch.models.Query import get [as 别名]
def auth_ip(request):
    # Get the IP of the current user, try and match it up to a session.
    current_ip = get_ip(request)

    # If there's a basic auth header, perform a check.
    basic_auth = request.META.get("HTTP_AUTHORIZATION")
    if basic_auth:
        # Check basic auth against Azure AD as an alternative to SSO.
        username, password = base64.b64decode(
            basic_auth.split(" ", 1)[1].strip()).decode('utf-8').split(":", 1)
        username = force_email(username)
        user = shared_id_authenticate(username, password)

        if not user:
            user = adal_authenticate(username, password)

        if user:
            response = HttpResponse(json.dumps(
                {'email': user.email, 'client_logon_ip': current_ip}), content_type='application/json')
            response["X-email"] = user.email
            response["X-client-logon-ip"] = current_ip
            return response

    # If user has a SSO cookie, do a normal auth check.
    if request.user.is_authenticated():
        return auth(request)

    # We can assume that the Session and UserSession tables only contain
    # current sessions.
    qs = UserSession.objects.filter(
        session__isnull=False,
        ip=current_ip).order_by("-session__expire_date")

    headers = {'client_logon_ip': current_ip}

    if qs.exists():
        user = qs[0].user
        headers["email"] = user.email
        try:
            headers["kmi_roles"] = DepartmentUser.objects.get(
                email__iexact=user.email).extra_data.get("KMIRoles", '')
        except:
            headers["kmi_roles"] = ''

    response = HttpResponse(json.dumps(headers), content_type='application/json')
    for key, val in headers.items():
        key = "X-" + key.replace("_", "-")
        response[key] = val

    return response 
开发者ID:parksandwildlife,项目名称:oim-cms,代码行数:52,代码来源:views.py


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