コード例 #1
0
ファイル: __init__.py プロジェクト: KaySchus/Flask-Blog
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. appname.settings.ProdConfig
	"""
    app = Flask(__name__, static_url_path='/static')
    app.config.from_object(object_name)

    db.init_app(app)

    login_manager.init_app(app)

    mail.init_app(app)

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

    # Loading the Blueprint in controllers defined by main.py - Handles routing
    app.register_blueprint(main_blueprint)
    app.register_blueprint(user_blueprint)

    return app
コード例 #2
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. resrv.settings.ProdConfig
    """

    app = Flask(__name__)

    app.config.from_object(object_name)

    # initialize SQLAlchemy
    db.init_app(app)
    login_manager.init_app(app)
    humanize.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
コード例 #3
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. appname.settings.ProdConfig
    """

    app = Flask(__name__)

    app.config.from_object(object_name)

    # initialize the cache
    cache.init_app(app)

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

    # FIXME: init arango
#    db.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)
    app.register_blueprint(authors)

    return app
コード例 #4
0
def register_extensions(app):
    # initialize SQLAlchemy
    db.init_app(app)    
    # initialize the cache
    cache.init_app(app)

    # initialize security
    ds = SQLAlchemyUserDatastore(db, User, Role)
    security.init_app(app, datastore=ds,
                      register_form=forms.ExtendedRegisterForm)   
    # initialize bootstrap resource
    bootstrap.init_app(app)
    # initialize the debug tool bar
    #debug_toolbar.init_app(app)

    # Initialize social
    social_ds = SQLAlchemyConnectionDatastore(db, Connection)
    social.init_app(app, social_ds)

    #Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)
    return None
コード例 #5
0
def create_app(object_name, env="dev"):
    """
    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. mobsec.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)

    # 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
コード例 #6
0
ファイル: __init__.py プロジェクト: aybuketurker/NEXT-psych
def create_app(object_name, env="prod"):
    """
    A flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Inputs:  ::\n
        object_name: the python path of the config object,
                     e.g. appname.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

    # Init the cache
    cache.init_app(app)

    # Init debug toolbar
    debug_toolbar.init_app(app)

    # Init Mongo engine
    # mongoengine.connect(config.MONGODB_FRONTEND_DB_NAME, host=config.MONGODB_HOST, port=config.MONGODB_PORT)
    app.config['MONGODB_DB'] = config.MONGODB_FRONTEND_DB_NAME
    app.config['MONGODB_HOST'] = config.MONGODB_HOST
    app.config['MONGODB_PORT'] = config.MONGODB_PORT
    db.init_app(app)

    # Init login_manager
    login_manager.init_app(app)
    login_manager.login_view = "main.login"
    login_manager.refresh_view = "main.login"
    # Init current to track current project/experiment
    current.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().iteritems():
        assets_env.register(name, bundle)

    # register all the  blueprints
    from controllers import (main, error, dashboard, new_experiment,
                             new_project, account_settings, project,
                             experiment, targets, setup)

    app.register_blueprint(main)
    app.register_blueprint(error, url_prefix="/error")
    app.register_blueprint(dashboard, url_prefix="/dashboard")
    app.register_blueprint(new_experiment, url_prefix="/new_experiment")
    app.register_blueprint(new_project, url_prefix="/new_project")
    app.register_blueprint(account_settings, url_prefix="/account_settings")
    app.register_blueprint(project, url_prefix="/project")
    app.register_blueprint(experiment, url_prefix="/experiment")
    app.register_blueprint(targets, url_prefix="/targets")
    app.register_blueprint(setup, url_prefix="/setup")

    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. mothership.settings.ProdConfig

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

    app = Flask(__name__)

    @app.before_first_request
    def _run_on_start():
        init_db()

    csrf = CsrfProtect(app)

    @app.template_filter('datetime')
    def datetimeformat(value, format='%d/%m/%y %H:%M %p'):
        return datetime.datetime.utcfromtimestamp(value).strftime(format)

    app.config.from_object(object_name)

    # 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)
    app.register_blueprint(campaigns)
    app.register_blueprint(graphs)
    app.register_blueprint(fuzzers)
    csrf.exempt(fuzzers)

    try:
        os.mkdir(app.config['DATA_DIRECTORY'])
    except FileExistsError:
        pass

    return app
コード例 #8
0
ファイル: __init__.py プロジェクト: sleekslush/flocka
def create_app(config='', **config_kwargs):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        config: the path of config file
        config_kwargs: overrides

    Default config read from flocka/config_default.py
    See FiftyFlask docs
    """

    app = Flask(__name__)
    config = config if os.path.isfile(config) else None
    app.configure(config, **config_kwargs)

    # Cache
    cache.init_app(app)

    # Logging
    app.logger.addHandler(logging.StreamHandler(sys.stderr))

    # Debug toolbar
    debug_toolbar.init_app(app)

    # SQLAlchemy
    db.init_app(app)

    # Flask Login
    login_manager.init_app(app)

    # FiftyTables
    FiftyTables(app)

    # Alembic
    migrate.init_app(app, db)

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

    # Register our blueprints
    from controllers import main, branches
    app.register_blueprint(main.main_bp)
    app.register_blueprint(branches.branched_bp)

    # Jinja extensions
    app.jinja_env.add_extension('jinja2.ext.do')
    app.jinja_env.add_extension('jinja2.ext.loopcontrols')

    return app
