def index(slug): project = object_or_404(Project.by_slug(slug)) validate_cache(last_modified=project.updated_at) query = Schema.all() query = query.filter_by(project=project) pager = Pager(query) conv = lambda es: [schemata.to_rest_index(e) for e in es] return jsonify(pager.to_dict(conv))
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 to_rest(entity): """ Full serialization of the entity. """ data = to_rest_base(entity) data['created_at'] = entity.created_at data['updated_at'] = entity.updated_at ss = [schemata_logic.to_rest_index(s) for s in entity.schemata] data['schemata'] = ss data['properties'] = {} for prop in entity.active_properties: name, prop = properties_logic.to_rest(prop) data['properties'][name] = prop data['inbound_relations'] = entity.inbound.count() if data['inbound_relations'] > 0: data['inbound_url'] = url_for('relations_api.index', target=entity.id) data['outbound_relations'] = entity.outbound.count() if data['outbound_relations'] > 0: data['outbound_url'] = url_for('relations_api.index', source=entity.id) return data