示例#1
0
def handle_caching(sketch: Sketch):
    sketch.add_requirements("flask-caching")

    sketch.settings["development"]["CACHE_TYPE"] = "simple"
    sketch.settings["testing"]["CACHE_TYPE"] = "simple"
    sketch.settings["production"]["CACHE_TYPE"] = "simple"

    sketch.add_extensions("caching")

    sketch.write_template(
        "ext_caching_tpl",
        templates.ext,
        pjoin(sketch.app_folder, "ext", "caching.py"),
    )
    sketch.write_template(
        "examples_caching_tpl",
        templates.examples,
        pjoin(
            sketch.app_folder,
            "examples",
            "caching_examples.py",
        ),
    )
    sketch.write_template(
        "examples_init_caching_tpl",
        templates.examples,
        pjoin(
            sketch.app_folder,
            "examples",
            "__init__.py",
        ),
    )
示例#2
0
def handle_limiter(sketch: Sketch):
    sketch.add_requirements("flask-limiter")

    sketch.settings["default"]["RATELIMIT_DEFAULT"] = "200 per day;50 per hour"
    sketch.settings["default"]["RATELIMIT_ENABLED"] = True
    sketch.settings["development"]["RATELIMIT_ENABLED"] = False

    sketch.add_extensions("limiter")

    sketch.write_template(
        "ext_limiter_tpl",
        templates.ext,
        pjoin(sketch.app_folder, "ext", "limiter.py"),
    )
    sketch.write_template(
        "examples_limiter_tpl",
        templates.examples,
        pjoin(
            sketch.app_folder,
            "examples",
            "limiter_examples.py",
        ),
    )
    sketch.write_template(
        "examples_init_limiter_tpl",
        templates.examples,
        pjoin(
            sketch.app_folder,
            "examples",
            "__init__.py",
        ),
    )
示例#3
0
def handle_migrate(sketch: Sketch):
    sketch.add_requirements("flask-migrate")

    sketch.add_extensions("migrate")

    sketch.write_template(
        "ext_migrate_tpl",
        templates.ext,
        pjoin(sketch.app_folder, "ext", "migrate.py"),
    )
示例#4
0
def security_web_handler(sketch: Sketch):
    if sketch.auth_framework == "security_web":
        sketch.add_requirements("flask-security-too", "argon2-cffi")

        sketch.settings["default"]["SECURITY_REGISTERABLE"] = True
        sketch.settings["default"]["SECURITY_POST_LOGIN_VIEW"] = "/"
        sketch.settings["default"]["SECURITY_PASSWORD_HASH"] = "argon2"

        sketch.add_extensions("auth")

        sketch.secrets["default"]["SECURITY_PASSWORD_SALT"] = random_string()

        sketch.write_template(
            "security_web_only_tpl",
            templates.commands,
            pjoin(
                sketch.app_folder,
                "commands",
                "__init__.py",
            ),
        )

        sketch.write_template(
            "ext_security_web_only_tpl",
            templates.ext,
            pjoin(sketch.app_folder, "ext", "auth.py"),
        )

        sketch.write_template(
            "models_security_web_only_tpl",
            templates.models,
            pjoin(sketch.app_folder, "models", "user.py"),
        )

        sketch.write_template(
            "examples_security_auth_tpl",
            templates.examples,
            pjoin(
                sketch.app_folder,
                "examples",
                "auth_examples.py",
            ),
        )

        sketch.write_template(
            "examples_init_security_tpl",
            templates.examples,
            pjoin(
                sketch.app_folder,
                "examples",
                "__init__.py",
            ),
        )

        return True
示例#5
0
def handle_sql_db(sketch: Sketch):
    sketch.add_requirements("flask-sqlalchemy")

    sketch.settings["default"]["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    sketch.settings["development"]["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
    sketch.settings["default"][
        "SQLALCHEMY_DATABASE_URI"] = "sqlite:///db.sqlite3"

    sketch.add_extensions("database")

    sketch.write_template(
        "ext_sqlalchemy_tpl",
        templates.ext,
        pjoin(sketch.app_folder, "ext", "database.py"),
    )
示例#6
0
def handle_debugtoolbar(sketch: Sketch):
    sketch.add_requirements("flask-debugtoolbar", dev=True)

    sketch.add_extensions("debugtoolbar")

    sketch.settings["development"]["DEBUG_TB_INTERCEPT_REDIRECTS"] = False
    if sketch.config_framework != "dynaconf":
        sketch.write_template(
            "ext_debugtoolbar_tpl",
            templates.ext,
            pjoin(
                sketch.app_folder,
                "ext",
                "debugtoolbar.py",
            ),
        )
示例#7
0
def handle_admin(sketch: Sketch):
    sketch.add_requirements("flask-admin")

    sketch.add_extensions("admin")

    sketch.settings["default"]["ADMIN_TEMPLATE_MODE"] = "bootstrap3"
    sketch.settings["development"][
        "ADMIN_NAME"] = f"{sketch.project_name} (Dev)"
    sketch.settings["testing"][
        "ADMIN_NAME"] = f"{sketch.project_name} (Testing)"
    sketch.settings["production"]["ADMIN_NAME"] = sketch.project_name

    # TODO refact this part to not use a lot of if statements
    if sketch.auth_framework == "security_web":
        sketch.write_template(
            "ext_admin_security_tpl",
            templates.ext.admin,
            pjoin(
                sketch.app_folder,
                "ext",
                "admin",
                "__init__.py",
            ),
        )