def to_rest_base(relation): from grano.logic import entities as entities_logic return { 'id': relation.id, 'properties': {}, 'project': projects_logic.to_rest_index(relation.project), 'api_url': url_for('relations_api.view', id=relation.id), 'schema': schemata_logic.to_rest_index(relation.schema), 'source': entities_logic.to_rest_index(relation.source), 'target': entities_logic.to_rest_index(relation.target) }
def to_rest_base(relation): from grano.logic import entities as entities_logic return { "id": relation.id, "properties": {}, "project": projects_logic.to_rest_index(relation.project), "api_url": url_for("relations_api.view", id=relation.id), "schema": schemata_logic.to_rest_index(relation.schema), "source": entities_logic.to_rest_index(relation.source), "target": entities_logic.to_rest_index(relation.target), }
def search(): # TODO: move to be project-specific, the implement access control! searcher = ESSearcher(request.args) if 'project' in request.args: searcher.add_filter('project.slug', request.args.get('project')) pager = Pager(searcher) # TODO: get all entities at once: conv = lambda res: [entities.to_rest_index(Entity.by_id(r.get('id'))) for r in res] data = pager.to_dict(results_converter=conv) data['facets'] = searcher.facets() return jsonify(data)
def index(): query = filter_query(Entity, Entity.all(), request.args) for schema in request.args.getlist('schema'): alias = aliased(Schema) query = query.join(alias, Entity.schemata) query = query.filter(alias.name.in_(schema.split(','))) pager = Pager(query) conv = lambda es: [entities.to_rest_index(e) for e in es] return jsonify(pager.to_dict(conv))
def convert(serp): ents = Entity.by_id_many([r['id'] for r in serp], request.account) results = [ents.get(r['id']) for r in serp] results = [entities.to_rest_index(r) for r in results] return results