Exemplo n.º 1
0
def create_app(config_object, env):
    '''An application factory, as explained here:
        http://flask.pocoo.org/docs/patterns/appfactories/

    :param config_object: The configuration object to use.
    :param env: A string, the current environment. Either "dev" or "prod"
    '''
    app = Flask(__name__)
    app.config.from_object(config_object)
    app.config['ENV'] = env
    # Initialize SQLAlchemy
    db.init_app(app)
    # Register bcrypt
    bcrypt.init_app(app)
    # Register asset bundles
    assets_env.init_app(app)
    assets_loader = PythonLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)
    # Register blueprints
    from flask_boilerplate.modules import public, member
    app.register_blueprint(public.blueprint)
    app.register_blueprint(member.blueprint)

    return app
Exemplo n.º 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. zeus.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)

    return app
Exemplo n.º 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__, 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
Exemplo n.º 4
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
Exemplo n.º 5
0
Arquivo: assets.py Projeto: shepazu/h
def includeme(config):
    config.include('pyramid_webassets')

    env = config.get_webassets_env()

    # Configure the static views
    if env.url_expire is not False:
        # Cache for one year (so-called "far future" Expires)
        config.add_static_view(env.url, env.directory, cache_max_age=31536000)
    else:
        config.add_static_view(env.url, env.directory)

    # Set up a predicate and subscriber to set CORS headers on asset responses
    config.add_subscriber_predicate('asset_request', AssetRequest)
    config.add_subscriber(asset_response_subscriber,
                          pyramid.events.NewResponse,
                          asset_request=True)

    loader = PythonLoader(config.registry.settings.get('h.assets', __name__))
    bundles = loader.load_bundles()
    for bundle_name in bundles:
        log.info('name: ' + str(bundle_name))
        config.add_webasset(bundle_name, bundles[bundle_name])

    from deform.field import Field
    resource_registry = WebassetsResourceRegistry(config.get_webassets_env())
    Field.set_default_resource_registry(resource_registry)
    config.registry.resources = resource_registry
Exemplo n.º 6
0
def create_app(config_object, env):
    '''An application factory, as explained here:
        http://flask.pocoo.org/docs/patterns/appfactories/

    :param config_object: The configuration object to use.
    :param env: A string, the current environment. Either "dev" or "prod"
    '''
    app = Flask(__name__)
    app.config.from_object(config_object)
    app.config['ENV'] = env
    # Initialize SQLAlchemy
    db.init_app(app)
    # Register bcrypt
    bcrypt.init_app(app)
    # Register asset bundles
    assets_env.init_app(app)
    assets_loader = PythonLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)
    # Register blueprints
    from flask_boilerplate.modules import public, member
    app.register_blueprint(public.blueprint)
    app.register_blueprint(member.blueprint)

    return app
Exemplo n.º 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. 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
Exemplo n.º 8
0
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
Exemplo n.º 9
0
def _setup_assets_bundler(app):
    assets.init_app(app)

    # Loads and registers assets bundles
    bundles = PythonLoader("assets_bundles").load_bundles()
    for name, bundle in bundles.iteritems():
        assets.register(name, bundle)
Exemplo n.º 10
0
def create_app(object_name='bosphorus.settings', env='dev'):
    
    app = create_barebones_app(object_name, env)

    # Import and register the different asset bundles
    assets_env = Environment()
    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
    from controllers.user import user
    from controllers.studies import studies
    from controllers.person import person
    from controllers.protocol import protocol
    from utils import proxy
    app.register_blueprint(main)
    app.register_blueprint(user)
    app.register_blueprint(person)
    app.register_blueprint(studies)
    app.register_blueprint(protocol)
    app.register_blueprint(proxy)

    return app
Exemplo n.º 11
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
Exemplo n.º 12
0
def create_app(object_name, env="prod"):
    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config['ENV'] = env
    db.init_app(app)
    mail.init_app(app)
    security = Security(app, user_datastore)

    @security.context_processor
    def security_context_processor():
        return dict(admin_base_template=admin.base_template,
                    admin_view=admin.index_view,
                    h=admin_helpers)

    admin.init_app(app)

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

    with app.app_context():
        register_models()

    import pacioli.views.admin_views
    import pacioli.views.bookkeeping_views
    import pacioli.views.accounting_views
    import pacioli.views.ofx_views
    import pacioli.views.amazon_views
    import pacioli.views.payroll_views

    return app
