Exemple #1
0
def make_app(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.

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

    with app.app_context():
        if not testing:
            Logger.init(app)
            init_sentry(app)
        celery.init_app(app)
        cache.init_app(app)
        babel.init_app(app)
        if config.DEFAULT_LOCALE not in get_all_locales():
            Logger.get('i18n').error(
                f'Configured DEFAULT_LOCALE ({config.DEFAULT_LOCALE}) does not exist'
            )
        multipass.init_app(app)
        setup_oauth_provider(app)
        webpack.init_app(app)
        setup_jinja(app)
        configure_db(app)
        mm.init_app(app)  # must be called after `configure_db`!
        limiter.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))))
        setup_jinja_customization(app)
        # Below this points plugins are available, i.e. sending signals makes sense
        add_plugin_blueprints(app)
        # themes can be provided by plugins
        signals.core.app_created.send(app)
        config.validate()
        check_db()

    return app
Exemple #2
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
Exemple #3
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')
        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