def config_list(user):
    if request.method == "GET":
        configs = [c.json() for c in user.configs]
        return _json_response(configs)
    elif request.method == "POST":
        if request.json is None:
            return Response(status=400)
        c = Config(user, request.json)
        db.session.add(c)
        db.session.commit()
        return _json_response(c.json())
def config_item(user, cid):
    config = Config.query.filter(Config.user_id == user.id).filter(Config.id == cid)
    if request.method == "PUT":
        if request.json is None:
            return Response(status=400)
        try:
            config = config.one()
            config.update(request.json)
        except NoResultFound:
            config = Config(user, request.json)
            db.session.add(config)
        db.session.commit()
        return _json_response(config.json())
    elif request.method == "DELETE":
        try:
            db.session.delete(config.one())
            db.session.commit()
        except NoResultFound:
            pass
        return Response(status=200)
    elif request.method == "GET":
        return _json_response(config.first_or_404().json())