from flask import Flask, request from flask_migrate import Migrate # Add this line from .config import Config from .db import db from .models import init_schedule_config from .models import ActivityLog, ActivityCategory from .blueprints import register_blueprints def create_app(test_config=None): app = Flask(__name__) app.config.from_object(Config) # Celery configuration app.config['CELERY_BROKER_URL'] = app.config.get('CELERY_BROKER_URL', 'redis://localhost:6379/0') app.config['CELERY_RESULT_BACKEND'] = app.config.get('CELERY_RESULT_BACKEND', 'redis://localhost:6379/0') if test_config: app.config.update(test_config) db.init_app(app) migrate = Migrate(app, db) with app.app_context(): db.create_all() init_schedule_config() @app.context_processor def inject_app_title(): return {"app_title": app.config["APP_TITLE"]} register_blueprints(app) @app.before_request def before_request(): # Skip logging for static files, health checks, or other frequent requests if request.path.startswith('/static/') or request.path == '/health' or request.path == '/favicon.ico': return # Skip task status checks to avoid log spam if request.path.startswith('/task_status/'): return action = request.endpoint or request.path or "unknown_request" ActivityLog.log_gui_interaction( action=action, description=f"Request to {request.path}", extra={"method": request.method, "url": request.url} ) return app