コード例 #9
0
ファイル: __init__.py プロジェクト: hysds/pele
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. pele.settings.ProductionConfig
    """

    app = Flask(__name__)
    app.config.from_object(object_name)
    app.config.from_pyfile('../settings.cfg')  # override

    # register converters
    app.url_map.converters['list'] = ListConverter

    # set debug logging level
    if app.config.get('DEBUG', False):
        app.logger.setLevel(logging.DEBUG)

    cors.init_app(app)
    app.wsgi_app = ReverseProxied(app.wsgi_app, app.config)

    app.es_client = get_es_client(app.config)
    app.es_util = QueryES(app.es_client, logger=app.logger)

    # init extensions
    cache.init_app(app)
    debug_toolbar.init_app(app)
    bcrypt.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    limiter.init_app(app)
    mail.init_app(app)

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

    # register our blueprints
    from .controllers.main import main
    app.register_blueprint(main)

    from .controllers.api_v01 import services as api_v01
    app.register_blueprint(api_v01)
    app.register_blueprint(apidoc.apidoc)

    return app
コード例 #10
0
def create_app(environment_name='dev'):
    app = Flask(__name__)
    config = configurations[environment_name]
    app.config.from_object(config)
    db.init_app(app)
    csrf.init_app(app)
    # need render_as_batch to correctly generate migrations for sqlite
    migrate.init_app(app, db, render_as_batch=True)
    login_manager.init_app(app)
    mail.init_app(app)
    checkout.init_app(app)
    assets_env.init_app(app)
    rq2.init_app(app)
    debug_toolbar.init_app(app)
    cache.init_app(app)

    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    if app.config["SENTRY_DSN"]:  # pragma: no cover
        sentry_sdk.init(dsn=app.config["SENTRY_DSN"],
                        integrations=[
                            FlaskIntegration(),
                            SqlalchemyIntegration(),
                            RqIntegration()
                        ])

    @app.errorhandler(401)
    def unauthorized_error(error):
        return render_template('errors/401.html'), 401  # pragma: no cover

    @app.errorhandler(404)
    def not_found_error(error):
        return render_template('errors/404.html'), 404

    @app.errorhandler(500)
    def internal_error(error):
        return render_template('errors/500.html'), 500  # pragma: no cover

    app.register_blueprint(product_bp, url_prefix='/product')
    app.register_blueprint(store_bp)
    app.register_blueprint(user_bp)
    app.register_blueprint(checkout_bp)
    app.register_blueprint(landing_bp)

    # Admin tools
    app.register_blueprint(rq_blueprint, url_prefix="/rq")
    csrf.exempt(rq_blueprint)

    return app
コード例 #11
0
def create_app(environment_name='dev'):
    app = Flask(__name__)
    app.config.from_object(configurations[environment_name])

    # init extensions
    db.init_app(app)
    csrf.init_app(app)
    login_manager.init_app(app)
    migrate.init_app(app, db, render_as_batch=True)
    mail.init_app(app)
    checkout.init_app(app)
    rq2.init_app(app)
    debug_toolbar.init_app(app)
    cache.init_app(app)

    # assets bundling
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    # register blueprints
    app.register_blueprint(products, url_prefix="/product")
    app.register_blueprint(user_bp)
    app.register_blueprint(store_bp)
    app.register_blueprint(checkout_bp)
    app.register_blueprint(landing_bp)
    app.register_blueprint(rq_blueprint, url_prefix="/rq")

    # errors monitoring
    if app.config.get("SENTRY_DSN"):
        sentry_sdk.init(
            dsn=app.config["SENTRY_DSN"],
            integrations=[FlaskIntegration(), SqlalchemyIntegration()]
        )

    # errors handling
    @app.errorhandler(401)
    def unauthorized_error(error):
        return render_template('errors/401.html'), 401

    @app.errorhandler(404)
    def not_found_error(error):
        return render_template('errors/404.html'), 404

    @app.errorhandler(500)
    def internal_error(error):
        return render_template('errors/500.html'), 500

    return app
コード例 #12
0
ファイル: __init__.py プロジェクト: hellwen/ivy_3dprint_site
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. ivy_3dprint_site.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

    #init the cache
    cache.init_app(app)

    #init SQLAlchemy
    db.init_app(app)

    #int Flask-admin
    admin = Admin(app)
    from controllers.admin import UserView, ProductView
    from models import User, Tag, Lang, Photo, Product, \
        File, Sample, Contact, About
    from forms import CKTextAdmin
    admin.add_view(UserView(User))
    admin.add_view(ModelView(Tag))
    admin.add_view(ModelView(Lang))
    admin.add_view(ModelView(Photo))
    admin.add_view(ModelView(File))
    admin.add_view(ProductView(Product))
    admin.add_view(CKTextAdmin(Sample))
    admin.add_view(CKTextAdmin(Contact))
    admin.add_view(CKTextAdmin(About))

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

    # register our blueprints
    from controllers.main import main
    app.register_blueprint(main)

    return app
コード例 #13
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. appname.settings.ProdConfig
    """

    app = Flask(__name__)

    @app.route('/uploads/<filename>')
    def uploaded_file(filename):
        return send_from_directory('/home/ahmad/workspace/python/Flask-CRUD/uploads/', filename)

    Bootstrap(app)

    app.config.from_object(object_name)

    # initialize the cache
    cache.init_app(app)

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

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

    login_manager.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    with app.app_context():
        assets_env.load_path = [
            os.path.join(os.path.join(os.path.dirname(__file__), os.pardir), 'node_modules'),
            os.path.join(os.path.dirname(__file__), 'static'),
        ]
    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)
    app.register_blueprint(categories)
    app.register_blueprint(products)
    app.register_blueprint(catalogs)

    return app
