Exemplo n.º 1
0
def search(request):
    """Search the database for annotations matching with the given query."""
    params = request.params.copy()

    separate_replies = params.pop('_separate_replies', False)
    result = search_lib.Search(request, separate_replies=separate_replies) \
        .run(params)

    out = {
        'total': result.total,
        'rows': _present_annotations(request, result.annotation_ids)
    }

    if separate_replies:
        out['replies'] = _present_annotations(request, result.reply_ids)

    return out
Exemplo n.º 2
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}

    query = {'uri': uri, 'limit': 0}
    result = search.Search(request).run(query)

    return {'total': result.total}
Exemplo n.º 3
0
Arquivo: feeds.py Projeto: st-fresh/h
def _annotations(request):
    """Return the annotations from the search API."""
    result = search.Search(request, stats=request.stats).run(request.params)
    return fetch_ordered_annotations(request.db, result.annotation_ids)