feat: initial Flask project setup with factory pattern

This commit is contained in:
2026-03-11 16:23:39 +01:00
parent 3b3a5e4187
commit 41679d1861
13 changed files with 119 additions and 0 deletions

39
app/__init__.py Normal file
View File

@@ -0,0 +1,39 @@
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import tomllib
import os
db = SQLAlchemy()
def create_app(config_path=None):
app = Flask(__name__, instance_relative_config=True)
os.makedirs(app.instance_path, exist_ok=True)
app.config["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{os.path.join(app.instance_path, 'worklog.db')}"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "dev-secret-change-in-prod")
# Load TOML config
if config_path is None:
config_path = os.path.join(os.path.dirname(app.root_path), "config.toml")
if os.path.exists(config_path):
with open(config_path, "rb") as f:
app.config["TOML"] = tomllib.load(f)
else:
app.config["TOML"] = {}
db.init_app(app)
from app.routes.dashboard import bp as dashboard_bp
from app.routes.entries import bp as entries_bp
from app.routes.reports import bp as reports_bp
app.register_blueprint(dashboard_bp)
app.register_blueprint(entries_bp)
app.register_blueprint(reports_bp)
with app.app_context():
db.create_all()
return app

Binary file not shown.

0
app/routes/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
app/routes/dashboard.py Normal file
View File

@@ -0,0 +1,3 @@
from flask import Blueprint
bp = Blueprint("dashboard", __name__)

3
app/routes/entries.py Normal file
View File

@@ -0,0 +1,3 @@
from flask import Blueprint
bp = Blueprint("entries", __name__)

3
app/routes/reports.py Normal file
View File

@@ -0,0 +1,3 @@
from flask import Blueprint
bp = Blueprint("reports", __name__)