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
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
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
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
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
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