import os import tomllib from flask import Flask from flask_bcrypt import Bcrypt from flask_login import LoginManager from flask_migrate import Migrate from flask_sqlalchemy import SQLAlchemy from flask_wtf.csrf import CSRFProtect APP = Flask(__name__, static_folder="static") db = SQLAlchemy() migrate = Migrate() bcrypt = Bcrypt() login_manager = LoginManager() def create_app(): APP.secret_key = "secret-key" APP.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///distribusiverse.db" APP.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True APP.config["MAX_CONTENT_LENGTH"] = 150 * 1024 * 1024 APP.config["MAIL_SERVER"] = "mail.autonomic.zone" APP.config["MAIL_PORT"] = 587 APP.config["MAIL_USE_SSL"] = False APP.config["MAIL_USE_TLS"] = True APP.config["MAIL_USERNAME"] = "noreply@vvvvvvaria.org" login_manager.session_protection = "strong" login_manager.login_view = "index" login_manager.login_message_category = "info" csrf = CSRFProtect() APP.config["SECRET_KEY"] = os.urandom(24) APP.config["UPLOAD_FOLDER"] = "tmpupload" APP.config["PUBLIC_THEMES"] = "themes/publicthemes" # user settings_file settings() csrf.init_app(APP) login_manager.init_app(APP) db.init_app(APP) migrate.init_app(APP, db, render_as_batch=True) bcrypt.init_app(APP) @APP.context_processor def inject_title(): return dict(title=APP.config["title"]) return APP def settings(): settings = settings_from_file() APP.config.update(settings) return APP def settings_from_file(): settings = {} if os.path.isfile("settings_development.toml"): with open("settings_development.toml", "rb") as settings_file: return tomllib.load(settings_file) with open("settings.toml", "rb") as settings_file: return tomllib.load(settings_file)