diff options
author | erdgeist <erdgeist@erdgeist.org> | 2024-12-22 23:59:10 +0100 |
---|---|---|
committer | erdgeist <erdgeist@erdgeist.org> | 2024-12-22 23:59:10 +0100 |
commit | 4182581f3d540d0a3c95d212c120e2080d18f7cd (patch) | |
tree | f2a4fbd5744d767bd08411eee0e3a8649b01df2b | |
parent | e3481a4a35091b32b6fbee80c1c9ba2b6d7b50d6 (diff) |
use delayed db initialisation to allow parsing parameters in main
-rw-r--r-- | config.json | 2 | ||||
-rwxr-xr-x | 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 @@ | |||
1 | { | 1 | { |
2 | "server-name": "halfnarp.events.ccc.de", | ||
2 | "host": "127.0.0.1", | 3 | "host": "127.0.0.1", |
3 | "port": 5023, | 4 | "port": 5023, |
5 | "database-uri": "postgresql://halfnarp@localhost:5432/halfnarp", | ||
4 | "pretalx-url": "https://cfp.example.de/", | 6 | "pretalx-url": "https://cfp.example.de/", |
5 | "pretalx-token": "<YOUR API KEY HERE>", | 7 | "pretalx-token": "<YOUR API KEY HERE>", |
6 | "pretalx-conference": "38c3" | 8 | "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 | |||
12 | from html_sanitizer import Sanitizer | 12 | from html_sanitizer import Sanitizer |
13 | from hashlib import sha256 | 13 | from hashlib import sha256 |
14 | 14 | ||
15 | app = Flask(__name__) | ||
16 | app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://halfnarp@localhost:5432/halfnarp" | ||
17 | app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False | ||
18 | app.config["SERVER_NAME"] = "halfnarp.events.ccc.de" | ||
19 | app.config["SECRET_KEY"] = "<YOUR SERVER SECRET HERE>" | ||
20 | app.jinja_env.trim_blocks = True | ||
21 | app.jinja_env.lstrip_blocks = True | ||
22 | CORS(app) | ||
23 | |||
24 | db = SQLAlchemy(app) | 15 | db = SQLAlchemy(app) |
25 | 16 | ||
26 | 17 | ||
@@ -276,6 +267,19 @@ if __name__ == "__main__": | |||
276 | config["pretalx-url"] + "api/events/" + config["pretalx-conference"] | 267 | config["pretalx-url"] + "api/events/" + config["pretalx-conference"] |
277 | ) | 268 | ) |
278 | 269 | ||
270 | app = Flask(__name__) | ||
271 | app.config["SQLALCHEMY_DATABASE_URI"] = config.get( | ||
272 | "database-uri", "sqlite:///test.db" | ||
273 | ) | ||
274 | app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False | ||
275 | app.config["SERVER_NAME"] = config.get("server-name", "localhost") | ||
276 | app.config["SECRET_KEY"] = "<YOUR SERVER SECRET HERE>" | ||
277 | app.jinja_env.trim_blocks = True | ||
278 | app.jinja_env.lstrip_blocks = True | ||
279 | CORS() | ||
280 | |||
281 | db.init(app) | ||
282 | |||
279 | with app.app_context(): | 283 | with app.app_context(): |
280 | db.create_all() | 284 | db.create_all() |
281 | if args.pretalx_import: | 285 | if args.pretalx_import: |