Ejemplo n.º 1
0
def create_app(config_object):
    app = Flask(__name__)
    app.config.from_object(config_object)

    db.init_app(app)
    login_manager.init_app(app)
    principal.init_app(app)

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

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        # Set the identity user object
        identity.user = current_user

        # Add the UserNeed to the identity
        if hasattr(current_user, 'id'):
            identity.provides.add(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))

    return app
Ejemplo n.º 2
0
def create_app(config_obj: str) -> Flask:
    app = Flask(__name__)
    app.config.from_object(config_obj)
    app.register_blueprint(main_blueprint)
    app.register_blueprint(blog_blueprint)

    db.init_app(app)
    return app
Ejemplo n.º 3
0
def create_app(config_object):
    app = Flask(__name__)
    app.config.from_object(config_object)

    db.init_app(app)
    login_manager.init_app(app)
    principal.init_app(app)
    admin.init_app(app)

    rest_api.add_resource(
        MovieAPI,
        '/api/movie',
        '/api/movie/<int:movie_id>',
    )
    rest_api.add_resource(
        ActorAPI,
        '/api/actor',
        '/api/actor/<int:actor_id>',
    )
    rest_api.add_resource(
        AuthAPI,
        '/api/auth',
    )

    rest_api.init_app(app)

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

    admin.add_view(CustomView())
    admin.add_view(UserView(User, db.session))
    admin.add_view(CustomModelView(Role, db.session))
    admin.add_view(ActorView(Actor, db.session))
    admin.add_view(CustomModelView(Movie, db.session))
    admin.add_view(CustomModelView(MovieRole, db.session))
    admin.add_view(CustomModelView(Post, db.session))
    admin.add_view(CustomModelView(Comment, db.session))

    static_dir = os.path.join(os.path.dirname(__file__), 'static')
    admin.add_view(CustomFileView(static_dir, '/static/', name="Static Files"))

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        # Set the identity user object
        identity.user = current_user

        # Add the UserNeed to the identity
        if hasattr(current_user, 'id'):
            identity.provides.add(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))

    return app
Ejemplo n.º 4
0
def create_app(config_object):
    app = Flask(__name__)
    app.config.from_object(config_object)

    db.init_app(app)

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

    return app
Ejemplo n.º 5
0
def create_app(object_name):
    app = Flask(__name__)
    app.config.from_object(object_name)

    db.init_app(app)

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

    return app
Ejemplo n.º 6
0
def create_app(config_object):
    app = Flask(__name__)
    app.config.from_object(config_object)

    db.init_app(app)
    login_manager.init_app(app)
    bcrypt.init_app(app)
    app.register_blueprint(main_blueprint)
    app.register_blueprint(blog_blueprint)

    return app
Ejemplo n.º 7
0
def create_app(config_object):
    app = Flask(__name__)
    app.config.from_object(config_object)

    db.init_app(app)
    login_manager.init_app(app)
    principal.init_app(app)

    rest_api.add_resource(
        MovieAPI,
        '/api/movie',
        '/api/movie/<int:movie_id>',
    )
    rest_api.add_resource(
        ActorAPI,
        '/api/actor',
        '/api/actor/<int:actor_id>',
    )
    rest_api.add_resource(
        AuthAPI,
        '/api/auth',
    )

    rest_api.init_app(app)

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

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        # Set the identity user object
        identity.user = current_user

        # Add the UserNeed to the identity
        if hasattr(current_user, 'id'):
            identity.provides.add(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))

    return app
Ejemplo n.º 8
0
def create_app(config_object):
    app = Flask(__name__)
    app.config.from_object(config_object)
    init_heroku(app)
    
    db.init_app(app)
    login_manager.init_app(app)
    principal.init_app(app)
    admin.init_app(app)
    toolbar.init_app(app)
    cache.init_app(app)
    assets_env.init_app(app)
    celery.init_app(app)

    assets_env.register('main_js', main_js)
    assets_env.register('main_css', main_css)

    rest_api.add_resource(
        MovieAPI,
        '/api/movie',
        '/api/movie/<int:movie_id>',
    )
    rest_api.add_resource(
        ActorAPI,
        '/api/actor',
        '/api/actor/<int:actor_id>',
    )
    rest_api.add_resource(
        AuthAPI,
        '/api/auth',
    )

    rest_api.init_app(app)

    app.register_blueprint(main_blueprint)
    app.register_blueprint(blog_blueprint)
    
    admin.add_view(
        CustomView()
    )
    admin.add_view(
        UserView(
            User, db.session
        )
    )
    admin.add_view(
        CustomModelView(
            Role, db.session
        )
    )
    admin.add_view(
        ActorView(
            Actor, db.session
        )
    )
    admin.add_view(
        CustomModelView(
            Movie, db.session
        )
    )
    admin.add_view(
        CustomModelView(
            MovieRole, db.session
        )
    )
    admin.add_view(
        CustomModelView(
            Post, db.session
        )
    )
    admin.add_view(
        CustomModelView(
            Comment, db.session
        )
    )

    static_dir = os.path.join(os.path.dirname(__file__), 'static')
    admin.add_view(
        CustomFileView(
            static_dir,
            '/static/',
            name="Static Files"
        )
    )

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        # Set the identity user object
        identity.user = current_user

        # Add the UserNeed to the identity
        if hasattr(current_user, 'id'):
            identity.provides.add(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))

    return app