setup_app.py 676 Bytes
Newer Older
Nicolas Joyard's avatar
Nicolas Joyard committed
1 2 3 4 5 6 7
# -*- coding: utf-8 -*-

import os

from flask import Flask
from flaskext.markdown import Markdown

Nicolas Joyard's avatar
Nicolas Joyard committed
8
from .config import get_secret_key
Nicolas Joyard's avatar
Nicolas Joyard committed
9 10 11
from .routes import setup_routes


Nicolas Joyard's avatar
Nicolas Joyard committed
12

Nicolas Joyard's avatar
Nicolas Joyard committed
13 14 15 16 17 18 19 20 21
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 35
    # Setup DB
    from .models import db
    db.init_app(app)

    # Enable Markdown
    Markdown(app)

    # Setup routes
    setup_routes(app)

    return app