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
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)})
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)
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
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
def view(id): collection = obj_or_404(Collection.by_id(id)) authz.require(authz.collection_read(id)) return jsonify(collection)
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)
def view(id): entity = obj_or_404(Entity.by_id(id)) authz.require(authz.collection_read(entity.collection_id)) return jsonify(entity)
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)
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))
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)
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)