コード例 #14
0
ファイル: __init__.py プロジェクト: TNguyen137/CS4400-DB
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config_name)

    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    login_manager.init_app(app)

    app.register_blueprint(main)
    app.register_blueprint(admin, url_prefix='/admin')

    return app
コード例 #15
0
def create_app(environment_name='dev'):
    app = Flask(__name__)
    app.config.from_object(configurations[environment_name])

    db.init_app(app)
    csrf.init_app(app)
    login_manager.init_app(app)
    migrate.init_app(app, db, render_as_batch=True)
    # mail.init_app(app)
    checkout.init_app(app)
    assets_env.init_app(app)
    rq2.init_app(app)
    debug_toolbar.init_app(app)
    cache.init_app(app)

    if app.config.get('SENTRY_DSN'):
        sentry_sdk.init(
            dsn=app.config['SENTRY_DSN'],
            integrations=[FlaskIntegration(),
                          SqlalchemyIntegration()],
            send_default_pii=True,
            traces_sample_rate=1.0)  # pragma: no cover

    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    app.register_blueprint(products, url_prefix='/product')
    app.register_blueprint(user_bp)
    app.register_blueprint(store_bp, url_prefix='/store')
    app.register_blueprint(checkout_bp)
    app.register_blueprint(landing_bp)
    app.register_blueprint(rq_blueprint, url_prefix='/rq')
    csrf.exempt(rq_blueprint)

    @app.errorhandler(401)
    def unauthorized_error(error):
        return render_template('errors/401.html'), 401  # pragma: no cover

    @app.errorhandler(404)
    def not_found_error(error):
        return render_template('errors/404.html'), 404

    @app.errorhandler(500)
    def internal_error(error):
        return render_template('errors/500.html'), 500  # pragma: no cover

    return app
