当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.configure方法代码示例

本文整理汇总了Python中sngconnect.database.DBSession.configure方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.configure方法的具体用法?Python DBSession.configure怎么用?Python DBSession.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sngconnect.database.DBSession的用法示例。


在下文中一共展示了DBSession.configure方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import configure [as 别名]
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'database.')
    DBSession.configure(bind=engine)
    ModelBase.metadata.create_all(engine)
开发者ID:fikander,项目名称:sngtec-sngconnect,代码行数:11,代码来源:initialize_database.py

示例2: main

# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import configure [as 别名]
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    database_engine = sqlalchemy.engine_from_config(settings, 'database.')
    DBSession.configure(bind=database_engine)
    generate_data()
开发者ID:fikander,项目名称:sngtec-sngconnect,代码行数:11,代码来源:create_test_users.py

示例3: configure_application

# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import configure [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
开发者ID:fikander,项目名称:sngtec-sngconnect,代码行数:96,代码来源:__init__.py


注:本文中的sngconnect.database.DBSession.configure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。