示例#1
0
def delete(slug, type, name):
    network = _get_network(slug)
    schema = _get_schema(network, type, name)
    require.schema.delete(network, schema)
    schema.delete()
    db.session.commit()
    raise Gone('Successfully deleted: %s' % name)
示例#2
0
def delete(slug, type, name):
    network = _get_network(slug)
    schema = _get_schema(network, type, name)
    require.schema.delete(network, schema)
    schema.delete()
    db.session.commit()
    raise Gone('Successfully deleted: %s' % name)
示例#3
0
def _get_query(slug, name):
    network = _get_network(slug)
    query = Query.by_name(network, name)
    if query is None:
        raise NotFound('No such entity: %s' % name)
    require.query.read(network, query)
    return network, query
示例#4
0
def _get_query(slug, name):
    network = _get_network(slug)
    query = Query.by_name(network, name)
    if query is None:
        raise NotFound('No such entity: %s' % name)
    require.query.read(network, query)
    return network, query
示例#5
0
def update(slug, type, name):
    network = _get_network(slug)
    schema = _get_schema(network, type, name)
    require.schema.update(network, schema)
    data = request_content(request)
    data = validate_schema(dict(data.items()))
    schema.update(network, type, data)
    db.session.commit()
    return jsonify(schema, status=202)
示例#6
0
def update(slug, type, name):
    network = _get_network(slug)
    schema = _get_schema(network, type, name)
    require.schema.update(network, schema)
    data = request_content(request)
    data = validate_schema(dict(data.items()))
    schema.update(network, type, data)
    db.session.commit()
    return jsonify(schema, status=202)
示例#7
0
def index(slug, type):
    """ List all available schemata for a type. """
    network = _get_network(slug)
    require.schema.list(network)
    _valid_schema(type)
    schemata = {
        Schema.ENTITY: network.entity_schemata,
        Schema.RELATION: network.relation_schemata
    }.get(type)
    return jsonify(schemata)
示例#8
0
def _get_entity(slug, id):
    network = _get_network(slug)
    entity = network.Entity.current_by_id(id)
    if entity is None:
        raise NotFound('No such entity: %s' % id)
    require.entity.read(network, entity)
    request.cache_key['modified'] = entity.created_at
    request.cache_key['id'] = id
    validate_cache(request)
    return network, entity
示例#9
0
def _get_entity(slug, id):
    network = _get_network(slug)
    entity = network.Entity.current_by_id(id)
    if entity is None:
        raise NotFound('No such entity: %s' % id)
    require.entity.read(network, entity)
    request.cache_key['modified'] = entity.created_at
    request.cache_key['id'] = id
    validate_cache(request)
    return network, entity
示例#10
0
def _get_relation(slug, id):
    network = _get_network(slug)
    relation = network.Relation.current_by_id(id)
    if relation is None:
        raise NotFound('No such entity: %s' % id)
    require.relation.read(network, relation)
    request.cache_key['modified'] = relation.created_at
    request.cache_key['id'] = id
    validate_cache(request)
    return network, relation
示例#11
0
def _get_relation(slug, id):
    network = _get_network(slug)
    relation = network.Relation.current_by_id(id)
    if relation is None:
        raise NotFound("No such entity: %s" % id)
    require.relation.read(network, relation)
    request.cache_key["modified"] = relation.created_at
    request.cache_key["id"] = id
    validate_cache(request)
    return network, relation
示例#12
0
def index(slug, type):
    """ List all available schemata for a type. """
    network = _get_network(slug)
    require.schema.list(network)
    _valid_schema(type)
    schemata = {
        Schema.ENTITY: network.entity_schemata,
        Schema.RELATION: network.relation_schemata
        }.get(type)
    return jsonify(schemata)
示例#13
0
def index(slug):
    """ List all available relations. """
    network = _get_network(slug)
    require.relation.list(network)
    type_name = request.args.get("type", None)
    type_ = _get_schema(network, type_name).cls if type_name else network.Relation
    count, query = filtered_query(type_, request)
    data = {"results": query.all(), "count": count}
    request.cache_key["ids"] = [r.id for r in data["results"]]
    request.cache_key["count"] = data["count"]
    return jsonify(data)
示例#14
0
def index(slug):
    """ List all available entities. """
    network = _get_network(slug)
    require.entity.list(network)
    type_name = request.args.get('type', None)
    type_ = _get_schema(network, type_name).cls if type_name else network.Entity
    count, query = filtered_query(type_, request, fts=True)
    data = {'results': query.all(), 'count': count}
    request.cache_key['ids'] = [r.id for r in data['results']]
    request.cache_key['count'] = data['count']
    return jsonify(data)
