示例#1
0
def create_app(config=None):
    app = Flask(__name__)
    app.config.from_object("purepage.config_default")
    if config:
        app.config.from_object(config)
    app.url_map.converters['no'] = NoConverter
    app.route("/webhooks")(Webhooks())
    route_views(app)
    db.init_app(app)
    github.init_app(app)
    mail.init_app(app)
    limiter.init_app(app)

    bp_api = Blueprint('api', __name__, static_folder='static')
    api.init_app(app, blueprint=bp_api, docs=__doc__)
    for x in resources:
        api.add_resource(x)
    api.add_resource(Permission, auth=auth)
    auth.init_api(api, fn_user_role=fn_user_role)
    app.register_blueprint(bp_api, url_prefix='/api')

    gen = Gen(api)
    gen.resjs()
    gen.resdocs()
    gen.permission()
    return app
示例#2
0
def create_app(config=None):
    app = Flask(__name__)
    app.config.from_object("purepage.config_default")
    if config:
        app.config.from_object(config)
    app.url_map.converters['no'] = NoConverter
    app.route("/webhooks")(Webhooks())
    route_views(app)
    db.init_app(app)
    github.init_app(app)
    mail.init_app(app)
    limiter.init_app(app)

    bp_api = Blueprint('api', __name__, static_folder='static')
    api.init_app(app, blueprint=bp_api, docs=__doc__)
    for x in resources:
        api.add_resource(x)
    api.add_resource(Permission, auth=auth)
    auth.init_api(api, fn_user_role=fn_user_role)
    app.register_blueprint(bp_api, url_prefix='/api')

    gen = Gen(api)
    gen.resjs()
    gen.resdocs()
    gen.permission()
    return app
def test_gendocs():
    class Hello(Resource):
        """中文docstring for Hello哈哈"""

        def get(self):
            """你好啊"""
            return "hello"

    app = Flask(__name__)
    api = Api(app, docs=__doc__)
    api.add_resource(Hello)
    gen = Gen(api)
    gen.resjs('static/res.js')
    gen.resdocs('static/resdocs.html', resjs='static/res.js',
                bootstrap="bootstrap.css")
示例#4
0
def create_app(test=False):
    app = Flask(__name__)
    app.config["ADMIN_EMAIL"] = "*****@*****.**"
    app.config["ADMIN_PASSWORD"] = "******"

    if test:
        app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://"
        app.config["SQLALCHEMY_ECHO"] = True
    else:
        db_path = os.path.join(app.root_path, "todos.db")
        app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + db_path
    db.init_app(app)

    bp_api = Blueprint('api', __name__, static_folder='static')
    api.init_app(app, blueprint=bp_api, docs=__doc__)
    auth.init_api(api, fn_user_role=fn_user_role)

    api.add_resource(Todos)
    api.add_resource(User)
    api.add_resource(Permission, auth=auth)
    api.add_resource(ApiInfo, api=api)

    def make_view(filename):
        return lambda *args, **kwargs: app.send_static_file(filename)
    for url, filename in url_views:
        end = os.path.splitext(filename)[0]
        app.route(url, endpoint=end)(make_view(filename))

    app.before_first_request(before_first_request)
    app.register_blueprint(bp_api, url_prefix='/api')

    gen = Gen(api)
    gen.resjs('static/js/res.js')
    gen.resdocs('static/resdocs.html', resjs='/static/js/res.js',
                bootstrap='/static/css/bootstrap.min.css')
    gen.permission('static/permission.html', resjs='/static/js/res.js',
                   bootstrap='/static/css/bootstrap.min.css',
                   vuejs='/static/js/vue.js')
    return app
示例#5
0
from flask_restaction import Resource, Api, Gen

app = Flask(__name__)
api = Api(app)


class Hello(Resource):
    """hello world"""
    schema_inputs = {
        "get": {
            "name": ("safestr&default='world'", "your name")
        }
    }
    schema_outputs = {
        "get": {"hello": "unicode&required"}
    }

    def get(self, name):
        """welcome to flask-restaction"""
        return {"hello": name}

api.add_resource(Hello)

gen = Gen(api)
gen.resjs('static/res.js')
gen.resdocs('static/resdocs.html', resjs='/static/res.js',
            bootstrap='/static/bootstrap.min.css')

if __name__ == '__main__':
    app.run(debug=True)
示例#6
0
        print(name)
        user = User(name, password)
        return user.toDict()

    def put(self, user_id, name, password):
        user = filter(lambda x: True
                      if x._id == user_id else False, Userlist)[0]
        if name:
            user.name = name
        if password:
            user.password = password

        return user.toDict()

    def delete(self, user_id):
        global Userlist
        Userlist = filter(lambda x: False
                          if x._id == user_id else True, Userlist)
        return {"message": "OK"}


api.add_resource(Users)

gen = Gen(api)
gen.resjs('static/js/res.js')
gen.resdocs('static/resdocs.html',
            resjs='/static/js/res.js',
            bootstrap='/static/css/bootstrap.min.css')

if __name__ == '__main__':
    app.run(debug=True)