本文整理汇总了Python中pyramid.config.Configurator.add_layout方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_layout方法的具体用法?Python Configurator.add_layout怎么用?Python Configurator.add_layout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.add_layout方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_configurator
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_layout [as 别名]
def get_configurator(settings, enable_auth=True):
config = Configurator(root_factory=SiteRootFactory, settings=settings)
if enable_auth:
authn_policy = SessionAuthenticationPolicy(callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.set_default_permission('view')
config.add_request_method(User.get_auth_user, 'user', reify=True)
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_layout('koala.layout.MasterLayout', 'koala.layout:templates/master_layout.pt')
for route in urls:
config.add_route(route.name, route.pattern)
config.scan()
return config
示例2: test_layout_pyramid_declarative
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_layout [as 别名]
def test_layout_pyramid_declarative(self):
from pyramid.config import Configurator
from player.layout_impl import ILayout
config = Configurator(autocommit=True)
config.include('player')
config.commit()
class Layout(View):
def __call__(self):
""" """
config.add_layout('test', view=Layout)
layout_factory = config.registry.adapters.lookup(
(interface.providedBy(None),
IRequest, interface.providedBy(None)), ILayout, name='test')
self.assertIs(layout_factory.original, Layout)
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_layout [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
config = Configurator(settings=settings, root_factory=".resources.DefaultResource")
config.add_layout("advent.layouts.RedIndex", template="advent:templates/index.mako", name="red")
config.add_layout("advent.layouts.GreenIndex", template="advent:templates/index.mako", name="green")
config.add_layout("advent.layouts.BlueIndex", template="advent:templates/index.mako", name="blue")
config.add_layout("advent.layouts.YellowIndex", template="advent:templates/index.mako", name="yellow")
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('index', '/')
config.scan()
return config.make_wsgi_app()
示例4: get_configurator
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_layout [as 别名]
def get_configurator(settings, enable_auth=True):
connection_debug = asbool(settings.get('connection.debug'))
boto.set_stream_logger('boto', level=(logging.DEBUG if connection_debug else logging.CRITICAL))
ensure_session_keys(settings)
check_types()
config = Configurator(root_factory=SiteRootFactory, settings=settings)
if enable_auth:
authn_policy = SessionAuthenticationPolicy(callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.set_default_permission('view')
config.add_request_method(User.get_auth_user, 'user', reify=True)
cache_duration = int(settings.get('static.cache.duration', 43200))
config.add_static_view(name='static/' + __version__, path='static', cache_max_age=cache_duration)
config.add_layout('eucaconsole.layout.MasterLayout',
'eucaconsole.layout:templates/master_layout.pt')
for route in urls:
config.add_route(route.name, route.pattern)
setup_tweens(config)
setup_exts(config)
config.scan()
return config
示例5: get_configurator
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_layout [as 别名]
def get_configurator(settings, enable_auth=True):
check_config(settings)
connection_debug = asbool(settings.get('connection.debug'))
boto.set_stream_logger('boto', level=(logging.DEBUG if connection_debug else logging.CRITICAL))
ensure_session_keys(settings)
check_types()
config = Configurator(root_factory=SiteRootFactory, settings=settings)
if enable_auth:
authn_policy = SessionAuthenticationPolicy(callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
config.set_default_permission('view')
config.add_request_method(User.get_auth_user, 'user', reify=True)
config.add_subscriber(escape_braces, BeforeRender)
cache_duration = int(settings.get('static.cache.duration', 43200))
config.add_static_view(name='static/' + __version__, path='static', cache_max_age=cache_duration)
config.add_layout('eucaconsole.layout.MasterLayout',
'eucaconsole.layout:templates/master_layout.pt')
locale_dir = os.path.join(os.getcwd(), 'locale')
# use local locale directory over system one
if not os.path.exists(locale_dir) and os.path.exists('/usr/share/locale'):
locale_dir = '/usr/share/locale'
config.add_translation_dirs(locale_dir)
config.set_locale_negotiator(custom_locale_negotiator)
for route in urls:
config.add_route(route.name, route.pattern)
setup_tweens(config, settings)
config.scan('.views')
if not boto.config.has_section('Boto'):
boto.config.add_section('Boto')
boto.config.set('Boto', 'num_retries', settings.get('connection.retries', '2'))
memory_cache = settings.get('cache.memory')
memory_cache_url = settings.get('cache.memory.url')
username = settings.get('cache.username', None)
password = settings.get('cache.password', None)
short_term.configure(
memory_cache,
expiration_time=int(settings.get('cache.short_term.expire')),
arguments={
'url': [memory_cache_url],
'binary': True,
'min_compress_len': 1024,
'behaviors': {"tcp_nodelay": True, "ketama": True},
'username': username,
'password': password
},
)
default_term.configure(
memory_cache,
expiration_time=int(settings.get('cache.default_term.expire')),
arguments={
'url': [memory_cache_url],
'binary': True,
'min_compress_len': 1024,
'behaviors': {"tcp_nodelay": True, "ketama": True},
'username': username,
'password': password
},
)
long_term.configure(
memory_cache,
expiration_time=int(settings.get('cache.long_term.expire')),
arguments={
'url': [memory_cache_url],
'binary': True,
'min_compress_len': 1024,
'behaviors': {"tcp_nodelay": True, "ketama": True},
'username': username,
'password': password
},
)
extra_long_term.configure(
memory_cache,
expiration_time=int(settings.get('cache.extra_long_term.expire')),
arguments={
'url': [memory_cache_url],
'binary': True,
'min_compress_len': 1024,
'behaviors': {"tcp_nodelay": True, "ketama": True},
'username': username,
'password': password
},
)
if not asbool(settings.get('connection.ssl.validation', False)):
"""See https://www.python.org/dev/peps/pep-0476/#opting-out"""
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context
return config
示例6: index
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import add_layout [as 别名]
from pyramid.config import Configurator
def index(request):
return ""
def setup_admin(config):
config.add_admin_site(None, "demo")
config = Configurator()
config.include("pyramid_debugtoolbar")
config.include("pyramid_layout")
config.include("deform_bootstrap")
config.add_layout("mimosa.layouts.BaseLayout", template="mimosa:templates/base.mako")
config.add_view(index, renderer="json")
config.include("mimosa")
config.include(setup_admin, route_prefix="admin-demo")
application = config.make_wsgi_app()