本文整理汇总了Python中pyramid_basemodel.Session.configure方法的典型用法代码示例。如果您正苦于以下问题:Python Session.configure方法的具体用法?Python Session.configure怎么用?Python Session.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid_basemodel.Session
的用法示例。
在下文中一共展示了Session.configure方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import configure [as 别名]
def main(argv=sys.argv):
if len(argv) < 2:
usage(argv)
config_uri = argv[1]
options = parse_vars(argv[2:])
setup_logging(config_uri)
settings = get_appsettings(config_uri, options=options)
engine = engine_from_config(settings, 'sqlalchemy.')
Session.configure(bind=engine)
Base.metadata.create_all(engine)
示例2: bootstrap_pyramid
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import configure [as 别名]
def bootstrap_pyramid(signal, sender):
import os
from pyramid.paster import bootstrap
sender.app.settings = \
bootstrap(os.environ['BALISTOS_CONFIG'])['registry'].settings
engine = engine_from_config(sender.app.settings, 'sqlalchemy.')
register_after_fork(engine, engine.dispose)
Session.configure(bind=engine)
示例3: main
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import configure [as 别名]
def main(argv=sys.argv):
# TODO: check for DB existance etc.? this fails if run more than once
db_url = os.environ.get('DATABASE_URL')
if not db_url and len(argv) > 1:
env = bootstrap(argv[1])
db_url = env['app'].registry.settings['sqlalchemy.url']
if not db_url:
print 'Set your database url in environment or provide .ini file' # noqa
return
settings = {'sqlalchemy.url': db_url}
engine = engine_from_config(settings, 'sqlalchemy.')
Session.configure(bind=engine)
Base.metadata.create_all(engine)
insert_data()
print 'DB populated with dummy data: {0}'.format(db_url) # noqa
示例4: main
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import configure [as 别名]
def main(global_config, **settings):
"""This function returns a Pyramid WSGI application."""
engine = engine_from_config(settings, 'sqlalchemy.')
Session.configure(bind=engine)
session_factory = UnencryptedCookieSessionFactoryConfig(
settings.get('session.secret', 'secret'),
)
authentication_policy = AuthTktAuthenticationPolicy(
secret=settings.get('authtkt.secret', 'secret'),
hashalg='sha512',
callback=groupfinder,
max_age=86400,
)
authorization_policy = ACLAuthorizationPolicy()
SOCIAL_AUTH_SETTINGS['SOCIAL_AUTH_FACEBOOK_KEY'] = settings['social.facebook_key'] # noqa
SOCIAL_AUTH_SETTINGS['SOCIAL_AUTH_FACEBOOK_SECRET'] = settings['social.facebook_secret'] # noqa
SOCIAL_AUTH_SETTINGS['SOCIAL_AUTH_GOOGLE_OAUTH2_KEY'] = settings['social.google_key'] # noqa
SOCIAL_AUTH_SETTINGS['SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET'] = settings['social.google_secret'] # noqa
settings.update(SOCIAL_AUTH_SETTINGS)
config = Configurator(
settings=settings,
root_factory=RootFactory,
authentication_policy=authentication_policy,
authorization_policy=authorization_policy,
session_factory=session_factory,
)
is_sqlite = 'sqlite' in settings['sqlalchemy.url']
configure(config, sqlite=is_sqlite)
DEVELOPER_KEY = settings['balistos.youtube_key'] # noqa
config.include('pyramid_basemodel')
config.include('pyramid_tm')
config.include('social.apps.pyramid_app')
init_social(config, Base, Session)
config.scan('social.apps.pyramid_app')
return config.make_wsgi_app()
示例5: createTestDB
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import configure [as 别名]
def createTestDB():
engine = create_engine('sqlite:///:memory:')
Session.configure(bind=engine)
Base.metadata.create_all(engine)
insert_data()
示例6: test_filled
# 需要导入模块: from pyramid_basemodel import Session [as 别名]
# 或者: from pyramid_basemodel.Session import configure [as 别名]
def test_filled(self):
'''Test whether correct __LOCALE__ is left'''
request = self._makeRequest()
route_parameters = request.default_locale(slug='some-slug', __LOCALE__='pl')
self.assertEqual(route_parameters['__LOCALE__'], 'pl')
def test_filled_wrong(self):
'''Test whether wrong locale is change'''
request = self._makeRequest()
route_parameters = request.default_locale(slug='some-slug', __LOCALE__='fr')
self.assertTrue(route_parameters['__LOCALE__'] in
request.config.localize.locales.available)
engine = create_engine('sqlite://', echo=False)
Session.configure(bind=engine)
Base.metadata.bind = engine
class RequestMethodTest(BaseRequestTest):
def setUp(self):
'''
setUp test method @see unittest.TestCase.setUp
'''
Base.metadata.create_all(engine)
for locale in ['pl', 'cz', 'fr']:
locale_object = Language(name=text_type(locale),
native_name=text_type(locale),
language_code=text_type(locale))