本文整理汇总了Python中flask_assets.Environment.init_app方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.init_app方法的具体用法?Python Environment.init_app怎么用?Python Environment.init_app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_assets.Environment
的用法示例。
在下文中一共展示了Environment.init_app方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_app
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import init_app [as 别名]
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
示例2: InvenioAssets
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import init_app [as 别名]
class InvenioAssets(object):
"""Invenio asset extension."""
def __init__(self, app=None, **kwargs):
r"""Extension initialization.
:param app: An instance of :class:`~flask.Flask`.
:param \**kwargs: Keyword arguments are passed to ``init_app`` method.
"""
self.env = Environment()
self.collect = Collect()
if app:
self.init_app(app, **kwargs)
def init_app(self, app, entry_point_group='invenio_assets.bundles',
**kwargs):
"""Initialize application object.
:param app: An instance of :class:`~flask.Flask`.
:param entry_point_group: A name of entry point group used to load
``webassets`` bundles.
.. versionchanged:: 1.0.0b2
The *entrypoint* has been renamed to *entry_point_group*.
"""
self.init_config(app)
self.env.init_app(app)
self.collect.init_app(app)
if entry_point_group:
self.load_entrypoint(entry_point_group)
app.extensions['invenio-assets'] = self
def init_config(self, app):
"""Initialize configuration.
:param app: An instance of :class:`~flask.Flask`.
"""
app.config.setdefault('REQUIREJS_BASEURL', app.static_folder)
app.config.setdefault('COLLECT_STATIC_ROOT', app.static_folder)
app.config.setdefault('COLLECT_STORAGE', 'flask_collect.storage.link')
app.config.setdefault(
'COLLECT_FILTER', partial(collect_staticroot_removal, app))
def load_entrypoint(self, entry_point_group):
"""Load entrypoint.
:param entry_point_group: A name of entry point group used to load
``webassets`` bundles.
.. versionchanged:: 1.0.0b2
The *entrypoint* has been renamed to *entry_point_group*.
"""
for ep in pkg_resources.iter_entry_points(entry_point_group):
self.env.register(ep.name, ep.load())
示例3: setup
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import init_app [as 别名]
class TestConfigNoAppBound:
"""The application is not bound to a specific app.
"""
def setup(self):
self.env = Environment()
def test_no_app_available(self):
"""Without an application bound, we can't do much."""
assert_raises(RuntimeError, setattr, self.env, 'debug', True)
assert_raises(RuntimeError, self.env.config.get, 'debug')
def test_global_defaults(self):
"""We may set defaults even without an application, however."""
self.env.config.setdefault('FOO', 'BAR')
with Flask(__name__).test_request_context():
assert self.env.config['FOO'] == 'BAR'
def test_multiple_separate_apps(self):
"""Each app has it's own separate configuration.
"""
app1 = Flask(__name__)
self.env.init_app(app1)
# With no app yet available...
assert_raises(RuntimeError, getattr, self.env, 'url')
# ...set a default
self.env.config.setdefault('FOO', 'BAR')
# When an app is available, the default is used
with app1.test_request_context():
assert self.env.config['FOO'] == 'BAR'
# If the default is overridden for this application, it
# is still valid for other apps.
self.env.config['FOO'] = '42'
assert self.env.config['FOO'] == '42'
app2 = Flask(__name__)
with app2.test_request_context():
assert self.env.config['FOO'] == 'BAR'
def test_key_error(self):
"""KeyError is raised if a config value doesn't exist.
"""
with Flask(__name__).test_request_context():
assert_raises(KeyError, self.env.config.__getitem__, 'YADDAYADDA')
# The get() helper, on the other hand, simply returns None
assert self.env.config.get('YADDAYADDA') == None
示例4: create_app
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import init_app [as 别名]
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
示例5: TestUrlAndDirectoryWithInitApp
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import init_app [as 别名]
class TestUrlAndDirectoryWithInitApp(object):
"""[Regression] Make sure the automatic "directory" and "url"
values also work if the application is initialized via "init_app()".
"""
def setup(self):
self.app = Flask(__name__, static_path='/initapp_static')
self.env = Environment()
self.env.init_app(self.app)
def test(self):
"""Make sure the "url" and "directory" config values are
read from the Flask app.
"""
with self.app.test_request_context():
assert not 'url' in self.env.config
assert Bundle('foo', env=self.env).urls() == ['/initapp_static/foo']
assert not 'directory' in self.env.config
root = self.app.root_path
assert get_all_bundle_files(Bundle('foo'), self.env) == [root + '/static/foo']
示例6: InvenioAssets
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import init_app [as 别名]
class InvenioAssets(object):
"""Invenio asset extension."""
def __init__(self, app=None, entrypoint='invenio_assets.bundles',
**kwargs):
"""Extension initialization."""
self.env = Environment()
self.collect = Collect()
self.entrypoint = entrypoint
if app:
self.init_app(app, **kwargs)
def init_app(self, app, **kwargs):
"""Initialize application object."""
self.init_config(app)
self.env.init_app(app)
self.collect.init_app(app)
self.init_cli(app.cli)
if self.entrypoint:
self.load_entrypoint(self.entrypoint)
app.extensions['invenio-assets'] = self
def init_config(self, app):
"""Initialize configuration."""
app.config.setdefault("REQUIREJS_BASEURL", app.static_folder)
app.config.setdefault('COLLECT_STATIC_ROOT', app.static_folder)
app.config.setdefault('COLLECT_STORAGE', 'flask_collect.storage.link')
def init_cli(self, cli):
"""Initialize CLI."""
cli.add_command(assets_cmd)
cli.add_command(npm)
cli.add_command(collect)
def load_entrypoint(self, entrypoint):
"""Load entrypoint."""
for ep in pkg_resources.iter_entry_points(entrypoint):
self.env.register(ep.name, ep.load())
示例7: import
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import init_app [as 别名]
from flask import (
Flask,
jsonify,
request,
url_for,
render_template,
)
from jsonschema import validate
from flask_assets import Environment
IS_DEBUG = os.environ.get('DEBUG', 'false').lower() == 'true'
app = Flask(__name__, static_url_path='/dist', static_folder='./dist')
app.config['ASSETS_DEBUG'] = IS_DEBUG
assets = Environment()
assets.init_app(app)
class FlightService(object):
'''Data access layer extracts data from internal API.
This can be extended for external APIs in the future'''
def __init__(self, filename):
with open(filename) as f:
self.flights = json.loads(f.read())['flights']
# index the json for quick lookups
self.flights_index = {}
for index, flight in enumerate(self.flights):
self.flights_index[flight['number']] = index
def get(self, number):
示例8: init
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import init_app [as 别名]
def init(app):
assets = Environment(app)
# Basic CSS and Javascript:
# Available under: base_css, base_js
base_css = Bundle('css/base.scss', filters='pyscss',
output='gen/css/base.%(version)s.css')
base_js = Bundle('scripts/base.js', filters='jsmin',
output='gen/scripts/base.%(version)s.js')
assets.register('base_css', base_css)
assets.register('base_js', base_js)
# Pleblist-related javascript
# Available under the following assets: pleblist_shared, pleblist_host, pleblist_client
pleblist_client = Bundle('scripts/pleblist.js', filters='jsmin',
output='gen/scripts/pleblist.%(version)s.js')
pleblist_shared = Bundle('scripts/pleblist.shared.js', filters='jsmin',
output='gen/scripts/pleblist.shared.%(version)s.js')
pleblist_host = Bundle(
'scripts/pleblist.host.js',
'scripts/pleblist.host.streamtip.js',
'scripts/pleblist.host.streamelements.js',
'scripts/pleblist.host.streamlabs.js',
filters='jsmin',
output='gen/scripts/pleblist.host.%(version)s.js')
assets.register('pleblist_shared', pleblist_shared)
assets.register('pleblist_client', pleblist_client)
assets.register('pleblist_host', pleblist_host)
# CLR Overlay
# Availabe under: clr_overlay_js, clr_overlay_css, clr_donations_js, clr_donations_css, clr_shared_js
clr_overlay_js = Bundle('scripts/clr.overlay.js', filters='jsmin',
output='gen/scripts/clr.overlay.%(version)s.js')
clr_overlay_css = Bundle('css/clr.overlay.scss', filters='pyscss',
output='gen/css/clr.overlay.%(version)s.css')
clr_donations_js = Bundle('scripts/clr.donations.js', filters='jsmin',
output='gen/scripts/clr.donations.%(version)s.js')
clr_donations_css = Bundle('css/clr.donations.scss', filters='pyscss',
output='gen/css/clr.donations.%(version)s.css')
clr_shared_js = Bundle('scripts/clr.shared.js', filters='jsmin',
output='gen/scripts/clr.shared.%(version)s.js')
assets.register('clr_overlay_js', clr_overlay_js)
assets.register('clr_overlay_css', clr_overlay_css)
assets.register('clr_donations_js', clr_donations_js)
assets.register('clr_donations_css', clr_donations_css)
assets.register('clr_shared_js', clr_shared_js)
# Admin site
# Availabe under: admin_create_banphrase, admin_create_command,
# admin_create_row, admin_edit_command
admin_create_banphrase = Bundle('scripts/admin/create_banphrase.js', filters='jsmin',
output='gen/scripts/admin/create_banphrase.%(version)s.js')
admin_create_command = Bundle('scripts/admin/create_command.js', filters='jsmin',
output='gen/scripts/admin/create_command.%(version)s.js')
admin_create_row = Bundle('scripts/admin/create_row.js', filters='jsmin',
output='gen/scripts/admin/create_row.%(version)s.js')
admin_edit_command = Bundle('scripts/admin/edit_command.js', filters='jsmin',
output='gen/scripts/admin/edit_command.%(version)s.js')
assets.register('admin_create_banphrase', admin_create_banphrase)
assets.register('admin_create_command', admin_create_command)
assets.register('admin_create_row', admin_create_row)
assets.register('admin_edit_command', admin_edit_command)
# Admin CLR
admin_clr_donations_edit_js = Bundle('scripts/admin/clr/donations/edit.js',
output='gen/scripts/admin/clr/donations/edit.%(version)s.js')
assets.register('admin_clr_donations_edit_js', admin_clr_donations_edit_js)
notifications_base = Bundle('scripts/notifications/base.js', filters='jsmin',
output='gen/scripts/notifications/base.%(version)s.js')
assets.register('notifications_base', notifications_base)
notifications_subscribers = Bundle('scripts/notifications/subscribers.js', filters='jsmin',
output='gen/scripts/notifications/subscribers.%(version)s.js')
assets.register('notifications_subscribers', notifications_subscribers)
# Third party libraries
# Available under: autolinker
autolinker = Bundle('scripts/autolinker.js', filters='jsmin',
output='gen/scripts/autolinker.%(version)s.js')
assets.register('autolinker', autolinker)
# Commands
# Available under: commands_js
commands_js = Bundle('scripts/commands.js', filters='jsmin',
output='gen/scripts/commands.%(version)s.js')
assets.register('commands_js', commands_js)
# Pagination script
# Available under: paginate_js
paginate_js = Bundle('scripts/paginate.js', filters='jsmin',
output='gen/scripts/paginate.%(version)s.js')
assets.register('paginate_js', paginate_js)
assets.init_app(app)
示例9: setupAssets
# 需要导入模块: from flask_assets import Environment [as 别名]
# 或者: from flask_assets.Environment import init_app [as 别名]
def setupAssets(app):
createStorage()
assets = Environment(app)
assets.init_app(app)
assets.register("js_all", bundleJavascripts())
assets.register("css_all", bundleStylesheets())