Beispiel #1
0
def configure_extensions(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-babel
    babel = Babel(app)

    @babel.localeselector
    def get_locale():
        return request.accept_languages.best_match(DefaultConfig.LANGUAGES)

    # flask-login
    login_manager.login_view = 'frontend.login'
    login_manager.refresh_view = 'frontend.reauth'

    @login_manager.user_loader
    def load_user(id):
        return User.query.get(id)
    login_manager.setup_app(app)
Beispiel #2
0
def configure_extensions(app):
    # sqlalchemy
    db.init_app(app)
    # mail
    mail.init_app(app)
    # cache
    cache.init_app(app)

    # babel
    babel = Babel(app)

    @babel.localeselector
    def get_locale():
        accept_languages = app.config.get("ACCEPT_LANGUAGES")
        return request.accept_languages.best_match(accept_languages)

    # login.
    login_manager.login_view = "frontend.login"
    login_manager.refresh_view = "frontend.reauth"

    @login_manager.user_loader
    def load_user(id):
        return User.query.get(int(id))

    login_manager.setup_app(app)
Beispiel #3
0
def configure_extensions(app):
    # flask-sqlalchemy
    db.init_app(app)

    # flask-mail
    mail.init_app(app)

    # flask-cache
    cache.init_app(app)

    # flask-babel
    babel = Babel(app)
    @babel.localeselector
    def get_locale():
        override = request.args.get('lang')
        if override:
            session['lang'] = override
            return session.get('lang', 'en')
        else:
            accept_languages = app.config.get('ACCEPT_LANGUAGES')
            return request.accept_languages.best_match(accept_languages)

    # flask-login
    login_manager.login_view = 'frontend.login'
    login_manager.refresh_view = 'frontend.reauth'
    @login_manager.user_loader
    def load_user(id):
        return User.query.get(id)
    login_manager.setup_app(app)

    # flask-admin
    admin = Admin()
    # Setup locale
    admin.locale_selector(get_locale)
    # Views
    # Model admin
    admin.add_view(ModelView(User, db.session, endpoint='usermodel', category='Model'))
    admin.add_view(ModelView(UserDetail, db.session, endpoint='userdetailmodel', category='Model'))
    admin.add_view(ModelView(Role, db.session, endpoint='rolemodel', category='Model'))
    # File admin 
    path = os.path.join(os.path.dirname(__file__), 'static/img/users')
    # Create directory if existed.
    try:
        os.mkdir(path)
    except OSError:
        pass
    admin.add_view(FileAdmin(path, '/static/img/users', endpoint='useravatar', name='User Avatars', category='Image'))
    admin.init_app(app)
Beispiel #4
0
def configure_extensions(app):
    # sqlalchemy
    db.init_app(app)
    # mail
    mail.init_app(app)
    # cache
    cache.init_app(app)

    # babel
    babel = Babel(app)
    @babel.localeselector
    def get_locale():
        accept_languages = app.config.get('ACCEPT_LANGUAGES')
        return request.accept_languages.best_match(accept_languages)

    # login.
    login_manager.login_view = 'frontend.login'
    login_manager.refresh_view = 'frontend.reauth'
    @login_manager.user_loader
    def load_user(id):
        return User.query.get(int(id))
    login_manager.setup_app(app)
Beispiel #5
0
def configure_extensions(app):
    # flask-sqlalchemy
    db.init_app(app)

    # flask-mail
    mail.init_app(app)

    # flask-cache
    cache.init_app(app)

    # flask-babel
    babel = Babel(app)
    @babel.localeselector
    def get_locale():
        accept_languages = app.config.get('ACCEPT_LANGUAGES')
        return request.accept_languages.best_match(accept_languages)

    # flask-login
    login_manager.login_view = 'frontend.login'
    login_manager.refresh_view = 'frontend.reauth'
    @login_manager.user_loader
    def load_user(id):
        return User.query.get(int(id))
    login_manager.setup_app(app)

    # flask-admin
    admin = Admin()
    # Views
    # Model admin
    admin.add_view(ModelView(User, db.session, endpoint='usermodel', category='Model'))
    admin.add_view(ModelView(UserDetail, db.session, endpoint='userdetailmodel', category='Model'))
    admin.add_view(ModelView(Role, db.session, endpoint='rolemodel', category='Model'))
    # File admin 
    path = os.path.join(os.path.dirname(__file__), 'static/img/users')
    admin.add_view(FileAdmin(path, '/static/img/users', endpoint='useravatar', name='User Avatars', category='Image'))
    admin.init_app(app)