當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。