Пример #1
0
    def test_it_returns_annotations_for_ids_in_the_same_order(self, db_session, factories):
        ann_1 = factories.Annotation(userid='luke')
        ann_2 = factories.Annotation(userid='luke')

        assert [ann_2, ann_1] == storage.fetch_ordered_annotations(db_session,
                                                                   [ann_2.id, ann_1.id])
        assert [ann_1, ann_2] == storage.fetch_ordered_annotations(db_session,
                                                                   [ann_1.id, ann_2.id])
Пример #2
0
    def test_it_returns_annotations_for_ids_in_the_same_order(self, db_session, factories):
        ann_1 = factories.Annotation(userid='luke')
        ann_2 = factories.Annotation(userid='luke')

        assert [ann_2, ann_1] == storage.fetch_ordered_annotations(db_session,
                                                                   [ann_2.id, ann_1.id])
        assert [ann_1, ann_2] == storage.fetch_ordered_annotations(db_session,
                                                                   [ann_1.id, ann_2.id])
Пример #3
0
Файл: query.py Проект: nlisgo/h
def fetch_annotations(session, ids, reply_ids):
    def load_documents(query):
        return query.options(subqueryload(Annotation.document))

    annotations = storage.fetch_ordered_annotations(
        session, ids, query_processor=load_documents)

    replies = storage.fetch_ordered_annotations(session, reply_ids)

    return (annotations, replies)
Пример #4
0
    def test_it_returns_annotations_for_ids_in_the_same_order(self, db_session):
        ann_1 = Annotation(userid='luke')
        ann_2 = Annotation(userid='luke')
        db_session.add_all([ann_1, ann_2])
        db_session.flush()

        assert [ann_2, ann_1] == storage.fetch_ordered_annotations(db_session,
                                                                   [ann_2.id, ann_1.id])
        assert [ann_1, ann_2] == storage.fetch_ordered_annotations(db_session,
                                                                   [ann_1.id, ann_2.id])
Пример #5
0
def fetch_annotations(session, ids, reply_ids):
    def load_documents(query):
        return query.options(subqueryload(Annotation.document))

    annotations = storage.fetch_ordered_annotations(
        session, ids, query_processor=load_documents)

    replies = storage.fetch_ordered_annotations(session, reply_ids)

    return (annotations, replies)
Пример #6
0
    def test_it_returns_annotations_for_ids_in_the_same_order(
            self, db_session):
        ann_1 = Annotation(userid='luke')
        ann_2 = Annotation(userid='luke')
        db_session.add_all([ann_1, ann_2])
        db_session.flush()

        assert [ann_2, ann_1
                ] == storage.fetch_ordered_annotations(db_session,
                                                       [ann_2.id, ann_1.id])
        assert [ann_1, ann_2
                ] == storage.fetch_ordered_annotations(db_session,
                                                       [ann_1.id, ann_2.id])
Пример #7
0
    def test_it_allows_to_change_the_query(self, db_session):
        ann_1 = Annotation(userid='luke', target_uri='http://example.com')
        ann_2 = Annotation(userid='maria', target_uri='http://example.com')
        db_session.add_all([ann_1, ann_2])

        doc = Document(document_uris=[
            DocumentURI(uri='http://bar.com/', claimant='http://example.com'),
            DocumentURI(uri='http://example.com/',
                        type='rel-canonical',
                        claimant='http://example.com')
        ],
                       meta=[
                           DocumentMeta(claimant='http://example.com',
                                        type='title',
                                        value='Example')
                       ])
        db_session.add(doc)

        db_session.flush()

        def only_maria(query):
            return query.filter(Annotation.userid == 'maria')

        assert [ann_2] == storage.fetch_ordered_annotations(
            db_session, [ann_2.id, ann_1.id], query_processor=only_maria)
Пример #8
0
    def test_it_allows_to_change_the_query(self, db_session, factories):
        ann_1 = factories.Annotation(userid='luke')
        ann_2 = factories.Annotation(userid='maria')

        def only_maria(query):
            return query.filter(Annotation.userid == 'maria')

        assert [ann_2] == storage.fetch_ordered_annotations(
            db_session, [ann_2.id, ann_1.id], query_processor=only_maria)
Пример #9
0
    def test_it_allows_to_change_the_query(self, db_session, factories):
        ann_1 = factories.Annotation(userid='luke')
        ann_2 = factories.Annotation(userid='maria')

        def only_maria(query):
            return query.filter(Annotation.userid == 'maria')

        assert [ann_2] == storage.fetch_ordered_annotations(db_session,
                                                            [ann_2.id, ann_1.id],
                                                            query_processor=only_maria)
Пример #10
0
def _present_annotations(request, ids):
    """Load annotations by id from the database and present them."""
    def eager_load_documents(query):
        return query.options(
            subqueryload(models.Annotation.document))

    annotations = storage.fetch_ordered_annotations(request.db, ids,
                                                    query_processor=eager_load_documents)
    links_service = request.find_service(name='links')
    return [AnnotationJSONPresenter(ann, links_service).asdict()
            for ann in annotations]
Пример #11
0
def _present_annotations(request, ids):
    """Load annotations by id from the database and present them."""
    def eager_load_documents(query):
        return query.options(subqueryload(models.Annotation.document))

    annotations = storage.fetch_ordered_annotations(
        request.db, ids, query_processor=eager_load_documents)
    links_service = request.find_service(name='links')
    return [
        AnnotationJSONPresenter(ann, links_service).asdict()
        for ann in annotations
    ]
Пример #12
0
    def test_it_allows_to_change_the_query(self, db_session):
        ann_1 = Annotation(userid='luke', target_uri='http://example.com')
        ann_2 = Annotation(userid='maria', target_uri='http://example.com')
        db_session.add_all([ann_1, ann_2])

        doc = Document(
            document_uris=[DocumentURI(uri='http://bar.com/', claimant='http://example.com'),
                           DocumentURI(uri='http://example.com/', type='rel-canonical', claimant='http://example.com')],
            meta=[DocumentMeta(claimant='http://example.com', type='title', value='Example')])
        db_session.add(doc)

        db_session.flush()

        def only_maria(query):
            return query.filter(Annotation.userid == 'maria')

        assert [ann_2] == storage.fetch_ordered_annotations(db_session,
                                                            [ann_2.id, ann_1.id],
                                                            query_processor=only_maria)
Пример #13
0
Файл: feeds.py Проект: nlisgo/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)
Пример #14
0
def _annotations(request):
    """Return the annotations from the search API."""
    result = search.Search(request).run(request.params)
    return storage.fetch_ordered_annotations(request.db, result.annotation_ids)