Exemple #1
0
def register_extensions(app):
    """Register Flask extensions."""
    assets.init_app(app)
    db.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
Exemple #2
0
def register_extensions(app):
    oidc.init_app(app)
    db.init_app(app)
    bootstrap.init_app(app)
    # login_manager.init_app(app)
    csrf.init_app(app)
    ckeditor.init_app(app)
    moment.init_app(app)
Exemple #3
0
def configure_extensions(app):
    """Configures the extensions."""

    # Flask-WTF CSRF
    csrf.init_app(app)

    # Flask-SQLAlchemy
    db.init_app(app)
Exemple #4
0
def register_extensions(app):
    """
    Register Flask extensions.
    """
    bcrypt.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    ma.init_app(app)
    jwt.init_app(app)
Exemple #5
0
def register_extensions(app):
    """Register Flask extensions."""
    storage.init_app(app)
    assets.init_app(app)
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
Exemple #6
0
def register_extensions(app):

    bcrypt.init_app(app)
    db.init_app(app)
    return None
def create_app() -> Flask:
    """Create app."""
    # pylint: disable=W0621
    app = Flask(__name__)

    if app.config["ENV"] == "development":
        try:
            from config_cust import DevConfig as DevConfigCust

            app.config.from_object(DevConfigCust())
        except ImportError:
            from config import DevConfig

            app.config.from_object(DevConfig())

    elif app.config["ENV"] == "test":
        try:
            from config_cust import (
                TestConfig as TestConfigCust,  # type: ignore[attr-defined]
            )

            app.config.from_object(TestConfigCust())
        except ImportError:
            from config import TestConfig

            app.config.from_object(TestConfig())

    else:
        try:
            from config_cust import Config as ConfigCust

            app.config.from_object(ConfigCust())
        except ImportError:
            from config import Config

            app.config.from_object(Config())

    compress.init_app(app)
    web_assets.init_app(app)

    # auth
    login_manager.init_app(app)
    login_manager.login_view = app.config["LOGIN_VIEW"]
    login_manager.login_message = app.config["LOGIN_MESSAGE"]

    sess.init_app(app)

    # database
    db.init_app(app)
    migrate.init_app(app, db, directory=app.config["MIGRATIONS"])

    # web cache
    cache.init_app(app)
    cache.clear()
    # run tasks off main thread
    executor.init_app(app)

    # redis
    redis_client.init_app(app)

    # html min
    htmlmin.init_app(app)

    with app.app_context():

        # pylint: disable=W0611
        from web import cli
        from web.web import assets  # noqa: F401
        from web.web import (
            admin,
            auth,
            connection,
            dashboard,
            executors,
            filters,
            project,
            saml_auth,
            table,
            task,
            task_controls,
            task_edit,
            task_files,
        )

        app.register_blueprint(saml_auth.login_bp)
        app.register_blueprint(admin.admin_bp)
        app.register_blueprint(auth.auth_bp)
        app.register_blueprint(connection.connection_bp)
        app.register_blueprint(project.project_bp)
        app.register_blueprint(task.task_bp)
        app.register_blueprint(task_controls.task_controls_bp)
        app.register_blueprint(task_edit.task_edit_bp)
        app.register_blueprint(task_files.task_files_bp)
        app.register_blueprint(dashboard.dashboard_bp)
        app.register_blueprint(table.table_bp)
        app.register_blueprint(executors.executors_bp)
        app.register_blueprint(filters.filters_bp)
        app.register_blueprint(cli.cli_bp)

        if app.config["DEBUG"]:
            from flask_debugtoolbar import DebugToolbarExtension

            toolbar = DebugToolbarExtension()
            toolbar.init_app(app)
            assets.cache = False  # type: ignore[attr-defined]
            assets.manifest = False  # type: ignore[attr-defined]

        @app.errorhandler(404)
        @app.errorhandler(500)
        def error_message(error: str) -> str:
            """Return error page for 404 and 500 errors including the specific error message.

            :param error: error message
            :return: json web response with error message:

            .. code-block:: python

                {"error": "messsage"}

            """
            return render_template(
                "error.html.j2",
                message="<strong>" + str(error).replace(":", "</strong>:"),
                trace=full_stack(),
                title="That was an error",
            )

        return app
Exemple #8
0
def register_extensions(app):

    bcrypt.init_app(app)
    db.init_app(app)
    return None
from www import register_blueprint

base_dir = os.path.abspath(os.path.dirname(__file__))

if win:
    template_folder = os.path.join(base_dir, f"web\\templates\\")
    static_folder = os.path.join(base_dir, f"web\\static\\")
    # todo 考虑配置文件导入,放在Application类之中
    base_config = os.path.join(base_dir, f"config\\base_setting.py")
    env_config = os.path.join(base_dir, f"config\\{os.getenv('FLASK_CONFIG', 'local_setting')}.py")
else:
    template_folder = os.path.join(base_dir, f"web/templates/")
    static_folder = os.path.join(base_dir, f"web/static/")
    base_config = os.path.join(base_dir, f"config/base_setting.py")
    env_config = os.path.join(base_dir, f"config/{os.getenv('FLASK_CONFIG', 'local_setting')}.py")

app = Application(__name__, template_folder=template_folder, root_path=os.getcwd(), static_folder=static_folder)
app.config.from_pyfile(base_config)
app.config.from_pyfile(env_config)
db.init_app(app)
register_blueprint(app)
app.before_request(check_auth)
register_error(app)

app.add_template_global(UrlManager.buildUrl, 'buildUrl')
app.add_template_global(UrlManager.buildStaticUrl, 'buildStaticUrl')
app.add_template_global(UrlManager.buildImageUrl, 'buildImageUrl')

# Manager 没有init__app() 方法
manager = Manager(app)
Exemple #10
0
def register_extensions(app):
    """Register Flask extensions."""
    db.init_app(app)
    migrate.init_app(app, db)
    mail.init_app(app)
    cache.init_app(app)