Пример #1
0
def configure_extensions(app):
    # configure extensions
    # sqlalchemy
    db.init_app(app)
    db_ean.init_app(app)
    # mail
    mail.init_app(app)
    # cache
    cache.init_app(app)
    # babel
    babel = Babel(app)
    # 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)
    # security and Social
    app.flask_security = Security(app, SQLAlchemyUserDatastore(db, User, Role))
    #app.flask_social = Social(app, SQLAlchemyConnectionDatastore(db, Connection))
    # admin
    admin = Admin(app)
    #admin.add_view(ModelView(GenomeRule, db.session))
    admin.add_view(GenomeRuleView(db.session, name="Genome Rules"))
    admin.add_view(GenomeCategoryView(db.session, name="Genome Categories"))
Пример #2
0
def register_extensions(app: Flask) -> None:
    """Registers flask extensions to the application object.

    Args:
        app (Flask): The flask application object.
    """
    db.init_app(app)
    migrate.init_app(app, db, render_as_batch=True)
    api_.init_app(app)
    jwt.init_app(app)
    cache.init_app(app)
Пример #3
0
def register_extensions(app):
    """Register Flask extensions."""
    assets.init_app(app)
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
Пример #4
0
def register_extensions(app):
    """Register Flask extensions."""
    assets.init_app(app)
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
Пример #5
0
def create_app(object_name):
    app = Flask(__name__)
    app.config.from_object(object_name)

    db.init_app(app)

    bcrypt.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    cache.init_app(app)

    rest_api = Api(app)
    rest_api.add_resource(PostApi,
            '/restapi/post',
            '/restapi/post/<int:post_id>',
            endpoint='restapi')

    app.register_blueprint(main_blueprint)
    app.register_blueprint(blog_blueprint)
    return app
Пример #6
0
def create_app(testing=False):
    app = flask.Flask(__name__,
                      template_folder='../templates',
                      static_folder='../static')

    app.config.from_object('webapp.config')
    app.testing = testing

    app.wsgi_app = ProxyFix(app.wsgi_app)
    if app.debug:
        app.wsgi_app = DebuggedApplication(app.wsgi_app)

    app.url_map.strict_slashes = False
    app.url_map.converters['regex'] = helpers.RegexConverter

    if not testing:
        talisker.flask.register(app)

        prometheus_flask_exporter.PrometheusMetrics(
            app,
            group_by_endpoint=True,
            buckets=[0.25, 0.5, 0.75, 1, 2],
            path=None)

        init_extensions(app)

    app.config.from_object('webapp.configs.' + app.config['WEBAPP'])
    cache.init_app(app)
    with app.app_context():
        cache.clear()

    set_handlers(app)

    if app.config['WEBAPP'] == 'snapcraft':
        init_snapcraft(app)
    else:
        init_brandstore(app)

    return app
