示例#1
0
def test_search_with_user_object(search_raw):
    """If search() gets a user arg it passes it to search_raw().

    Note: This test is testing the function's user param. You can also
    pass one or more user arguments in the request.params, those are
    tested elsewhere.

    """
    user = mock.MagicMock()

    search.search(request_params=multidict.NestedMultiDict(), user=user)

    first_call = search_raw.call_args_list[0]
    assert first_call[1]["user"] == user
示例#2
0
文件: search_test.py 项目: stuk88/h
def test_search_with_user_object(search_raw):
    """If search() gets a user arg it passes it to search_raw().

    Note: This test is testing the function's user param. You can also
    pass one or more user arguments in the request.params, those are
    tested elsewhere.

    """
    user = mock.MagicMock()

    search.search(request_params=multidict.NestedMultiDict(), user=user)

    first_call = search_raw.call_args_list[0]
    assert first_call[1]["user"] == user
示例#3
0
文件: views.py 项目: VanyTang/h
def annotations_index(request):
    """Do a search for all annotations on anything and return results.

    This will use the default limit, 20 at time of writing, and results
    are ordered most recent first.
    """
    return search_lib.search(request, {"limit": 20})
示例#4
0
文件: views.py 项目: chrber/h
def _read_group(request, group):
    """Return the rendered "Share this group" page.

    This is the page that's shown when a user who is already a member of a
    group visits the group's URL.

    """
    url = request.route_url('group_read', pubid=group.pubid, slug=group.slug)

    result = search.search(request, private=False, params={
        "group": group.pubid, "limit": 1000})
    annotations = [presenters.AnnotationHTMLPresenter(a)
                   for a in result['rows']]

    # Group the annotations by URI.
    # Create a dict mapping the (normalized) URIs of the annotated documents
    # to the most recent annotation of each document.
    annotations_by_uri = collections.OrderedDict()
    for annotation in annotations:
        normalized_uri = uri.normalize(annotation.uri)
        if normalized_uri not in annotations_by_uri:
            annotations_by_uri[normalized_uri] = annotation
            if len(annotations_by_uri) >= 25:
                break

    document_links = [annotation.document_link
                      for annotation in annotations_by_uri.values()]

    template_data = {
        'group': group, 'group_url': url, 'document_links': document_links}

    return renderers.render_to_response(
        renderer_name='h:groups/templates/share.html.jinja2',
        value=template_data, request=request)
示例#5
0
def _annotations(request):
    """Return the annotations from the search API."""
    rows = search.search(request, request.params)['rows']
    ids = [r['id'] for r in rows]
    return storage.fetch_ordered_annotations(request.db,
                                             ids,
                                             load_documents=True)
示例#6
0
文件: views.py 项目: coolcool21/h
def search(request):
    """Search the database for annotations matching with the given query."""
    results = search_lib.search(request, request.params)

    return {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']],
    }
示例#7
0
文件: views.py 项目: VanyTang/h
def search(request):
    """Search the database for annotations matching with the given query."""
    params = request.params.copy()

    separate_replies = params.pop('_separate_replies', False)
    return search_lib.search(request,
                             params,
                             separate_replies=separate_replies)
示例#8
0
文件: logic.py 项目: plainspace/h
def search_annotations(params, user=None, search_normalized_uris=False):
    results = search_lib.search(request_params=params,
                                user=user,
                                search_normalized_uris=search_normalized_uris)

    return {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']],
    }
示例#9
0
文件: views.py 项目: chrber/h
def annotations_index(request):
    """Do a search for all annotations on anything and return results.

    This will use the default limit, 20 at time of writing, and results
    are ordered most recent first.
    """
    results = search_lib.search(request, {"limit": 20})

    return {"total": results["total"], "rows": [search_lib.render(a) for a in results["rows"]]}
示例#10
0
文件: views.py 项目: linhua55/h
def annotations_index(request):
    """Do a search for all annotations on anything and return results.

    This will use the default limit, 20 at time of writing, and results
    are ordered most recent first.
    """
    results = search_lib.search(request, {"limit": 20})

    return {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']],
    }
示例#11
0
文件: views.py 项目: chrber/h
def search(request):
    """Search the database for annotations matching with the given query."""
    params = request.params.copy()

    separate_replies = params.pop("_separate_replies", False)
    results = search_lib.search(request, params, separate_replies=separate_replies)

    return_value = {"total": results["total"], "rows": [search_lib.render(a) for a in results["rows"]]}

    if separate_replies:
        return_value["replies"] = [search_lib.render(a) for a in results["replies"]]

    return return_value