Exemplo n.º 13
0
def create_app():
    app = Flask(__name__)
    prod = True

    if prod:
        app.config.from_object('settings.ProdConfig')
        app.config['ENV'] = 'prod'
        app.config['DEBUG'] = False
        # initialize the cache
#   cache.init_app(app)
    else:
        app.config.from_object('settings.DevConfig')
        app.config['ENV'] = 'dev'
        app.config['DEBUG'] = True
        # 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 (see templates)
    assets_env.init_app(app)
    assets_loader = AssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)
#    if not prod:
#      print 'bundle=%s' % name
    return app
Exemplo n.º 14
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
Exemplo n.º 15
0
def includeme(config):
    config.include('pyramid_webassets')

    env = config.get_webassets_env()

    # Configure the static views
    if env.url_expire is not False:
        # Cache for one year (so-called "far future" Expires)
        config.add_static_view(env.url, env.directory, cache_max_age=31536000)
    else:
        config.add_static_view(env.url, env.directory)

    # Set up a predicate and subscriber to set CORS headers on asset responses
    config.add_subscriber_predicate('asset_request', AssetRequest)
    config.add_subscriber(
        asset_response_subscriber,
        pyramid.events.NewResponse,
        asset_request=True
    )

    loader = PythonLoader(config.registry.settings.get('h.assets', __name__))
    bundles = loader.load_bundles()
    for bundle_name in bundles:
        log.info('name: ' + str(bundle_name))
        config.add_webasset(bundle_name, bundles[bundle_name])

    from deform.field import Field
    resource_registry = WebassetsResourceRegistry(config.get_webassets_env())
    Field.set_default_resource_registry(resource_registry)
    config.registry.resources = resource_registry
Exemplo n.º 16
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. 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 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().iteritems():
        assets_env.register(name, bundle)

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

    return app