コード例 #16
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. {{cookiecutter.app_name}}.settings.ProdConfig

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

    app = Flask(__name__)

    app.config.from_object(object_name)

    if cache:
        # initialize the cache
        cache.init_app(app)

    if debug_toolbar:
        # 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
    if assets_env:
        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
    main_controller.before_request(before_app_request)
    app.register_blueprint(main_controller)

    admin_controller.before_request(before_app_request)
    app.register_blueprint(admin_controller)

    file_controller.before_request(before_app_request)
    app.register_blueprint(file_controller)

    return app
コード例 #17
0
ファイル: __init__.py プロジェクト: mthakka2/note-platform
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. {{cookiecutter.repo_name}}.settings.ProdConfig

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

    app = Flask(__name__)

    app.config.from_object(object_name)

    #initialize CORS
    CORS(app, resources={r"/*":{"origins":"*"}})

    # initialize the cache
    cache.init_app(app)

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

    # initialize SQLAlchemy
    db.init_app(app)

    #initialize migration
    migrate.init_app(app, db)

    #initialize socket
    # socketio.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(api)

    return app
コード例 #18
0
def create_app(object_name, env="development"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    :argument string object_name: Object name
    :argument string env: Environment
    """
    app = Flask(__name__)
    app.config.from_object(object_name)
    app.config['ENV'] = env

    configure_logging(app)

    # init the cache
    cache.init_app(app)

    # init debug toolbar
    debug_toolbar.init_app(app)

    # init notifications object
    notifications = Notifications()
    notifications.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 index blueprint
    from app.controllers.index import index
    app.register_blueprint(index)

    # register api blueprints
    api_prefix = "/{0}".format(app.config['API_VERSION'])

    from app.controllers.errors import errors
    app.register_blueprint(errors, url_prefix=api_prefix)

    from app.controllers.status import status
    app.register_blueprint(status, url_prefix=api_prefix)

    return app
コード例 #19
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. fv_prov_es.settings.ProdConfig

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

    app = Flask(__name__)

    app.wsgi_app = ReverseProxied(app.wsgi_app)

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

    #init extensions
    cache.init_app(app)
    debug_toolbar.init_app(app)
    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().iteritems():
        assets_env.register(name, bundle)

    # register our blueprints
    from controllers.main import main
    app.register_blueprint(main)

    from controllers.services_v01 import services as services_v01
    app.register_blueprint(services_v01)

    from controllers.services_v02 import services as services_v02
    app.register_blueprint(services_v02)

    app.register_blueprint(apidoc.apidoc)

    return app
コード例 #20
0
ファイル: __init__.py プロジェクト: eruixma/trading-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. trading.settings.ProdConfig
    """

    app = Flask(__name__)

    app.config.from_object(object_name)

    # 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)
    app.register_blueprint(portfolio, url_prefix="/api/v1")
    app.register_blueprint(search, url_prefix="/api/v1")
    app.register_blueprint(quotes, url_prefix="/api/v1")

    api.init_app(app)

    @app.errorhandler(404)
    def page_not_found(e):
        return app.send_static_file('index.html')

    return app
コード例 #21
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. flaskheartbeat.settings.ProdConfig

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

    app = Flask(__name__)

    app.config.from_object(object_name)

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

    #API resources
    api = Api(app)

    api.add_resource(HeartbeatReceiver,
                     "/api/heartbeat/<string:deviceID>/<int:statuscode>")

    return app
コード例 #22
0
ファイル: __init__.py プロジェクト: gtyagi777/temp_test
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. cron_ui.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """
    UPLOAD_FOLDER = os.path.dirname(os.path.abspath(__file__)) + '/uploads'
    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

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

    # Impor t 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
コード例 #23
0
def create_app():
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/
    """

    app = Flask(__name__)

    #app.config.from_object(object_name)
    env = DotEnv()
    env.init_app(app=app,
                 env_file=fs.getApplicationDirectory() + os.path.sep + '.env')

    for k, v in app.config.items():
        if isinstance(v, str):
            v = v.lower().strip()
            if v == 'true':
                app.config[k] = True
            elif v == 'false':
                app.config[k] = False

    # initialize the cache
    cache.init_app(app)

    # initialize the debug tool bar
    debug_toolbar.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)

    modules.init_app(app)

    return app
