示例#1
0
文件: util.py 项目: adamchainz/aleph
def get_document(document_id):
    document = Document.by_id(document_id)
    if document is None:
        raise NotFound()
    readable = [c for c in document.collection_ids if authz.collection_read(c)]
    authz.require(len(readable))
    return document
示例#2
0
def get_document(document_id):
    document = Document.by_id(document_id)
    if document is None:
        raise NotFound()
    readable = [c for c in document.collection_ids if authz.collection_read(c)]
    authz.require(len(readable))
    return document
示例#3
0
def pending(id):
    collection = obj_or_404(Collection.by_id(id))
    authz.require(authz.collection_read(id))
    q = collection.pending_entities()
    q = q.limit(30)
    entities = []
    for entity in q.all():
        data = entity.to_dict()
        data['name_latin'] = latinize_text(entity.name, lowercase=False)
        entities.append(data)
    return jsonify({'results': entities, 'total': len(entities)})
示例#4
0
def pending(id):
    collection = obj_or_404(Collection.by_id(id))
    authz.require(authz.collection_read(id))
    q = collection.pending_entities()
    q = q.limit(30)
    entities = []
    for entity in q.all():
        data = entity.to_dict()
        data['name_latin'] = latinize_text(entity.name, lowercase=False)
        entities.append(data)
    return jsonify({'results': entities, 'total': len(entities)})
示例#5
0
def paths(id):
    collection = obj_or_404(Collection.by_id(id))
    authz.require(authz.collection_read(collection.id))
    start_entity_id = request.args.get('entity_id')
    labels = request.args.getlist('label')
    types = request.args.getlist('type')
    collection_id = request.args.getlist('collection_id')
    end_collection_id = authz.collections_intersect(authz.READ, collection_id)
    q = Path.find(collection, start_entity_id=start_entity_id, labels=labels,
                  types=types, end_collection_id=end_collection_id)
    data = Pager(q, id=collection.id).to_dict()
    data['facets'] = Path.facets(collection, start_entity_id=start_entity_id,
                                 labels=labels, types=types,
                                 end_collection_id=end_collection_id,
                                 collection_id=authz.collections(authz.READ))
    return jsonify(data)
示例#6
0
def entity_collections(q, aggs, args, filters):
    """Filter entities, facet for collections."""
    entities = args.getlist('entity')
    collections = []
    readable = authz.collections(authz.READ)
    requested = args.getlist('collection') or readable
    for collection_id in requested:
        collection_id = int(collection_id)
        if authz.collection_read(collection_id):
            collections.append(collection_id)

    flt = {
        'or': [{
            'terms': {
                'entities.collection_id': collections
            }
        }, {
            'and': [{
                'terms': {
                    'entities.collection_id': readable
                },
                'terms': {
                    'entities.uuid': entities
                },
            }]
        }]
    }
    aggs['entities'] = {
        'nested': {
            'path': 'entities'
        },
        'aggs': {
            'inner': {
                'filter': flt,
                'aggs': {
                    'entities': {
                        'terms': {
                            'field': 'entities.uuid',
                            'size': FACET_SIZE
                        }
                    }
                }
            }
        }
    }
    return q
示例#7
0
def entity_collections(q, aggs, args, filters):
    """Filter entities, facet for collections."""
    entities = args.getlist('entity')
    collections = []
    readable = authz.collections(authz.READ)
    requested = args.getlist('collection') or readable
    for collection_id in requested:
        collection_id = int(collection_id)
        if authz.collection_read(collection_id):
            collections.append(collection_id)

    flt = {
        'or': [
            {
                'terms': {'entities.collection_id': collections}
            },
            {
                'and': [
                    {
                        'terms': {'entities.collection_id': readable},
                        'terms': {'entities.uuid': entities},
                    }
                ]
            }
        ]
    }
    aggs['entities'] = {
        'nested': {
            'path': 'entities'
        },
        'aggs': {
            'inner': {
                'filter': flt,
                'aggs': {
                    'entities': {
                        'terms': {'field': 'entities.uuid', 'size': FACET_SIZE}
                    }
                }
            }
        }
    }
    return q
示例#8
0
def view(id):
    collection = obj_or_404(Collection.by_id(id))
    authz.require(authz.collection_read(id))
    return jsonify(collection)
示例#9
0
def lookup():
    entity = obj_or_404(
        Entity.by_identifier(request.args.get('scheme'),
                             request.args.get('identifier')))
    authz.require(authz.collection_read(entity.collection_id))
    return jsonify(entity)
示例#10
0
def view(id):
    entity = obj_or_404(Entity.by_id(id))
    authz.require(authz.collection_read(entity.collection_id))
    return jsonify(entity)
示例#11
0
def view(collection_id, id):
    collection = obj_or_404(Collection.by_id(collection_id))
    authz.require(authz.collection_read(collection_id))
    network = obj_or_404(Network.by_id_collection(id, collection))
    return jsonify(network)
示例#12
0
def index(collection_id):
    collection = obj_or_404(Collection.by_id(collection_id))
    authz.require(authz.collection_read(collection.id))
    q = Network.all()
    q = q.filter(Network.collection_id == collection.id)
    return jsonify(Pager(q, collection_id=collection.id))
示例#13
0
def lookup():
    entity = obj_or_404(Entity.by_identifier(request.args.get('scheme'),
                                             request.args.get('identifier')))
    authz.require(authz.collection_read(entity.collection_id))
    return jsonify(entity)
示例#14
0
def view(id):
    entity = obj_or_404(Entity.by_id(id))
    authz.require(authz.collection_read(entity.collection_id))
    return jsonify(entity)
示例#15
0
def view(id):
    collection = obj_or_404(Collection.by_id(id))
    authz.require(authz.collection_read(id))
    data = collection.to_dict()
    data.update(collection.content_statistics())
    return jsonify(data)
示例#16
0
def view(id):
    collection = obj_or_404(Collection.by_id(id))
    authz.require(authz.collection_read(id))
    data = collection.to_dict()
    data.update(collection.content_statistics())
    return jsonify(data)