2022-02-13 21:49:07 +01:00
|
|
|
import os
|
2024-04-22 20:34:33 +02:00
|
|
|
import tomllib
|
2024-04-21 20:44:08 +02:00
|
|
|
|
2022-01-05 13:42:24 +01:00
|
|
|
from flask import Flask
|
|
|
|
from flask_bcrypt import Bcrypt
|
2024-04-21 20:44:08 +02:00
|
|
|
from flask_login import LoginManager
|
2022-01-05 13:42:24 +01:00
|
|
|
from flask_migrate import Migrate
|
2024-04-21 20:44:08 +02:00
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
2022-01-05 13:42:24 +01:00
|
|
|
from flask_wtf.csrf import CSRFProtect
|
|
|
|
|
2024-06-29 15:21:47 +02:00
|
|
|
|
2024-04-22 20:34:33 +02:00
|
|
|
APP = Flask(__name__, static_folder="static")
|
2022-01-05 13:42:24 +01:00
|
|
|
db = SQLAlchemy()
|
|
|
|
migrate = Migrate()
|
|
|
|
bcrypt = Bcrypt()
|
|
|
|
login_manager = LoginManager()
|
|
|
|
|
|
|
|
|
|
|
|
def create_app():
|
2024-05-28 23:02:17 +02:00
|
|
|
APP.secret_key = os.urandom(24)
|
|
|
|
APP.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///distribusiverse.db"
|
|
|
|
APP.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
|
2022-01-05 13:42:24 +01:00
|
|
|
|
2024-05-28 23:02:17 +02:00
|
|
|
APP.config["MAX_CONTENT_LENGTH"] = 1024 * 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"
|
2022-03-25 15:37:00 +01:00
|
|
|
|
2024-05-28 23:02:17 +02:00
|
|
|
login_manager.session_protection = "strong"
|
|
|
|
login_manager.login_view = "index"
|
|
|
|
login_manager.login_message_category = "info"
|
2022-01-05 13:42:24 +01:00
|
|
|
|
2024-05-28 23:02:17 +02:00
|
|
|
csrf = CSRFProtect()
|
2022-01-05 13:42:24 +01:00
|
|
|
|
2024-05-28 23:02:17 +02:00
|
|
|
APP.config["SECRET_KEY"] = os.urandom(24)
|
|
|
|
APP.config["UPLOAD_FOLDER"] = "tmpupload"
|
|
|
|
APP.config["PUBLIC_THEMES"] = "themes/publicthemes"
|
2022-01-05 13:42:24 +01:00
|
|
|
|
2024-05-28 23:02:17 +02:00
|
|
|
# user settings_file
|
|
|
|
settings()
|
2024-04-22 20:34:33 +02:00
|
|
|
|
2024-05-28 23:02:17 +02:00
|
|
|
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)
|
2022-01-05 13:42:24 +01:00
|
|
|
|
2024-05-28 23:02:17 +02:00
|
|
|
@APP.context_processor
|
|
|
|
def inject_title():
|
|
|
|
return dict(title=APP.config["title"])
|
2024-04-22 20:34:33 +02:00
|
|
|
|
2024-05-28 23:02:17 +02:00
|
|
|
return APP
|
2024-04-22 20:34:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
def settings():
|
2024-05-28 23:02:17 +02:00
|
|
|
settings = settings_from_file()
|
|
|
|
APP.config.update(settings)
|
|
|
|
return APP
|
2024-04-22 20:34:33 +02:00
|
|
|
|
|
|
|
|
2024-04-28 13:04:07 +02:00
|
|
|
def get_app():
|
2024-05-28 23:02:17 +02:00
|
|
|
return APP
|
2024-04-28 13:04:07 +02:00
|
|
|
|
|
|
|
|
2024-04-22 20:34:33 +02:00
|
|
|
def settings_from_file():
|
2024-05-28 23:02:17 +02:00
|
|
|
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)
|