コード例 #24
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. appname.settings.ProdConfig
    """

    app = Flask(__name__)
    app.config.from_object(object_name)

    # initialize the cache
    cache.init_app(app)

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

    # initialize SQLAlchemy
    db.init_app(app)

    # initalize Flask Login
    login_manager.init_app(app)

    # initialize Flask-RQ2 (job queue)
    rq2.init_app(app)

    token.init_app(app)
    mail.init_app(app)
    limiter.init_app(app)
    stripe.init_app(app)

    if app.config.get('SENTRY_DSN') and not app.debug:
        sentry.init_app(app, dsn=app.config.get('SENTRY_DSN'))

        @app.errorhandler(500)
        def internal_server_error(error):
            return render_template(
                'errors/500.html',
                event_id=g.sentry_event_id,
                public_dsn=sentry.client.get_public_dsn('https')), 500

    @app.errorhandler(404)
    def not_found_error(error):
        if request.path.startswith("/api"):
            return api_blueprint.handle_error(error)
        return render_template('errors/404.html'), 404

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

    # Set some globals for Jinja templating
    app.jinja_env.globals.update({'utils': utils, 'debug': app.debug})

    # register our blueprints
    app.register_blueprint(main)
    app.register_blueprint(auth)
    app.register_blueprint(dashboard)
    app.register_blueprint(store)
    app.register_blueprint(api_blueprint, url_prefix='/api')
    app.register_blueprint(oauth_client, url_prefix='/oauth')

    # Admin Tools
    app.register_blueprint(jobs, url_prefix='/admin/rq')
    admin.init_app(app)

    # If you use websockets/realtime features
    # socketio.init_app(app)

    return app
コード例 #25
0
from app import assets
from app.utils.auth import Auth

# Config
app = Flask(__name__)
env = os.environ.get('FACTURE_ENV', 'dev')
app.config.from_object('config.%sConfig' % env.capitalize())
auth = Auth()

# Models
db = SQLAlchemy(app)
from app.models import User

# Assets
assets_env = Environment(app)
assets_loader = PythonAssetsLoader(assets)
for name, bundle in assets_loader.load_bundles().items():
    assets_env.register(name, bundle)

# Import & Register Blueprints
from app.users.views import users
from app.home.views import home
from app.organisations.views import orgs
from app.invoices.views import invoices

app.register_blueprint(home)
app.register_blueprint(users)
app.register_blueprint(orgs)
app.register_blueprint(invoices)

コード例 #26
0
def create_app(default_config_path=None):
    """Create and return a Flask application. Reads a config file path from the
    OK_SERVER_CONFIG environment variable. If it is not set, reads from
    default_config_path instead. This is so we can default to a development
    environment locally, but the app will fail in production if there is no
    config file rather than dangerously defaulting to a development environment.
    """

    app = Flask(__name__)

    config_path = os.getenv('OK_SERVER_CONFIG', default_config_path)
    if config_path is None:
        raise ValueError(
            'No configuration file found'
            'Check that the OK_SERVER_CONFIG environment variable is set.')
    app.config.from_pyfile(config_path)

    # Senty Error Reporting & Other Prod Changes
    sentry_dsn = os.getenv('SENTRY_DSN')
    if not app.debug:
        app.wsgi_app = ProxyFix(app.wsgi_app)
        if sentry_dsn:
            sentry.init_app(app, dsn=sentry_dsn)

            @app.errorhandler(500)
            def internal_server_error(error):
                return render_template(
                    'errors/500.html',
                    event_id=g.sentry_event_id,
                    public_dsn=sentry.client.get_public_dsn('https')), 500

        # In production mode, add log handler to sys.stderr.
        app.logger.addHandler(logging.StreamHandler())
        app.logger.setLevel(logging.INFO)

    @app.errorhandler(404)
    def not_found_error(error):
        if request.path.startswith("/api"):
            return api.handle_error(error)
        return render_template('errors/404.html'), 404

    # initialize the cache
    cache.init_app(app)

    # initialize redis task queues
    RQ(app)

    # Protect All Routes from csrf
    csrf.init_app(app)

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

    # initialize SQLAlchemy
    db.init_app(app)

    # Flask-Login manager
    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)

    # custom URL handling
    converters.init_app(app)

    # custom Jinja rendering
    app.jinja_env.globals.update({
        'utils':
        utils,
        'debug':
        app.debug,
        'instantclick':
        app.config.get('INSTANTCLICK', True),
        'CSRFForm':
        CSRFForm
    })

    app.jinja_env.filters.update({
        'markdown': utils.convert_markdown,
        'pluralize': utils.pluralize,
    })

    # register our blueprints
    # OAuth should not need CSRF protection
    csrf.exempt(auth)
    app.register_blueprint(auth)

    csrf.exempt(oauth)
    app.register_blueprint(oauth)

    app.register_blueprint(student)

    app.register_blueprint(admin, url_prefix='/admin')
    app.register_blueprint(about, url_prefix='/about')

    # Redis Queue dashboard
    csrf.exempt(queue)
    app.register_blueprint(queue, url_prefix='/rq')

    # API does not need CSRF protection
    csrf.exempt(api_endpoints)
    app.register_blueprint(api_endpoints, url_prefix=API_PREFIX)

    return app
コード例 #27
0
ファイル: assets.py プロジェクト: by46/coffee
def register_bundle(assets_env):
    loader = PythonAssetsLoader(__name__)
    for name, bundle in iteritems(loader.load_bundles()):
        assets_env.register(name, bundle)
コード例 #28
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. appname.settings.ProdConfig
    """

    app = Flask(__name__)
    app.config.from_object(object_name)

    # initialize the cache
    cache.init_app(app)

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

    # initialize SQLAlchemy
    db.init_app(app)

    # initalize Flask Login
    login_manager.init_app(app)

    # initialize Flask-RQ2 (job queue)
    rq2.init_app(app)

    # CSRF Protection
    csrf.init_app(app)

    # File Storage
    storage.init_app(app)

    # Special URL converters
    custom_converters.init_app(app)

    token.init_app(app)
    mail.init_app(app)
    limiter.init_app(app)
    stripe.init_app(app)
    hashids.init_app(app)

    if app.config.get('SENTRY_DSN') and not app.debug:
        sentry.init_app(app, dsn=app.config.get('SENTRY_DSN'))

        @app.errorhandler(500)
        def internal_server_error(error):
            return render_template(
                'errors/500.html',
                event_id=g.sentry_event_id,
                public_dsn=sentry.client.get_public_dsn('https')), 500

    @app.errorhandler(404)
    def not_found_error(error):
        if request.path.startswith("/api"):
            return handle_api_error(error)
        return render_template('errors/404.html'), 404

    @app.errorhandler(401)
    def permission_denied_error(error):
        if request.path.startswith("/api"):
            return handle_api_error(error)
        return render_template('tabler/401.html'), 401

    @app.before_request
    def check_for_confirmation(*args, **kwargs):
        pass
        # TODO: Check later.
        # if REQUIRE_EMAIL_CONFIRMATION:
        #     # If we have a logged in user, we can check if they have confirmed their email or not.
        #     if not current_user.is_authenticated or current_user.email_confirmed:
        #         return
        #     resend_confirm_link = url_for('auth.resend_confirmation')
        #     text = Markup(
        #         'Please confirm your email. '
        #         '<a href="{}" class="alert-link">Click here to resend</a>'.format(resend_confirm_link))
        #     flash(text, 'warning')

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

    # Set some globals for Jinja templating
    app.jinja_env.globals.update({
        'utils': utils,
        'view_helpers': view_helpers,
        'debug': app.debug,
        'constants': constants,
        'simple_form': SimpleForm,
        'features': {
            'oauth': app.config["GOOGLE_OAUTH_CLIENT_ID"] != 'bad_key',
            'segment': app.config["SEGMENT_ANALYTICS_KEY"],
        },
    })

    # register our blueprints
    app.register_blueprint(main)
    app.register_blueprint(auth)
    app.register_blueprint(google_blueprint, url_prefix='/oauth')
    app.register_blueprint(store)
    app.register_blueprint(settings_blueprint)

    # Register user dashboard blueprints
    for blueprint in dashboard_blueprints:
        app.register_blueprint(blueprint, url_prefix='/dashboard')

    # API
    app.register_blueprint(api_blueprint, url_prefix='/api')
    csrf.exempt(api_blueprint)

    app.register_blueprint(stripe_blueprint, url_prefix='/webhooks')
    csrf.exempt(stripe_blueprint)

    # Admin Tools
    app.register_blueprint(jobs, url_prefix='/admin/rq')
    admin.init_app(app)

    # If you use websockets/realtime features
    # socketio.init_app(app)

    return app
