本文整理汇总了Python中pyramid.config.Configurator.add_webasset方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_webasset方法的具体用法?Python Configurator.add_webasset怎么用?Python Configurator.add_webasset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.add_webasset方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_webasset [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application. """
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('partials', '/partials/{partial}.html')
config.add_route('movie.list', '/movies')
config.add_route('movie.play', '/movies/play')
js_bundle = Bundle('js/*.js',
filters='rjsmin', output='js/app.min.js', debug=False)
less_bundle = Bundle('css/app.less',
filters='less', output='css/app.min.css', debug=False)
config.add_webasset('js', js_bundle)
config.add_webasset('less', less_bundle)
config.scan()
return config.make_wsgi_app()
示例2: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_webasset [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
set_cache_regions_from_settings(settings)
config = Configurator(settings=settings)
css = webassets.Bundle(
'bootstrap.min.css',
webassets.Bundle('styles.css', filters='yui_css'),
output='bundle.min.css')
config.add_webasset('css', css)
config.registry.settings['webassets_env'] = config.get_webassets_env()
config.add_subscriber(add_webassets_env, NewRequest)
db_uri = settings['mongodb.db_uri']
conn = pymongo.Connection(db_uri)
config.registry.settings['db_conn'] = conn
try:
if asbool(settings.get('nurl.check_whitelist', False)):
with open(os.path.join(APP_PATH, '..' ,'whitelist.txt')) as whitelist:
config.registry.settings['nurl.whitelist'] = get_whitelist(whitelist,
asbool(settings.get('nurl.check_whitelist_auto_www', False)))
except IOError:
config.registry.settings['nurl.check_whitelist'] = False
config.add_subscriber(add_mongo_db, NewRequest)
config.add_renderer('jsonp', JSONP(param_name='callback'))
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('shortened', '/{short_ref}')
#rest api version 1
config.add_route('shortener_v1', '/api/v1/shorten')
config.scan()
application = config.make_wsgi_app()
#newrelic agent
try:
if asbool(settings.get('newrelic.enable', False)):
newrelic.agent.initialize(os.path.join(APP_PATH, '..', 'newrelic.ini'),
settings['newrelic.environment'])
return newrelic.agent.wsgi_application()(application)
else:
return application
except IOError:
config.registry.settings['newrelic.enable'] = False
return application
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_webasset [as 别名]
def main(global_config, **settings):
config = Configurator(settings=settings)
config.include("cornice")
config.scan("emokykla.auth") # /login, /logout, /register etc.
config.scan("emokykla.user") # /users/<uid>...
config.scan("emokykla.organization") # /orgs/<orgid>...
config.add_renderer('text', TextRenderer)
config.include('pyramid_webassets')
static = Bundle('/*.html', debug=True)
config.add_webasset('static', static)
return config.make_wsgi_app()
示例4: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_webasset [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
set_cache_regions_from_settings(settings)
config = Configurator(settings=settings)
add_directives(config)
authn_policy = BasicAuthAuthenticationPolicy(check=auth_check_func)
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('browse', '/browse')
config.add_route('simple', '/simple*traverse', factory=repository_root_factory)
config.add_notfound_view(notfound, append_slash=True)
config.add_jinja2_extension('webassets.ext.jinja2.AssetsExtension')
assets_env = config.get_webassets_env()
config.commit()
jinja2_env = config.get_jinja2_environment()
jinja2_env.assets_environment = assets_env
# config.add_webasset('test', jst)
config.add_webasset('papaye_js', papaye_js)
config.add_webasset('papaye_css', papaye_css)
config.add_webasset('papaye_font', papaye_font)
config.check_database_config()
config.scan()
config.start_scheduler()
return config.make_wsgi_app()
示例5: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_webasset [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(root_factory=root_factory, settings=settings)
includeme(config)
jsengine = Bundle('app/vendor/jquery-1.8.2.js',
'app/vendor/bootstrap-2.3.0/js/bootstrap.js',
'app/vendor/handlebars-1.0.0-rc.3.js',
'app/vendor/ember-1.0.0-rc.1.js',
'app/vendor/ember-data.js',
filters='rjsmin',
output='js/main.js', debug=False)
templates = Bundle('app/templates/*.handlebars',
'app/templates/*/*.handlebars',
filters='jst',
output='js/templates.js', debug=False)
jsapp = Bundle('app/app.js',
filters='rjsmin',
output='js/app.js', debug=True)
css = Bundle('app/vendor/bootstrap-2.3.0/css/bootstrap.css',
'app/vendor/bootstrap-2.3.0/css/bootstrap-responsive.css',
'app/css/app.css',
filters='cssmin',
output='css/main.css', debug=True)
config.add_webasset('jsengine', jsengine)
config.add_webasset('templates', templates)
config.add_webasset('jsapp', jsapp)
config.add_webasset('css', css)
config.add_renderer('json', json_renderer)
resolver = AssetResolver()
static_path = resolver.resolve('pyred:static').abspath()
config.add_static_view(name='static', path=static_path, cache_max_age=3600)
config.scan()
return config.make_wsgi_app()
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_webasset [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
session_factory = session_factory_from_settings(settings)
authn_policy = AuthTktAuthenticationPolicy('pyvor3',
callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
session_factory=session_factory,
authorization_policy=authz_policy,
authentication_policy=authn_policy
)
config.add_subscriber(handle_request, PasswordResetEvent)
config.add_subscriber(handle_request, NewRegistrationEvent)
config.add_subscriber(handle_request, RegistrationActivatedEvent)
config.add_subscriber(handle_request, ProfileUpdatedEvent)
config.registry.registerUtility(DBSession, ISession)
jst = Bundle('templates/*.html',
filters='jst',
output='jst.js', debug=False)
config.add_webasset('jst', jst)
# jinja2 configuration
config.add_jinja2_extension('jinja2.ext.i18n')
config.add_jinja2_extension('webassets.ext.jinja2.AssetsExtension')
config.add_jinja2_search_path(os.path.join(here, 'templates'))
config.add_jinja2_search_path("pyvore:templates")
jinja2_env = config.get_jinja2_environment()
assets_env = config.get_webassets_env()
jinja2_env.assets_environment = assets_env
renderer = jinja2_renderer_factory(
search_paths=(
'pyvore:templates/',
),
default_templates='deform_jinja2:bootstrap_templates',
translator=PyramidTranslator()
)
deform.Form.set_default_renderer(renderer)
# The are from pyramid_signup, we are overriding them to use CouchForm
# for rendering
override_forms = [
ISULoginForm, ISURegisterForm, ISUForgotPasswordForm,
ISUResetPasswordForm, ISUProfileForm
]
for form in override_forms:
config.registry.registerUtility(PyvoreForm, form)
config.registry.registerUtility(DBSession, ISUSession)
config.include('pyvore.routes')
config.scan()
return config.make_wsgi_app()
示例7: configure_application
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_webasset [as 别名]
def configure_application(settings, config=None):
# Provide deployment-independent settings
settings.update({
# Webassets
'webassets.base_dir': os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'static'
),
'webassets.base_url': '/static/',
# Jinja2
'jinja2.i18n.domain': 'sngconnect',
})
# Configure the database connection.
database_engine = sqlalchemy.engine_from_config(settings, 'database.')
DBSession.configure(bind=database_engine)
# Configure Cassandra connection.
cassandra_connection_pool.initialize_connection_pool(settings)
# Create application configurator.
if config is None:
config = Configurator(settings=settings)
else:
config.add_settings(settings)
config.registry['settings'] = settings
config.registry['database_engine'] = database_engine
# Configure ACL.
config.set_root_factory(RootFactory)
# Configure security.
authorization_policy = ACLAuthorizationPolicy()
config.set_authorization_policy(authorization_policy)
authentication_policy = AuthTktAuthenticationPolicy(
settings['session.secret'],
callback=User.authentication_callback
)
config.set_authentication_policy(authentication_policy)
# Configure session.
session_factory = UnencryptedCookieSessionFactoryConfig(
settings['session.secret']
)
config.set_session_factory(session_factory)
# Add translation directories.
config.add_translation_dirs(os.path.join(
os.path.dirname(__file__),
'locale'
))
# Set default timezone.
config.registry['default_timezone'] = pytz.timezone(
settings['sngconnect.default_timezone']
)
# Configure scheduler.
config.registry['scheduler'] = Scheduler()
register_jobs(config.registry, config.registry['scheduler'])
# Include add-ons.
config.include('pyramid_tm')
config.include('pyramid_jinja2')
config.include('pyramid_webassets')
config.include('pyramid_mailer')
# Configure asset bundles
for name, bundle in ASSET_BUNDLES.iteritems():
config.add_webasset(name, bundle)
# Add Jinja2 extensions.
config.add_jinja2_extension('jinja2.ext.with_')
config.add_jinja2_extension('webassets.ext.jinja2.AssetsExtension')
jinja2_environment = config.get_jinja2_environment()
config.registry['jinja2_environment'] = jinja2_environment
jinja2_environment.filters.update({
'tojson': template_filters.tojson,
'format_datetime': template_filters.format_datetime,
'format_date': template_filters.format_date,
'format_time': template_filters.format_time,
'format_number': template_filters.format_number,
'format_decimal': template_filters.format_decimal,
'format_currency': template_filters.format_currency,
})
jinja2_environment.assets_environment = config.get_webassets_env()
# Configure routes.
for name, pattern in ROUTES:
config.add_route(name, pattern)
# Add static views.
config.add_static_view(
name='static',
path='sngconnect:static',
cache_max_age=0
)
config.add_static_view(
name='device-images',
path=settings['sngconnect.device_image_upload_path'],
cache_max_age=0
)
config.add_static_view(
name='appearance-assets',
path=settings['sngconnect.appearance_assets_upload_path'],
cache_max_age=0
)
return config
示例8: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_webasset [as 别名]
def main(global_config, **settings):
# Provide deployment-independent settings
settings.update({
# Webassets
'webassets.base_dir': os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'static'
),
'webassets.base_url': settings.get('route.prefix', '') + '/static/',
# Jinja2
'jinja2.i18n.domain': 'alpaca',
})
# Configure database session.
database_engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=database_engine)
# Create configurator.
config = Configurator(settings=settings)
config.registry['settings'] = settings
# Configure ACL.
config.set_root_factory(RootFactory)
# Configure security.
authentication_policy = AuthTktAuthenticationPolicy(
settings['session.secret'],
callback=User.authentication_callback
)
config.set_authentication_policy(authentication_policy)
authorization_policy = ACLAuthorizationPolicy()
config.set_authorization_policy(authorization_policy)
# Configure session.
session_factory = UnencryptedCookieSessionFactoryConfig(
settings['session.secret']
)
config.set_session_factory(session_factory)
# Add translation directories.
config.add_translation_dirs(os.path.join(
os.path.dirname(__file__),
'locale'
))
# Include packages.
config.include('pyramid_tm')
config.include('pyramid_jinja2')
config.include('pyramid_webassets')
# Configure asset bundles.
for name, bundle in ASSET_BUNDLES.iteritems():
config.add_webasset(name, bundle)
# Add Jinja2 extensions.
config.add_jinja2_extension('jinja2.ext.with_')
config.get_jinja2_environment().filters['tojson'] = json.dumps
config.registry['jinja2_environment'] = config.get_jinja2_environment()
# Add webassets extension to Jinja2.
config.add_jinja2_extension('webassets.ext.jinja2.AssetsExtension')
webassets_environment = config.get_webassets_env()
config.get_jinja2_environment().assets_environment = webassets_environment
# Configure routes.
for name, pattern in ROUTES.iteritems():
config.add_route(name, pattern)
# Add static view.
config.add_static_view('static', 'static', cache_max_age=3600)
# Scan for view configuration.
config.scan()
return config.make_wsgi_app()