示例#12
0
文件: views.py 项目: hashin/h
def search(request):
    """Search the database for annotations matching with the given query."""
    params = request.params.copy()

    separate_replies = params.pop('_separate_replies', False)
    out = search_lib.search(request, params, separate_replies=separate_replies)

    # Run the results through the JSON presenter
    out['rows'] = [_present_searchdict(a) for a in out['rows']]
    if separate_replies:
        out['replies'] = [_present_searchdict(a) for a in out['replies']]

    return out
示例#13
0
文件: views.py 项目: ningyifan/h
def search(request):
    """Search the database for annotations matching with the given query."""
    search_normalized_uris = request.feature('search_normalized')

    # The search results are filtered for the authenticated user
    user = get_user(request)
    results = search_lib.search(request_params=request.params,
                                user=user,
                                search_normalized_uris=search_normalized_uris)

    return {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']],
    }
示例#14
0
文件: views.py 项目: ningyifan/h
def search(request):
    """Search the database for annotations matching with the given query."""
    search_normalized_uris = request.feature('search_normalized')

    # The search results are filtered for the authenticated user
    user = get_user(request)
    results = search_lib.search(request_params=request.params,
                                user=user,
                                search_normalized_uris=search_normalized_uris)

    return {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']],
    }
示例#15
0
文件: views.py 项目: hashin/h
def search(request):
    """Search the database for annotations matching with the given query."""
    params = request.params.copy()

    separate_replies = params.pop('_separate_replies', False)
    out = search_lib.search(request,
                            params,
                            separate_replies=separate_replies)

    # Run the results through the JSON presenter
    out['rows'] = [_present_searchdict(a) for a in out['rows']]
    if separate_replies:
        out['replies'] = [_present_searchdict(a) for a in out['replies']]

    return out
示例#16
0
def _read_group(request, group):
    """Return the rendered "Share this group" page.

    This is the page that's shown when a user who is already a member of a
    group visits the group's URL.

    """
    url = request.route_url('group_read', pubid=group.pubid, slug=group.slug)

    result = search.search(request,
                           private=False,
                           params={
                               "group": group.pubid,
                               "limit": 1000
                           })
    annotations = [
        presenters.AnnotationHTMLPresenter(storage.annotation_from_dict(a))
        for a in result['rows']
    ]

    # Group the annotations by URI.
    # Create a dict mapping the (normalized) URIs of the annotated documents
    # to the most recent annotation of each document.
    annotations_by_uri = collections.OrderedDict()
    for annotation in annotations:
        normalized_uri = uri.normalize(annotation.uri)
        if normalized_uri not in annotations_by_uri:
            annotations_by_uri[normalized_uri] = annotation
            if len(annotations_by_uri) >= 25:
                break

    document_links = [
        annotation.document_link for annotation in annotations_by_uri.values()
    ]

    template_data = {
        'group': group,
        'group_url': url,
        'document_links': document_links
    }

    return renderers.render_to_response(
        renderer_name='h:templates/groups/share.html.jinja2',
        value=template_data,
        request=request)
示例#17
0
文件: views.py 项目: bZichett/h
def search(request):
    """Search the database for annotations matching with the given query."""
    params = request.params.copy()

    separate_replies = params.pop('_separate_replies', False)
    out = search_lib.search(request,
                            params,
                            separate_replies=separate_replies)

    # Run the results through the JSON presenter
    ids = [r['id'] for r in out['rows']]
    out['rows'] = _present_annotations(request, ids)

    if separate_replies:
        ids = [r['id'] for r in out['replies']]
        out['replies'] = _present_annotations(request, ids)

    return out
示例#18
0
文件: views.py 项目: openbizgit/h
def search(request):
    """Search the database for annotations matching with the given query."""
    params = request.params.copy()

    separate_replies = params.pop('_separate_replies', False)
    results = search_lib.search(request, params,
                                separate_replies=separate_replies)

    return_value = {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']]
    }

    if separate_replies:
        return_value['replies'] = [
            search_lib.render(a) for a in results['replies']]

    return return_value
示例#19
0
文件: views.py 项目: linhua55/h
def search(request):
    """Search the database for annotations matching with the given query."""
    params = request.params.copy()

    separate_replies = params.pop('_separate_replies', False)
    results = search_lib.search(request,
                                params,
                                separate_replies=separate_replies)

    return_value = {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']]
    }

    if separate_replies:
        return_value['replies'] = [
            search_lib.render(a) for a in results['replies']
        ]

    return return_value
示例#20
0
def badge(request):
    """Return the number of public annotations on a given page.

    This is for the number that's displayed on the Chrome extension's badge.

    Certain pages are blocklisted so that the badge never shows a number on
    those pages. The Chrome extension is oblivious to this, we just tell it
    that there are 0 annotations.

    """
    uri = request.params.get('uri')

    if not uri:
        raise httpexceptions.HTTPBadRequest()

    if models.Blocklist.is_blocked(request.db, uri):
        return {'total': 0}

    return {
        'total': search_lib.search(request, {'uri': uri, 'limit': 0})['total']}
