80 lines
2.8 KiB
Python
80 lines
2.8 KiB
Python
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')
|
|
config_name = 'production' if config_name == 'production' else 'development'
|
|
|
|
app = Flask(__name__)
|
|
app.config.from_object(config[config_name])
|
|
|
|
db.init_app(app)
|
|
login_manager.init_app(app)
|
|
migrate.init_app(app, db)
|
|
csrf.init_app(app)
|
|
|
|
from app.routes.auth import auth_bp
|
|
from app.routes.dashboard import dashboard_bp
|
|
from app.routes.accounts import accounts_bp
|
|
from app.routes.categories import categories_bp
|
|
from app.routes.transactions import transactions_bp
|
|
from app.routes.budgets import budgets_bp
|
|
from app.routes.goals import goals_bp
|
|
from app.routes.investments import investments_bp
|
|
from app.routes.ai import ai_bp
|
|
from app.routes.reports import reports_bp
|
|
from app.routes.settings import settings_bp
|
|
from app.routes.teller import teller_bp
|
|
|
|
app.register_blueprint(auth_bp)
|
|
app.register_blueprint(dashboard_bp)
|
|
app.register_blueprint(accounts_bp)
|
|
app.register_blueprint(categories_bp)
|
|
app.register_blueprint(transactions_bp)
|
|
app.register_blueprint(budgets_bp)
|
|
app.register_blueprint(goals_bp)
|
|
app.register_blueprint(investments_bp)
|
|
app.register_blueprint(ai_bp)
|
|
app.register_blueprint(reports_bp)
|
|
app.register_blueprint(settings_bp)
|
|
app.register_blueprint(teller_bp)
|
|
|
|
with app.app_context():
|
|
from app.models import (
|
|
User, Account, Category, Receipt, RecurringRule,
|
|
Transaction, Budget, Goal, GoalContribution,
|
|
Investment, InvestmentTransaction, NetWorthSnapshot,
|
|
AiInsight, FxRate
|
|
)
|
|
from app.models.teller_enrollment import TellerEnrollment, TellerAccount
|
|
|
|
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
|
|
|
|
@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)
|
|
|
|
@app.template_filter('shares')
|
|
def shares_filter(value):
|
|
"""Format share quantity — strips trailing zeros, keeps up to 8 decimal places."""
|
|
try:
|
|
f = float(value)
|
|
except (TypeError, ValueError):
|
|
return '0'
|
|
# Format to 8 decimal places then strip trailing zeros
|
|
s = '{:.8f}'.format(f).rstrip('0').rstrip('.')
|
|
return s if s else '0'
|
|
|
|
return app
|