예제 #1
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)
예제 #2
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)
예제 #3
0
def update(slug, name):
    """ Update the data of the entity. """
    network, query = _get_query(slug, name)
    require.query.update(network, query)
    context = ValidationContext(network=network, query=query)
    data = dict(request_content(request).items())
    data = validate_query(dict(data.items()), context)
    query.update(data)
    db.session.commit()
    return jsonify(query, status=202)
예제 #4
0
def create():
    """ Create a new network. """
    require.network.create()
    data = request_content(request)
    context = ValidationContext()
    data = validate_network(dict(data.items()), context)
    network = Network.create(data)
    db.session.commit()
    url = url_for(".get", slug=network.slug)
    return jsonify(network, status=201, headers={"location": url})
예제 #5
0
def update(slug, name):
    """ Update the data of the entity. """
    network, query = _get_query(slug, name)
    require.query.update(network, query)
    context = ValidationContext(network=network, query=query)
    data = dict(request_content(request).items())
    data = validate_query(dict(data.items()), context)
    query.update(data)
    db.session.commit()
    return jsonify(query, status=202)
예제 #6
0
def update(slug):
    """ Update the data of the network. """
    network = _get_network(slug)
    require.network.update(network)
    data = request_content(request)
    context = ValidationContext(network=network)
    data = validate_network(dict(data.items()), context)
    network.update(data)
    db.session.commit()
    return jsonify(network)
예제 #7
0
def login_save():
    """ Create an account based on the sign-up form. """
    data = request_content(request)
    account = Account.by_name(data.get('name'))
    if not account \
       or not account.validate_password(data.get('password')) \
       or not login_user(account):
        return error_fill(login_form(), data,
                          {'name': 'Invalid username or password!'})
    flash("Welcome back, %s!" % account.display_name, 'success')
    return redirect(url_for('home.index'))
예제 #8
0
def login_save():
    """ Create an account based on the sign-up form. """
    data = request_content(request)
    account = Account.by_name(data.get('name'))
    if not account \
       or not account.validate_password(data.get('password')) \
       or not login_user(account):
        return error_fill(login_form(), data,
            {'name': 'Invalid username or password!'})
    flash("Welcome back, %s!" % account.display_name, 'success')
    return redirect(url_for('home.index'))
예제 #9
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})
예제 #10
0
def update(slug):
    """ Update the data of the network. """
    network = _get_network(slug)
    require.network.update(network)
    data = request_content(request)
    context = ValidationContext(network=network)
    data = validate_network(dict(data.items()), \
            context)
    network.update(data)
    db.session.commit()
    return jsonify(network)
예제 #11
0
def create():
    """ Create a new network. """
    require.network.create()
    data = request_content(request)
    context = ValidationContext()
    data = validate_network(dict(data.items()), \
            context)
    network = Network.create(data)
    db.session.commit()
    url = url_for('.get', slug=network.slug)
    return jsonify(network, status=201, headers={'location': url})
예제 #12
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})
예제 #13
0
def update(slug, id):
    """ Update the data of the relation. """
    network, relation = _get_relation(slug, id)
    require.relation.update(network, relation)
    data = dict(request_content(request).items())
    data['type'] = relation.type
    context = ValidationContext(network=network)
    schema = _get_schema(network, data.get('type'))
    data = validate_relation(data, schema, context)
    updated_relation = relation.update(schema, data)
    db.session.commit()
    return jsonify(updated_relation)
예제 #14
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})
예제 #15
0
def update(slug, id):
    """ Update the data of the relation. """
    network, relation = _get_relation(slug, id)
    require.relation.update(network, relation)
    data = dict(request_content(request).items())
    data["type"] = relation.type
    context = ValidationContext(network=network)
    schema = _get_schema(network, data.get("type"))
    data = validate_relation(data, schema, context)
    updated_relation = relation.update(schema, data)
    db.session.commit()
    return jsonify(updated_relation)
예제 #16
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})
예제 #17
0
def update(slug, id):
    """ Update the data of the entity. """
    network, entity = _get_entity(slug, id)
    require.entity.update(network, entity)
    data = dict(request_content(request).items())
    data['type'] = entity.type
    context = ValidationContext(network=network)
    schema = _get_schema(network, data.get('type'))
    data = validate_entity(data, schema, context)
    updated_entity = entity.update(schema, data)
    _deep_create(data, updated_entity, network)
    db.session.commit()
    return jsonify(updated_entity, status=202)
예제 #18
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})
예제 #19
0
def register_save():
    """ Create an account based on the sign-up form. """
    require.account.create()
    data = request_content(request)
    context = ValidationContext()
    try:
        data = validate_account(dict(data.items()), context)
        account = Account.create(data)
        db.session.commit()
        flash("Welcome, %s!" % account.display_name, 'success')
        return redirect(url_for('home.index'))
    except Invalid as inv:
        return error_fill(register_form(), data, invalid_dict(inv))
예제 #20
0
def update(slug, id):
    """ Update the data of the entity. """
    network, entity = _get_entity(slug, id)
    require.entity.update(network, entity)
    data = dict(request_content(request).items())
    data['type'] = entity.type
    context = ValidationContext(network=network)
    schema = _get_schema(network, data.get('type'))
    data = validate_entity(data, schema, context)
    updated_entity = entity.update(schema, data)
    _deep_create(data, updated_entity, network)
    db.session.commit()
    return jsonify(updated_entity, status=202)
예제 #21
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})
예제 #22
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})
예제 #23
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})
예제 #24
0
def register_save():
    """ Create an account based on the sign-up form. """
    require.account.create()
    data = request_content(request)
    context = ValidationContext()
    try:
        data = validate_account(dict(data.items()), context)
        account = Account.create(data)
        db.session.commit()
        flash("Welcome, %s!" % account.display_name, 'success')
        return redirect(url_for('home.index'))
    except Invalid as inv:
        return error_fill(register_form(),
                          data,
                          invalid_dict(inv))