示例#1
0
def make_app(set_path=False, testing=False, config_override=None):
    # If you are reading this code and wonder how to access the app:
    # >>> from flask import current_app as app
    # This only works while inside an application context but you really shouldn't have any
    # reason to access it outside this method without being inside an application context.
    # When set_path is enabled, SERVER_NAME and APPLICATION_ROOT are set according to BASE_URL
    # so URLs can be generated without an app context, e.g. in the indico shell

    if _app_ctx_stack.top:
        Logger.get('flask').warn(
            'make_app({}) called within app context, using existing app:\n{}'.
            format(set_path, '\n'.join(traceback.format_stack())))
        return _app_ctx_stack.top.app
    app = IndicoFlask('indico',
                      static_folder=None,
                      template_folder='web/templates')
    app.config['TESTING'] = testing
    app.config['INDICO'] = load_config(only_defaults=testing,
                                       override=config_override)
    configure_app(app, set_path)

    with app.app_context():
        if not testing:
            Logger.init(app)
        celery.init_app(app)
        babel.init_app(app)
        multipass.init_app(app)
        oauth.init_app(app)
        setup_mako(app)
        setup_jinja(app)

        core_env.init_app(app)
        setup_assets()

        configure_db(app)
        mm.init_app(app)
        extend_url_map(app)
        add_handlers(app)
        setup_request_stats(app)
        add_blueprints(app)
        plugin_engine.init_app(app, Logger.get('plugins'))
        if not plugin_engine.load_plugins(app):
            raise Exception('Could not load some plugins: {}'.format(', '.join(
                plugin_engine.get_failed_plugins(app))))
        # Below this points plugins are available, i.e. sending signals makes sense
        add_plugin_blueprints(app)
        # themes can be provided by plugins
        register_theme_sass()
        signals.app_created.send(app)
    return app
示例#2
0
文件: app.py 项目: bkolobara/indico
def make_app(set_path=False, testing=False, config_override=None):
    # If you are reading this code and wonder how to access the app:
    # >>> from flask import current_app as app
    # This only works while inside an application context but you really shouldn't have any
    # reason to access it outside this method without being inside an application context.
    # When set_path is enabled, SERVER_NAME and APPLICATION_ROOT are set according to BASE_URL
    # so URLs can be generated without an app context, e.g. in the indico shell

    if _app_ctx_stack.top:
        Logger.get('flask').warn('make_app called within app context, using existing app')
        return _app_ctx_stack.top.app
    app = IndicoFlask('indico', static_folder=None, template_folder='web/templates')
    app.config['TESTING'] = testing
    app.config['INDICO'] = load_config(only_defaults=testing, override=config_override)
    configure_app(app, set_path)

    with app.app_context():
        if not testing:
            Logger.init(app)
        celery.init_app(app)
        babel.init_app(app)
        multipass.init_app(app)
        oauth.init_app(app)
        setup_mako(app)
        setup_jinja(app)

        core_env.init_app(app)
        setup_assets()

        configure_db(app)
        mm.init_app(app)
        extend_url_map(app)
        add_handlers(app)
        setup_request_stats(app)
        add_blueprints(app)
        plugin_engine.init_app(app, Logger.get('plugins'))
        if not plugin_engine.load_plugins(app):
            raise Exception('Could not load some plugins: {}'.format(', '.join(plugin_engine.get_failed_plugins(app))))
        # Below this points plugins are available, i.e. sending signals makes sense
        add_plugin_blueprints(app)
        # themes can be provided by plugins
        register_theme_sass()
        signals.app_created.send(app)
    return app