feat: initial Flask project setup with factory pattern
This commit is contained in:
39
app/__init__.py
Normal file
39
app/__init__.py
Normal 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
|
||||
BIN
app/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
app/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
0
app/routes/__init__.py
Normal file
0
app/routes/__init__.py
Normal file
BIN
app/routes/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
app/routes/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
BIN
app/routes/__pycache__/dashboard.cpython-314.pyc
Normal file
BIN
app/routes/__pycache__/dashboard.cpython-314.pyc
Normal file
Binary file not shown.
BIN
app/routes/__pycache__/entries.cpython-314.pyc
Normal file
BIN
app/routes/__pycache__/entries.cpython-314.pyc
Normal file
Binary file not shown.
BIN
app/routes/__pycache__/reports.cpython-314.pyc
Normal file
BIN
app/routes/__pycache__/reports.cpython-314.pyc
Normal file
Binary file not shown.
3
app/routes/dashboard.py
Normal file
3
app/routes/dashboard.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from flask import Blueprint
|
||||
|
||||
bp = Blueprint("dashboard", __name__)
|
||||
3
app/routes/entries.py
Normal file
3
app/routes/entries.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from flask import Blueprint
|
||||
|
||||
bp = Blueprint("entries", __name__)
|
||||
3
app/routes/reports.py
Normal file
3
app/routes/reports.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from flask import Blueprint
|
||||
|
||||
bp = Blueprint("reports", __name__)
|
||||
Reference in New Issue
Block a user