setup_app.py 749 Bytes
Newer Older
Nicolas Joyard's avatar
Nicolas Joyard committed
1 2
# -*- coding: utf-8 -*-

3
import locale
Nicolas Joyard's avatar
Nicolas Joyard committed
4 5 6 7 8
import os

from flask import Flask
from flaskext.markdown import Markdown

Nicolas Joyard's avatar
Nicolas Joyard committed
9
from .config import get_secret_key
Nicolas Joyard's avatar
Nicolas Joyard committed
10 11 12 13 14 15 16 17 18 19 20 21
from .routes import setup_routes


def setup_app(name):
    # Create app
    app = Flask(name)

    # Load config
    config_obj = os.environ.get('IRFM_CONFIG',
                                'irfm.config.DefaultConfig')
    app.config.from_object(config_obj)

Nicolas Joyard's avatar
Nicolas Joyard committed
22 23 24
    if not app.config.get('SECRET_KEY'):
        app.config['SECRET_KEY'] = get_secret_key(app.config['DATA_DIR'])

Nicolas Joyard's avatar
Nicolas Joyard committed
25 26 27 28 29 30 31 32 33 34
    # Setup DB
    from .models import db
    db.init_app(app)

    # Enable Markdown
    Markdown(app)

    # Setup routes
    setup_routes(app)

35 36 37
    # Setup locale
    locale.setlocale(locale.LC_ALL, '')

Nicolas Joyard's avatar
Nicolas Joyard committed
38
    return app