From 4182581f3d540d0a3c95d212c120e2080d18f7cd Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 22 Dec 2024 23:59:10 +0100 Subject: use delayed db initialisation to allow parsing parameters in main --- config.json | 2 ++ halfnarp2.py | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/config.json b/config.json index e139d93..1ba9ca3 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,8 @@ { + "server-name": "halfnarp.events.ccc.de", "host": "127.0.0.1", "port": 5023, + "database-uri": "postgresql://halfnarp@localhost:5432/halfnarp", "pretalx-url": "https://cfp.example.de/", "pretalx-token": "", "pretalx-conference": "38c3" diff --git a/halfnarp2.py b/halfnarp2.py index ebd6f6b..5451411 100755 --- a/halfnarp2.py +++ b/halfnarp2.py @@ -12,15 +12,6 @@ import markdown from html_sanitizer import Sanitizer from hashlib import sha256 -app = Flask(__name__) -app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://halfnarp@localhost:5432/halfnarp" -app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False -app.config["SERVER_NAME"] = "halfnarp.events.ccc.de" -app.config["SECRET_KEY"] = "" -app.jinja_env.trim_blocks = True -app.jinja_env.lstrip_blocks = True -CORS(app) - db = SQLAlchemy(app) @@ -276,6 +267,19 @@ if __name__ == "__main__": config["pretalx-url"] + "api/events/" + config["pretalx-conference"] ) + app = Flask(__name__) + app.config["SQLALCHEMY_DATABASE_URI"] = config.get( + "database-uri", "sqlite:///test.db" + ) + app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False + app.config["SERVER_NAME"] = config.get("server-name", "localhost") + app.config["SECRET_KEY"] = "" + app.jinja_env.trim_blocks = True + app.jinja_env.lstrip_blocks = True + CORS() + + db.init(app) + with app.app_context(): db.create_all() if args.pretalx_import: -- cgit v1.2.3