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
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})
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)
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)
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']], }
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)
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']], }
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"]]}
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']], }
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
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
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']], }
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)
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
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
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
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']}
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']}
def _annotations(request): """Return the annotations from the search API.""" return search.search(request, request.params)['rows']
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]
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
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]
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)
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
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"