Beispiel #1
0
def test_flaskbbdomain_translations():
    domain = FlaskBBDomain(current_app)

    assert domain.get_translations_cache() == {}

    # returns an translation object
    assert domain.get_translations() is not None

    assert len(domain.get_translations_cache()) > 0
Beispiel #2
0
def test_flaskbbdomain_translations(default_settings):
    domain = FlaskBBDomain(current_app)

    with current_app.test_request_context():
        assert domain.get_translations_cache() == {}

        # just to be on the safe side that there are really no compiled
        # translations available
        _remove_compiled_translations()
        # no compiled translations are available
        assert isinstance(domain.get_translations(), NullTranslations)

        # lets compile them and test again
        _compile_translations()

        # now there should be translations :)
        assert isinstance(domain.get_translations(), Translations)
Beispiel #3
0
def configure_translations(app):
    """Configure translations."""

    # we have to initialize the extension after we have loaded the plugins
    # because we of the 'flaskbb_load_translations' hook
    babel.init_app(app=app, default_domain=FlaskBBDomain(app))

    @babel.localeselector
    def get_locale():
        # if a user is logged in, use the locale from the user settings
        if (current_user and current_user.is_authenticated
                and current_user.language):
            return current_user.language
        # otherwise we will just fallback to the default language
        return flaskbb_config["DEFAULT_LANGUAGE"]
Beispiel #4
0
def configure_extensions(app):
    """Configures the extensions."""

    # Flask-WTF CSRF
    csrf.init_app(app)

    # Flask-Plugins
    plugin_manager.init_app(app)

    # Flask-SQLAlchemy
    db.init_app(app)

    # Flask-Migrate
    migrate.init_app(app, db)

    # Flask-Mail
    mail.init_app(app)

    # Flask-Cache
    cache.init_app(app)

    # Flask-Debugtoolbar
    debugtoolbar.init_app(app)

    # Flask-Themes
    themes.init_themes(app, app_identifier="flaskbb")

    # Flask-And-Redis
    redis_store.init_app(app)

    # Flask-WhooshAlchemy
    with app.app_context():
        whoosh_index(app, Post)
        whoosh_index(app, Topic)
        whoosh_index(app, Forum)
        whoosh_index(app, Category)
        whoosh_index(app, User)

    # Flask-Login
    login_manager.login_view = app.config["LOGIN_VIEW"]
    login_manager.refresh_view = app.config["REAUTH_VIEW"]
    login_manager.anonymous_user = Guest

    @login_manager.user_loader
    def load_user(user_id):
        """Loads the user. Required by the `login` extension."""

        user_instance = User.query.filter_by(id=user_id).first()
        if user_instance:
            return user_instance
        else:
            return None

    login_manager.init_app(app)

    # Flask-BabelEx
    babel.init_app(app=app, default_domain=FlaskBBDomain(app))

    @babel.localeselector
    def get_locale():
        # if a user is logged in, use the locale from the user settings
        if current_user.is_authenticated and current_user.language:
            return current_user.language
        # otherwise we will just fallback to the default language
        return flaskbb_config["DEFAULT_LANGUAGE"]

    # Flask-Allows
    allows.init_app(app)
    allows.identity_loader(lambda: current_user)
Beispiel #5
0
def configure_extensions(app):
    """Configures the extensions."""

    # Flask-WTF CSRF
    csrf.init_app(app)

    # Flask-Plugins
    plugin_manager.init_app(app)

    # Flask-SQLAlchemy
    db.init_app(app)

    # Flask-Alembic
    alembic.init_app(app, command_name="db")

    # Flask-Mail
    mail.init_app(app)

    # Flask-Cache
    cache.init_app(app)

    # Flask-Debugtoolbar
    debugtoolbar.init_app(app)

    # Flask-Themes
    themes.init_themes(app, app_identifier="flaskbb")

    # Flask-And-Redis
    redis_store.init_app(app)

    # Flask-Limiter
    limiter.init_app(app)

    # Flask-Whooshee
    whooshee.init_app(app)
    # not needed for unittests - and it will speed up testing A LOT
    if not app.testing:
        whooshee.register_whoosheer(PostWhoosheer)
        whooshee.register_whoosheer(TopicWhoosheer)
        whooshee.register_whoosheer(ForumWhoosheer)
        whooshee.register_whoosheer(UserWhoosheer)

    # Flask-Login
    login_manager.login_view = app.config["LOGIN_VIEW"]
    login_manager.refresh_view = app.config["REAUTH_VIEW"]
    login_manager.login_message_category = app.config["LOGIN_MESSAGE_CATEGORY"]
    login_manager.needs_refresh_message_category = \
        app.config["REFRESH_MESSAGE_CATEGORY"]
    login_manager.anonymous_user = Guest

    @login_manager.user_loader
    def load_user(user_id):
        """Loads the user. Required by the `login` extension."""

        user_instance = User.query.filter_by(id=user_id).first()
        if user_instance:
            return user_instance
        else:
            return None

    login_manager.init_app(app)

    # Flask-BabelEx
    babel.init_app(app=app, default_domain=FlaskBBDomain(app))

    @babel.localeselector
    def get_locale():
        # if a user is logged in, use the locale from the user settings
        if current_user and \
                current_user.is_authenticated and current_user.language:
            return current_user.language
        # otherwise we will just fallback to the default language
        return flaskbb_config["DEFAULT_LANGUAGE"]

    # Flask-Allows
    allows.init_app(app)
    allows.identity_loader(lambda: current_user)
Beispiel #6
0
def configure_extensions(app):
    """
    Configures the extensions
    """
    # Flask-Restful
    restful.init_app(app)

    # Flask-Plugins
    plugin_manager.init_app(app)

    # Flask-SQLAlchemy
    db.init_app(app)

    # Flask-Migrate
    migrate.init_app(app, db)

    # Flask-Mail
    mail.init_app(app)

    # Flask-Cache
    cache.init_app(app)

    # Flask-Debugtoolbar
    debugtoolbar.init_app(app)

    # Flask-Themes
    themes.init_themes(app, app_identifier="flaskbb")

    # Flask-And-Redis
    redis_store.init_app(app)

    # Flask-WhooshAlchemy
    with app.app_context():
        whoosh_index(app, Post)
        whoosh_index(app, Topic)
        whoosh_index(app, Forum)
        whoosh_index(app, Category)
        whoosh_index(app, User)

    # Flask-Login
    login_manager.login_view = app.config["LOGIN_VIEW"]
    login_manager.refresh_view = app.config["REAUTH_VIEW"]
    login_manager.anonymous_user = Guest

    @login_manager.user_loader
    def load_user(id):
        """
        Loads the user. Required by the `login` extension
        """
        unread_count = db.session.query(db.func.count(PrivateMessage.id)).\
            filter(PrivateMessage.unread,
                   PrivateMessage.user_id == id).subquery()
        u = db.session.query(User, unread_count).filter(User.id == id).first()

        if u:
            user, user.pm_unread = u
            return user
        else:
            return None

    login_manager.init_app(app)

    # Flask-BabelEx
    babel.init_app(app=app, default_domain=FlaskBBDomain(app))

    @babel.localeselector
    def get_locale():
        # if a user is logged in, use the locale from the user settings
        if current_user.is_authenticated() and current_user.language:
            return current_user.language
        # otherwise we will just fallback to the default language
        return flaskbb_config["DEFAULT_LANGUAGE"]