コード例 #29
0
from flask import Flask
from flask_assets import Environment
from flask_sqlalchemy import SQLAlchemy
from webassets.loaders import PythonLoader as PythonAssetsLoader
import webapp.assets


app = Flask(__name__)
app.config.from_pyfile('../config.py')
db = SQLAlchemy(app)

assets_env = Environment(app)
assets_loader = PythonAssetsLoader(webapp.assets)
for name, bundle in assets_loader.load_bundles().items():
    assets_env.register(name, bundle)


#import app.forms
import webapp.views


if __name__ == "__main__":
    app.debug = True
    app.run(host='0.0.0.0')
コード例 #30
0
ファイル: __init__.py プロジェクト: rmoorman/SilverFlask
def init_app(app):
    db.init_app(app)
    cache.init_app(app)
    debug_toolbar.init_app(app)
    app.template_folder = os.path.join(os.path.dirname(__file__), 'templates/')

    migrate = Migrate(app, db)

    # Import and register the different asset bundles
    assets_env = Environment(app)
    assets_env.load_path = [os.path.join(os.path.dirname(__file__), 'static')]
    assets_env.directory = os.path.join(os.path.dirname(__file__), 'static')
    assets_env.url = '/admin/static/'
    # assets_env.register('js_all', js)
    print("directory ", assets_env.directory,
          os.path.join(os.path.dirname(__file__), 'static/'))
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in list(assets_loader.load_bundles().items()):
        assets_env.register(name, bundle)

    # Setup user handling
    from silverflask.models import User

    user_adapter = SQLAlchemyAdapter(db, User)
    user_manager = UserManager(user_adapter)
    user_manager.init_app(app)

    ###
    #  SILVERFLASK
    ###

    upload_path = os.path.join(app.instance_path,
                               app.config["SILVERFLASK_UPLOAD_PATH"])
    app.config["SILVERFLASK_ABSOLUTE_UPLOAD_PATH"] = upload_path
    app.storage_backend = LocalFileStorageBackend(upload_path)

    from silverflask.controllers.page_controller import SiteTreeController
    app.register_blueprint(SiteTreeController.create_blueprint(app))

    from silverflask.core.dev_controller import DevController
    app.register_blueprint(DevController.create_blueprint(app))

    from silverflask.controllers.cms_controller import CMSController, PagesCMSController, FilesCMSController, \
        DataObjectCMSController

    app.register_blueprint(CMSController.create_blueprint(app))
    app.register_blueprint(DataObjectCMSController.create_blueprint(app))
    app.register_blueprint(PagesCMSController.create_blueprint(app))
    app.register_blueprint(FilesCMSController.create_blueprint(app))
    from silverflask.controllers.security_controller import SecurityController
    app.register_blueprint(SecurityController.create_blueprint(app))

    from silverflask.core.theme import init_themes
    init_themes(app)

    from silverflask.controllers.main import setup_processors, init_blueprint
    from silverflask.controllers.cms import bp as cms_bp

    setup_processors(app)
    main = init_blueprint(app)
    app.register_blueprint(main)
    app.register_blueprint(cms_bp, url_prefix='/admin')

    # for rule in app.url_map.iter_rules():
    #     print(rule)

    return app