dbdbb77daf
Struttura monorepo completa con server FastAPI e client Flask: - Server: FastAPI + SQLAlchemy 2.0 async + Alembic migrations - Client: Flask + blueprints (auth, measure, maker, statistics) - Database: docker-compose MySQL 8.0 + Alembic async config - Config: pydantic-settings, TailwindCSS, Flask-Babel i18n - Piano implementazione completo (18 sezioni, 1600 righe) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
"""TieMeasureFlow Client - Flask Entry Point."""
|
|
import os
|
|
|
|
from flask import Flask, redirect, url_for, session, request
|
|
from flask_babel import Babel
|
|
|
|
from config import Config
|
|
|
|
|
|
def get_locale():
|
|
"""Get user's preferred language from session or Accept-Language header."""
|
|
# 1. User preference in session
|
|
if "language" in session:
|
|
return session["language"]
|
|
# 2. Browser Accept-Language
|
|
return request.accept_languages.best_match(
|
|
Config.LANGUAGES.keys(), default="it"
|
|
)
|
|
|
|
|
|
def create_app() -> Flask:
|
|
"""Application factory."""
|
|
app = Flask(__name__)
|
|
app.config.from_object(Config)
|
|
|
|
# Initialize Flask-Babel
|
|
Babel(app, locale_selector=get_locale)
|
|
|
|
# Register blueprints
|
|
from blueprints.auth import auth_bp
|
|
from blueprints.measure import measure_bp
|
|
from blueprints.maker import maker_bp
|
|
from blueprints.statistics import statistics_bp
|
|
|
|
app.register_blueprint(auth_bp)
|
|
app.register_blueprint(measure_bp, url_prefix="/measure")
|
|
app.register_blueprint(maker_bp, url_prefix="/maker")
|
|
app.register_blueprint(statistics_bp, url_prefix="/statistics")
|
|
|
|
@app.route("/")
|
|
def index():
|
|
"""Root redirect to login or dashboard based on session."""
|
|
if "user" in session:
|
|
return redirect(url_for("measure.select_recipe"))
|
|
return redirect(url_for("auth.login"))
|
|
|
|
@app.context_processor
|
|
def inject_globals():
|
|
"""Inject global variables into all templates."""
|
|
return {
|
|
"current_user": session.get("user"),
|
|
"current_theme": session.get("theme", "light"),
|
|
"current_language": get_locale(),
|
|
"languages": Config.LANGUAGES,
|
|
}
|
|
|
|
return app
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = create_app()
|
|
app.run(
|
|
host=os.getenv("CLIENT_HOST", "0.0.0.0"),
|
|
port=int(os.getenv("CLIENT_PORT", "5000")),
|
|
debug=True,
|
|
)
|