示例#21
0
def badge(request):
    """Return the number of public annotations on a given page.

    This is for the number that's displayed on the Chrome extension's badge.

    Certain pages are blocklisted so that the badge never shows a number on
    those pages. The Chrome extension is oblivious to this, we just tell it
    that there are 0 annotations.

    """
    uri = request.params.get('uri')

    if not uri:
        raise httpexceptions.HTTPBadRequest()

    if models.Blocklist.is_blocked(uri):
        return {'total': 0}

    return {
        'total': search_lib.search(request, {'uri': uri, 'limit': 0})['total']}
示例#22
0
文件: views.py 项目: chrber/h
def _annotations(request):
    """Return the annotations from the search API."""
    return search.search(request, request.params)['rows']
示例#23
0
文件: views.py 项目: Cinemacloud/h
def _annotations(request):
    """Return the annotations from the search API."""
    rows = search.search(request, request.params)['rows']
    return [storage.annotation_from_dict(a) for a in rows]
示例#24
0
文件: views.py 项目: ssin122/annotran
def read_group(request, group, language=None, search_url=None, user=None, render=True):
    """
    Return the rendered "Share this group" page.

    This is the page that's shown when a user who is already a member of a group visits the group's URL.
    :param request: a request object
    :param group: a group object
    :param language: a language object to search or None
    :param search_url: the URL to search or None
    :param user: the user object to search or None
    :param render: whether or not to return a context object
    :return: if render, a context object for a template. If render is false, a list of annotations
    """

    if group is None:
        public_group_id = "__world__"
        slug = "Public"
    else:
        public_group_id = group.pubid
        slug = group.slug

    url = request.route_url('group_read', pubid=public_group_id, slug=slug)

    parameters = {"group": public_group_id, "limit": 1000}

    if language:
        parameters['language'] = language.pubid

    if search_url:
        parameters['uri'] = search_url

    if user:
        parameters['user'] = user

    result = search.search(request,
                           private=False,
                           params=parameters)

    annotations = [presenters.AnnotationHTMLPresenter(h.models.Annotation(a))
                   for a in result['rows']]

    if render:
        # Group the annotations by URI.
        # Create a dict mapping the (normalized) URIs of the annotated documents
        # to the most recent annotation of each document.
        annotations_by_uri = collections.OrderedDict()
        for annotation in annotations:
            normalized_uri = uri.normalize(annotation.uri)
            if normalized_uri not in annotations_by_uri:
                annotations_by_uri[normalized_uri] = annotation
                if len(annotations_by_uri) >= 25:
                    break

        document_links = [annotation.document_link
                          for annotation in annotations_by_uri.values()]

        template_data = {
            'group': group, 'group_url': url, 'document_links': document_links}

        return renderers.render_to_response(
            renderer_name='h:templates/groups/share.html.jinja2',
            value=template_data, request=request)
    else:
        return annotations
示例#25
0
文件: views.py 项目: JJediny/h
def _annotations(request):
    """Return the annotations from the search API."""
    rows = search.search(request, request.params)['rows']
    return [models.Annotation(a) for a in rows]
示例#26
0
def _annotations(request):
    """Return the annotations from the search API."""
    return search.search(request, request.params)['rows']
示例#27
0
文件: views.py 项目: hylhero/h
def search(request):
    """Search the database for annotations matching with the given query."""
    # The search results are filtered for the authenticated user
    user = get_user(request)
    return search_lib.search(request.params, user)
示例#28
0
文件: views.py 项目: bZichett/h
def _annotations(request):
    """Return the annotations from the search API."""
    rows = search.search(request, request.params)['rows']
    ids = [r['id'] for r in rows]
    return storage.fetch_ordered_annotations(request.db, ids, load_documents=True)
示例#29
0
def _annotations(request):
    """Return the annotations from the search API."""
    rows = search.search(request, request.params)['rows']
    return [storage.annotation_from_dict(a) for a in rows]
示例#30
0
文件: search_test.py 项目: stuk88/h
def test_search_does_not_pass_userid_to_build_query(build_query, _):
    search.search(multidict.NestedMultiDict())
    assert build_query.call_args[1]["userid"] is None
示例#31
0
文件: search_test.py 项目: stuk88/h
def test_search_does_pass_userid_to_build_query(build_query, _):
    user = mock.Mock(id="test_id")

    search.search(multidict.NestedMultiDict(), user=user)

    assert build_query.call_args[1]["userid"] == "test_id"