05/31 Phase 1: refactor 3
This commit is contained in:
-55
@@ -1,55 +0,0 @@
|
|||||||
import os
|
|
||||||
from flask import Flask
|
|
||||||
from app.config import config
|
|
||||||
from app.extensions import db, login_manager, migrate, csrf
|
|
||||||
from app.utils.formatters import format_currency, format_percent, format_large_number
|
|
||||||
|
|
||||||
|
|
||||||
def create_app(config_name=None):
|
|
||||||
if config_name is None:
|
|
||||||
config_name = os.environ.get('FLASK_ENV', 'development')
|
|
||||||
if config_name == 'production':
|
|
||||||
config_name = 'production'
|
|
||||||
else:
|
|
||||||
config_name = 'development'
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
app.config.from_object(config[config_name])
|
|
||||||
|
|
||||||
# Init extensions
|
|
||||||
db.init_app(app)
|
|
||||||
login_manager.init_app(app)
|
|
||||||
migrate.init_app(app, db)
|
|
||||||
csrf.init_app(app)
|
|
||||||
|
|
||||||
# Register blueprints
|
|
||||||
from app.routes.auth import auth_bp
|
|
||||||
from app.routes.dashboard import dashboard_bp
|
|
||||||
|
|
||||||
app.register_blueprint(auth_bp)
|
|
||||||
app.register_blueprint(dashboard_bp)
|
|
||||||
|
|
||||||
# Import all models so Flask-Migrate can see them
|
|
||||||
with app.app_context():
|
|
||||||
from app.models import (
|
|
||||||
User, Account, Category, Receipt, RecurringRule,
|
|
||||||
Transaction, Budget, Goal, GoalContribution,
|
|
||||||
Investment, InvestmentTransaction, NetWorthSnapshot,
|
|
||||||
AiInsight, FxRate
|
|
||||||
)
|
|
||||||
|
|
||||||
# Jinja2 template globals
|
|
||||||
app.jinja_env.globals['format_currency'] = format_currency
|
|
||||||
app.jinja_env.globals['format_percent'] = format_percent
|
|
||||||
app.jinja_env.globals['format_large_number'] = format_large_number
|
|
||||||
|
|
||||||
# Jinja2 filters
|
|
||||||
@app.template_filter('currency')
|
|
||||||
def currency_filter(value, symbol=None):
|
|
||||||
return format_currency(value, symbol)
|
|
||||||
|
|
||||||
@app.template_filter('percent')
|
|
||||||
def percent_filter(value):
|
|
||||||
return format_percent(value)
|
|
||||||
|
|
||||||
return app
|
|
||||||
Reference in New Issue
Block a user