Exemplo n.º 17
0
def create_app():
    """
    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. hummingbirdexport.settings.ProdConfig

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

    app = Flask(__name__)

    # initialize the debug tool bar
    debug_toolbar.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
Exemplo n.º 18
0
def get_bundles():
    """Returns all registered bundles.

       .. note:: Returns only bundles from the assets module, you shouldn't register them anywhere else
    """
    loader = PythonAssetsLoader(__name__)

    return loader.load_bundles()
Exemplo n.º 19
0
    def test_load_bundles(self):
        import types
        module = types.ModuleType('test')
        module.foo = Bundle('bar')

        loader = PythonLoader(module)
        bundles = loader.load_bundles()
        assert len(bundles) == 1
        assert list(bundles.values())[0].contents[0] == 'bar'
Exemplo n.º 20
0
    def test_load_bundles(self):
        import types
        module = types.ModuleType('test')
        module.foo = Bundle('bar')

        loader = PythonLoader(module)
        bundles = loader.load_bundles()
        assert len(bundles) == 1
        assert list(bundles.values())[0].contents[0] == 'bar'
Exemplo n.º 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. 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
Exemplo n.º 22
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
Exemplo n.º 23
0
def _configure_assets(app):
    
    from flask.ext.assets import Environment 

    assets = Environment(app)
    pyload = PythonLoader('config.assets')
    bundles = pyload.load_bundles()
 
    assets.register('main_js', bundles['main_js'])
    assets.register('main_css', bundles['main_css'])
Exemplo n.º 24
0
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
Exemplo n.º 25
0
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 appname/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, widgets
    app.register_blueprint(main.main_bp)
    app.register_blueprint(widgets.widgets_bp)

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

    return app
Exemplo n.º 26
0
    def load_bundles(self, module):
        """
        Load predefined bundles from a YAML file.

        See bundles.yaml for an example.
        """

        # Load bundles from YAML file
        loader = PythonLoader(module)
        bundles = loader.load_bundles()

        # Register the bundles with the environment
        self.register(bundles)
Exemplo n.º 27
0
    def load_bundles(self, module):
        """
        Load predefined bundles from a YAML file.

        See bundles.yaml for an example.
        """

        # Load bundles from YAML file
        loader = PythonLoader(module)
        bundles = loader.load_bundles()

        # Register the bundles with the environment
        self.register(bundles)
Exemplo n.º 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. impression.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)

    # Add theme support
    # themes2.init_themes(app, app_identifier="...")
    themes2.init_themes(app, app_identifier='impression')

    return app
Exemplo n.º 29
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. 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
Exemplo n.º 30
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
Exemplo n.º 31
0
def register_extensions(app):
    # init the cache
    cache.init_app(app)
    # init debug toolbar
    debug_toolbar.init_app(app)
    # init SQLAlchemy
    db.init_app(app)
    # init 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().iteritems():
        assets_env.register(name, bundle)
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
Exemplo n.º 33
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. 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
Exemplo n.º 34
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. 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

    # initialize the cache
    cache.init_app(app)

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

    # initialize SQLAlchemy
    db.init_app(app)

    mail = Mail(app)

    security = Security(app, user_datastore)

    @security.context_processor
    def security_context_processor():
        return dict(
            admin_base_template=admin.base_template,
            admin_view=admin.index_view,
            h=admin_helpers,
        )

    admin.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
Exemplo n.º 35
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. appname.settings.ProdConfig

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

    app.config.from_object(object_name)

    upload_path = os.path.join(app.instance_path, app.config["SILVERFLASK_UPLOAD_FOLDER"])
    app.config["SILVERFLASK_ABSOLUTE_UPLOAD_PATH"] = upload_path
    app.storage_backend = LocalFileStorageBackend(upload_path)
    app.config['ENV'] = env

    db.init_app(app)
    logger.debug("DB Initialized")

    # init the cache
    cache.init_app(app)

    debug_toolbar.init_app(app)

    from silverflask.models import User
    user_adapter = SQLAlchemyAdapter(db, User)
    user_manager = UserManager(user_adapter, app)
    user_manager.enable_login_without_confirm_email = True

    # 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 silverflask.controllers.main import main
    from silverflask.controllers.main import setup_processors
    setup_processors(app)
    from silverflask.controllers.cms import bp as cms_bp
    app.register_blueprint(main)
    app.register_blueprint(cms_bp, url_prefix='/admin')

    with app.app_context():
        db.create_all()
    return app
Exemplo n.º 36
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
Exemplo n.º 37
0
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
Exemplo n.º 38
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
Exemplo n.º 39
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. neogameserver.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

    admin = Admin(app, name="neogameserver", template_mode="bootstrap3")
    admin.add_view(NeoModelView(User, db.session))
    admin.add_view(NeoModelView(Subscription, db.session))
    admin.add_view(NeoModelView(MinecraftProduct, db.session))
    admin.add_view(NeoModelView(VentriloProduct, db.session))
    admin.add_view(NeoModelView(OrderProduct, db.session))
    admin.add_view(NeoModelView(HostServer, db.session))
    admin.add_view(NeoModelView(Port, db.session))

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

    return app
Exemplo n.º 40
0
def create_app(object_name):
    app = Flask(__name__)

    app.config.from_object(object_name)
    cache.init_app(app)
    debug_toolbar.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)

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

    app.register_blueprint(main)
    return app
Exemplo n.º 41
0
 def test_path(self):
     """[bug] Regression test: Python loader does not leave
     sys.path messed up.
     """
     old_path = sys.path[:]
     loader = PythonLoader('sys')
     assert sys.path == old_path
Exemplo n.º 42
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. 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 SQLAlchemy
    db.init_app(app)
    
    # connect to the database
    mongo.init_app(app)
    
    # init admin views
    import flask.ext.admin
    admin = flask.ext.admin.Admin(app, u'用户管理系统')
    babel = Babel(app)
    @babel.localeselector
    def get_locale():
        return 'zh'
    with app.app_context():
        admin.add_view(OperatorView(mongo.db.operator, u'专员管理'))

    # 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
Exemplo n.º 43
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
Exemplo n.º 44
0
def run_flask():

    app = Flask(__name__)

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

    app.run(host="0.0.0.0", debug=True)
    return app
Exemplo n.º 45
0
Arquivo: assets.py Projeto: 3divs/h
def includeme(config):
    config.include('pyramid_webassets')

    config.add_static_view('css', 'h:css')
    config.add_static_view('js', 'h:js')
    config.add_static_view('lib', 'h:lib')
    config.add_static_view('images', 'h:images')

    loader = PythonLoader(config.registry.settings.get('h.assets', __name__))
    bundles = loader.load_bundles()
    for name in bundles:
        config.add_webasset(name, bundles[name])

    from deform.field import Field
    resource_registry = WebassetsResourceRegistry(config.get_webassets_env())
    Field.set_default_resource_registry(resource_registry)
    config.registry.resources = resource_registry
Exemplo n.º 46
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)

    # Fix for NginX
    app.wsgi_app = ProxyFix(app.wsgi_app)

    # initialize the cache
    cache.init_app(app)

    # initialize SQLAlchemy
    db.init_app(app)

    login_manager.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 assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    # register our blueprints
    app.register_blueprint(main)
    app.register_blueprint(g)
    app.register_blueprint(p)
    app.register_blueprint(ev)

    # configure uploads

    configure_uploads(app, (
        flyers,
        press,
    ))

    return app
Exemplo n.º 47
0
def includeme(config):
    config.include('pyramid_webassets')

    config.add_static_view('css', 'h:css')
    config.add_static_view('js', 'h:js')
    config.add_static_view('lib', 'h:lib')
    config.add_static_view('images', 'h:images')

    loader = PythonLoader(config.registry.settings.get('h.assets', __name__))
    bundles = loader.load_bundles()
    for name in bundles:
        config.add_webasset(name, bundles[name])

    from deform.field import Field
    resource_registry = WebassetsResourceRegistry(config.get_webassets_env())
    Field.set_default_resource_registry(resource_registry)
    config.registry.resources = resource_registry
Exemplo n.º 48
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.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
Exemplo n.º 49
0
def configure_extensions(app):

    db.init_app(app)
    login_manager.setup_app(app)

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

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

    @app.before_request
    def before_request():
        g.user = current_user
Exemplo n.º 50
0
 def _setup_assets_env(self, ns, log):
     env = self.env
     if env is None:
         assert not (ns.module and ns.config)
         if ns.module:
             env = PythonLoader(ns.module).load_environment()
         if ns.config:
             env = YAMLLoader(ns.config).load_environment()
     return env
Exemplo n.º 51
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. squall.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)

    # initialize MongoDB
    mongo.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(algorithms, url_prefix="/algorithms")
    app.register_blueprint(data, url_prefix="/data")
    app.register_blueprint(experiments, url_prefix="/experiments")
    app.register_blueprint(tags, url_prefix="/tags")

    return app
Exemplo n.º 52
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
Exemplo n.º 53
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. 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
Exemplo n.º 54
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
Exemplo n.º 55
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
Exemplo n.º 56
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
Exemplo n.º 57
0
def create_app(object_name='bosphorus.settings', env='dev'):

    app = Flask(__name__)

    # set config
    app.config.from_object(object_name)
    app.config['ENV'] = env
    app.config['DEBUG'] = False if env=="prod" else True

    # register all custom jinja filters
    for f in jinja_filters:
        app.jinja_env.filters[f[0]] = f[1]

    #init the cache
    cache.init_app(app)

    #init SQLAlchemy
    db.init_app(app)

    #init Orthanc
    orthanc.init_app(app)

    # Import and register the different asset bundles
    assets_env = Environment()
    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
    from controllers.user import user
    from controllers.studies import studies
    from controllers.person import person
    from utils import proxy
    app.register_blueprint(main)
    app.register_blueprint(user)
    app.register_blueprint(person)
    app.register_blueprint(studies)
    app.register_blueprint(proxy)

    return app