Пример #7
0
def create_app(object_name):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. webapp.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """
    app = Flask(__name__)
    """SXI"""
    app.config.from_object(object_name)

    db = SQLAlchemy(app)
    # initialize the cache
    cache.init_app(app)

    # initialize the debug tool bar
    debug_toolbar.init_app(app)

    # initialize SQLAlchemy
    db.init_app(app)

    login_manager.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    # register our blueprints
    app.register_blueprint(main)

    main.app = app

    return app
Пример #8
0
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. webapp.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config['ENV'] = env

    # initialize the cache
    cache.init_app(app)

    # initialize the debug tool bar
    debug_toolbar.init_app(app)

    # initialize SQLAlchemy
    db.init_app(app)

    login_manager.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    # register our blueprints
    app.register_blueprint(main)

    return app
Пример #9
0
def configure_extensions(app):

    db.init_app(app)
    mail.init_app(app)
    cache.init_app(app)
Пример #10
0
def configure_extensions(app):

    db.init_app(app)
    mail.init_app(app)
    cache.init_app(app)
Пример #11
0
def create_app(object_name):
    app = Flask(__name__)
    app.config.from_object(object_name)

    #db.init_app(app)
    #event.listen(Reminder, 'after_insert', on_reminder_save)


    db.init_app(app)
    bcrypt.init_app(app)
    login_manager.init_app(app)
    principals.init_app(app)
    celery.init_app(app)
    debug_toolbar.init_app(app)
    cache.init_app(app)
    admin.init_app(app)
    admin.add_view(CustomView(name='Custom'))

    models = [User,Role,Comment,Tag]
    for model in models:
        admin.add_view(CustomModelView(model,db.session,category='Models'))

    admin.add_view(
        PostView(
            Post, db.session, category='PostManager'
        )
    )
    admin.add_view(
        CustomFileAdmin(
            os.path.join(os.path.dirname(__file__), 'static'),
            '/static/',
            name='Static Files'
        )
    )

    rest_api.add_resource(
        AuthApi,
        '/api/auth',
    )
    rest_api.add_resource(
        PostApi,
        '/api/post',
        '/api/post/<int:post_id>',
    )
    rest_api.add_resource(
        CommentApi,
        '/api/comment',
        '/api/comment/<int:comment_id>',
        '/api/post/<int:post_id>/comment',
        '/api/post/<int:post_id>/comment/<int:comment_id>',
    )
    rest_api.init_app(app)



    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        # Set the identity user object
        identity.user = current_user
        print "In __init_.py......:%s" %current_user

        # Add the UserNeed to the identity
        if hasattr(current_user, 'id'):
            identity.provides.add(UserNeed(current_user.id))
            print UserNeed(current_user.id)

        # Add each role to the identity
        if hasattr(current_user, 'roles'):
            for role in current_user.roles:
                identity.provides.add(RoleNeed(role.name))
                print RoleNeed(role.name)



    app.register_blueprint(blog_blueprint)
    app.register_blueprint(main_blueprint)

    return app
Пример #12
0
def create_app(object_name):
    app = Flask(__name__)
    app.config.from_object(object_name)

    db.init_app(app)
    event.listen(Reminder, 'after_insert', on_reminder_save)
    bcrypt.init_app(app)
    oid.init_app(app)
    login_manager.init_app(app)
    principals.init_app(app)
    rest_api.add_resource(PostApi,
                          '/api/post',
                          '/api/post/<int:post_id>',
                          endpoint='api')
    rest_api.add_resource(AuthApi, '/api/auth', endpoint='auth')
    rest_api.init_app(app)
    celery.init_app(app)
    debug_toolbar.init_app(app)
    cache.init_app(app)
    assets_env.init_app(app)
    assets_env.register("main_js", main_js)
    assets_env.register("main_css", main_css)
    admin.init_app(app)
    # admin.add_view(CustomView(name="Custom"))
    # models = [User, Role, Post, Comment, Tag, Reminder]
    # for model in models:
    #     if model is not Post:
    #         admin.add_view(
    #             CustomModelView(model, db.session, category="models")
    #         )
    #     else:
    #         admin.add_view(
    #             PostView(Post, db.session, category="models")
    #         )
    admin.add_view(CustomView(name='Custom'))
    admin.add_view(CustomModelView(User, db.session, category="Models"))
    admin.add_view(CustomModelView(Role, db.session, category="Models"))
    #
    # Need to use a special view for Posts to get the CKEditor functionality
    #
    admin.add_view(PostView(Post, db.session, category="Models"))
    admin.add_view(CustomModelView(Comment, db.session, category="Models"))
    admin.add_view(CustomModelView(Tag, db.session, category="Models"))
    admin.add_view(CustomModelView(Reminder, db.session, category="Models"))
    admin.add_view(
        CustomFileAdmin(os.path.join(os.path.dirname(__file__), 'static'),
                        '/static/',
                        name='Static Files'))
    mail.init_app(app)
    youtube_ext.init_app(app)
    #
    # The gzip extension and the debug toolbar can't both be running...
    #
    #    flask_gzip.init_app(app)

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        identity.user = current_user
        if hasattr(current_user, 'id'):
            identity.provides.add(UserNeed(current_user.id))
        if hasattr(current_user, 'roles'):
            for role in current_user.roles:
                identity.provides.add(RoleNeed(role.name))

    #
    # Routes
    #
    @app.route('/')
    def index():
        return redirect(url_for('blog.home'))

    app.register_blueprint(blog_blueprint)
    app.register_blueprint(main_blueprint)

    return app