예제 #1
0
def test_unparse(query):
    result = parser.unparse(query)

    # We can't trivially test that the output is exactly what we expect,
    # because of uncertainty in the ordering of keys. Instead, we check that
    # parsing the result gives us an object equal to the original query.
    assert parser.parse(result) == query
예제 #2
0
def test_unparse(query):
    result = parser.unparse(query)

    # We can't trivially test that the output is exactly what we expect,
    # because of uncertainty in the ordering of keys. Instead, we check that
    # parsing the result gives us an object equal to the original query.
    assert parser.parse(result) == query
예제 #3
0
파일: activity.py 프로젝트: hypothesis/h
def _update_q(params, parsed_query):
    """
    Update the given request params based on the given parsed_query.

    Update the value of the 'q' string in the given request params based on the
    given parsed_query.

    If the query parses to an empty string then ensure that there is no 'q' in
    the given request params, to avoid redirecting the browser to a URL with an
    empty trailing ?q=

    """
    q = parser.unparse(parsed_query)
    if q.strip():
        params["q"] = q
    else:
        params.pop("q", None)
예제 #4
0
파일: activity.py 프로젝트: ssin122/test-h
def _update_q(params, parsed_query):
    """
    Update the given request params based on the given parsed_query.

    Update the value of the 'q' string in the given request params based on the
    given parsed_query.

    If the query parses to an empty string then ensure that there is no 'q' in
    the given request params, to avoid redirecting the browser to a URL with an
    empty trailing ?q=

    """
    q = parser.unparse(parsed_query)
    if q.strip():
        params['q'] = q
    else:
        params.pop('q', None)
예제 #5
0
파일: activity.py 프로젝트: angelicxsoul/h
def toggle_user_facet(request):
    """
    Toggle the given user from the search facets.

    If the search is not already faceted by the userid given in the
    "toggle_user_facet" request param then redirect the browser to the same
    page but with the a facet for this user added to the search query.

    If the search is already faceted by the userid then redirect the browser
    to the same page but with this user facet removed from the search query.

    """
    if not request.feature('search_page'):
        raise httpexceptions.HTTPNotFound()

    userid = request.POST['toggle_user_facet']
    username = util.user.split_user(userid)['username']

    new_params = request.POST.copy()

    del new_params['toggle_user_facet']

    parsed_query = _parsed_query(request)
    if _faceted_by_user(request, username, parsed_query):
        # The search query is already faceted by the given user,
        # so remove that user facet.
        username_facets = _username_facets(request, parsed_query)
        username_facets.remove(username)
        if username_facets:
            parsed_query['user'] = username_facets
        else:
            del parsed_query['user']
    else:
        # The search query is not yet faceted by the given user, so add a facet
        # for the user.
        parsed_query.add('user', username)

    new_params['q'] = parser.unparse(parsed_query)

    location = request.route_url('activity.group_search',
                                 pubid=request.matchdict['pubid'],
                                 _query=new_params)

    return httpexceptions.HTTPSeeOther(location=location)
예제 #6
0
파일: activity.py 프로젝트: nlisgo/h
def toggle_user_facet(request):
    """
    Toggle the given user from the search facets.

    If the search is not already faceted by the userid given in the
    "toggle_user_facet" request param then redirect the browser to the same
    page but with the a facet for this user added to the search query.

    If the search is already faceted by the userid then redirect the browser
    to the same page but with this user facet removed from the search query.

    """
    if not request.feature('search_page'):
        raise httpexceptions.HTTPNotFound()

    userid = request.POST['toggle_user_facet']
    username = util.user.split_user(userid)['username']

    new_params = request.POST.copy()

    del new_params['toggle_user_facet']

    parsed_query = _parsed_query(request)
    if _faceted_by_user(request, username, parsed_query):
        # The search query is already faceted by the given user,
        # so remove that user facet.
        username_facets = _username_facets(request, parsed_query)
        username_facets.remove(username)
        del parsed_query['user']
        for username_facet in username_facets:
            parsed_query.add('user', username_facet)
    else:
        # The search query is not yet faceted by the given user, so add a facet
        # for the user.
        parsed_query.add('user', username)

    new_params['q'] = parser.unparse(parsed_query)

    location = request.route_url('activity.group_search',
                                 pubid=request.matchdict['pubid'],
                                 _query=new_params)

    return httpexceptions.HTTPSeeOther(location=location)
예제 #7
0
파일: activity.py 프로젝트: angelicxsoul/h
def toggle_tag_facet(request):
    """
    Toggle the given tag from the search facets.

    If the search is not already faceted by the tag given in the
    "toggle_tag_facet" request param then redirect the browser to the same
    page but with the a facet for this  added to the search query.

    If the search is already faceted by the tag then redirect the browser
    to the same page but with this facet removed from the search query.

    """
    if not request.feature('search_page'):
        raise httpexceptions.HTTPNotFound()

    tag = request.POST['toggle_tag_facet']

    new_params = request.POST.copy()

    del new_params['toggle_tag_facet']

    parsed_query = _parsed_query(request)
    if _faceted_by_tag(request, tag, parsed_query):
        # The search query is already faceted by the given tag,
        # so remove that tag facet.
        tag_facets = _tag_facets(request, parsed_query)
        tag_facets.remove(tag)
        if tag_facets:
            parsed_query['tag'] = tag_facets
        else:
            del parsed_query['tag']
    else:
        # The search query is not yet faceted by the given tag, so add a facet
        # for the tag.
        parsed_query.add('tag', tag)

    new_params['q'] = parser.unparse(parsed_query)
    return _redirect_to_user_or_group_search(request, new_params)
예제 #8
0
파일: activity.py 프로젝트: nlisgo/h
def toggle_tag_facet(request):
    """
    Toggle the given tag from the search facets.

    If the search is not already faceted by the tag given in the
    "toggle_tag_facet" request param then redirect the browser to the same
    page but with the a facet for this  added to the search query.

    If the search is already faceted by the tag then redirect the browser
    to the same page but with this facet removed from the search query.

    """
    if not request.feature('search_page'):
        raise httpexceptions.HTTPNotFound()

    tag = request.POST['toggle_tag_facet']

    new_params = request.POST.copy()

    del new_params['toggle_tag_facet']

    parsed_query = _parsed_query(request)
    if _faceted_by_tag(request, tag, parsed_query):
        # The search query is already faceted by the given tag,
        # so remove that tag facet.
        tag_facets = _tag_facets(request, parsed_query)
        tag_facets.remove(tag)
        del parsed_query['tag']
        for tag_facet in tag_facets:
            parsed_query.add('tag', tag_facet)
    else:
        # The search query is not yet faceted by the given tag, so add a facet
        # for the tag.
        parsed_query.add('tag', tag)

    new_params['q'] = parser.unparse(parsed_query)
    return _redirect_to_user_or_group_search(request, new_params)
예제 #9
0
파일: activity.py 프로젝트: nlisgo/h
 def tag_link(tag):
     q = parser.unparse({'tag': tag})
     return request.route_url('activity.search', _query=[('q', q)])
예제 #10
0
파일: activity.py 프로젝트: hypothesis/h
 def tag_link(tag):
     q = parser.unparse({"tag": tag})
     return self.request.route_url("activity.search", _query=[("q", q)])
예제 #11
0
파일: activity.py 프로젝트: ssin122/test-h
 def tag_link(tag):
     q = parser.unparse({'tag': tag})
     return self.request.route_url('activity.search', _query=[('q', q)])