示例#15
0
def create(slug):
    """ Create a new query. """
    network = _get_network(slug)
    require.query.create(network)
    data = request_content(request)
    context = ValidationContext(network=network)
    data = validate_query(dict(data.items()), context)
    query = Query.create(network, data)
    db.session.commit()
    url = url_for('.get', slug=network.slug, name=query.name)
    return jsonify(query, status=201, headers={'location': url})
示例#16
0
def create(slug):
    """ Create a new query. """
    network = _get_network(slug)
    require.query.create(network)
    data = request_content(request)
    context = ValidationContext(network=network)
    data = validate_query(dict(data.items()), context)
    query = Query.create(network, data)
    db.session.commit()
    url = url_for('.get', slug=network.slug, name=query.name)
    return jsonify(query, status=201, headers={'location': url})
示例#17
0
def create(slug):
    """ Create a new relation. """
    network = _get_network(slug)
    require.relation.create(network)
    data = request_content(request)
    context = ValidationContext(network=network)
    schema = _get_schema(network, data.get("type"))
    data = validate_relation(dict(data.items()), schema, context)
    relation = network.Relation.create(schema, data)
    db.session.commit()
    url = url_for(".get", slug=network.slug, id=relation.id)
    return jsonify(relation, status=201, headers={"location": url})
示例#18
0
def create(slug, type):
    """ Create a new schema. """
    network = _get_network(slug)
    require.schema.create(network)
    _valid_schema(type)
    data = request_content(request)
    data = validate_schema(dict(data.items()))
    schema = Schema.create(network, type, data)
    db.session.commit()
    url = url_for('.get', slug=network.slug,
            type=schema.entity, name=schema.name)
    return jsonify(schema, status=201, headers={'location': url})
示例#19
0
def index(slug):
    """ List all available relations. """
    network = _get_network(slug)
    require.relation.list(network)
    type_name = request.args.get('type', None)
    type_ = _get_schema(network,
                        type_name).cls if type_name else network.Relation
    count, query = filtered_query(type_, request)
    data = {'results': query.all(), 'count': count}
    request.cache_key['ids'] = [r.id for r in data['results']]
    request.cache_key['count'] = data['count']
    return jsonify(data)
示例#20
0
def create(slug):
    """ Create a new entity. """
    network = _get_network(slug)
    require.entity.create(network)
    data = request_content(request)
    context = ValidationContext(network=network)
    schema = _get_schema(network, data.get('type'))
    data = validate_entity(dict(data.items()), schema, context)
    entity = network.Entity.create(schema, data)
    _deep_create(data, entity, network)
    db.session.commit()
    url = url_for('.get', slug=network.slug, id=entity.id)
    return jsonify(entity, status=201, headers={'location': url})
示例#21
0
def create(slug):
    """ Create a new relation. """
    network = _get_network(slug)
    require.relation.create(network)
    data = request_content(request)
    context = ValidationContext(network=network)
    schema = _get_schema(network, data.get('type'))
    data = validate_relation(dict(data.items()), \
            schema, context)
    relation = network.Relation.create(schema, data)
    db.session.commit()
    url = url_for('.get', slug=network.slug, id=relation.id)
    return jsonify(relation, status=201, headers={'location': url})
示例#22
0
def create(slug):
    """ Create a new entity. """
    network = _get_network(slug)
    require.entity.create(network)
    data = request_content(request)
    context = ValidationContext(network=network)
    schema = _get_schema(network, data.get('type'))
    data = validate_entity(dict(data.items()),
            schema, context)
    entity = network.Entity.create(schema, data)
    _deep_create(data, entity, network)
    db.session.commit()
    url = url_for('.get', slug=network.slug, id=entity.id)
    return jsonify(entity, status=201, headers={'location': url})
示例#23
0
def create(slug, type):
    """ Create a new schema. """
    network = _get_network(slug)
    require.schema.create(network)
    _valid_schema(type)
    data = request_content(request)
    data = validate_schema(dict(data.items()))
    schema = Schema.create(network, type, data)
    db.session.commit()
    url = url_for('.get',
                  slug=network.slug,
                  type=schema.entity,
                  name=schema.name)
    return jsonify(schema, status=201, headers={'location': url})
示例#24
0
def index(slug):
    """ List all available queries. """
    network = _get_network(slug)
    require.query.list(network)
    return jsonify({'results': Query.all(network)})
示例#25
0
def index(slug):
    """ List all available queries. """
    network = _get_network(slug)
    require.query.list(network)
    return jsonify({'results': Query.all(network)})
示例#26
0
def get(slug, type, name):
    network = _get_network(slug)
    schema = _get_schema(network, type, name)
    return jsonify(schema)
示例#27
0
def get(slug, type, name):
    network = _get_network(slug)
    schema = _get_schema(network, type, name)
    return jsonify(schema)