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


Python DBSession.configure方法代码示例

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


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

示例1: init_db

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import configure [as 别名]
def init_db(config_path):
    from intranet3.models import DBSession, Base
    setup_logging(config_path)
    settings = get_appsettings(config_path)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    print 'Done'
开发者ID:KenjiTakahashi,项目名称:intranet,代码行数:10,代码来源:__init__.py

示例2: main

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import configure [as 别名]
def main(global_config, **settings):
    """
    Creates wsgi app
    """
    global config
    config = settings
    global memcache
    memcache = MemcachedCache([config['MEMCACHE_URI']])

    from intranet3.models import DBSession, Base, User
    from intranet3.utils import request
    from intranet3.views.auth import forbidden_view

    def groupfinder(userid, request):
        if userid == 0: ## cron userid
            perm = ['g:cron']
        else:
            user = User.query.get(userid)
            perm = [ 'g:%s' % g for g in user.groups ]
            if user.freelancer:
                perm.append('g:freelancer')
        return perm

    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    session_factory = session_factory_from_settings(settings)
    authn_policy = CustomAuthenticationPolicy(config['SESSION_KEY'], callback=groupfinder)
    authz_policy = ACLAuthorizationPolicy()
    pyramid_config = Configurator(
        settings=settings,
        authentication_policy=authn_policy,
        authorization_policy=authz_policy,
        session_factory=session_factory,
        request_factory=request.Request,
        default_permission='view',
        root_factory=Root,
    )
    pyramid_config.add_forbidden_view(forbidden_view)

    pyramid_config.add_static_view('static', 'static', cache_max_age=3600)

    #beta:
    #pyramid_config.add_route('api_my_bugs', '/api/bugs')
    #pyramid_config.add_route('api_time_collection', '/api/times')
    #pyramid_config.add_route('api_time', '/api/times/{id:\d+}')

    pyramid_config.add_route('api_team', '/api/teams/{team_id:\d+}')
    pyramid_config.add_route('api_teams', '/api/teams')
    pyramid_config.add_route('api_users', '/api/users')
    pyramid_config.add_route('api_preview', '/api/preview')
    pyramid_config.add_route('api_images', '/api/images/{type:\w+}/{id:\d+}')
    pyramid_config.add_route('api_presence', 'api/presence')
    pyramid_config.add_route('api_blacklist', 'api/blacklist')
    pyramid_config.add_route('api_lateness', '/api/lateness')
    pyramid_config.add_route('api_absence', '/api/absence')
    pyramid_config.add_route('api_absence_days', '/api/absence_days')

    pyramid_config.add_renderer('.html', 'pyramid_jinja2.renderer_factory')
    pyramid_config.add_renderer(None, 'intranet3.utils.renderer.renderer_factory')
    pyramid_config.add_translation_dirs('intranet3:locale/')

    jinja2_env = pyramid_config.get_jinja2_environment()
    from intranet3.utils import filters

    jinja2_env.filters['slugify'] = filters.slugify
    jinja2_env.filters['parse_datetime_to_miliseconds'] = filters.parse_datetime_to_miliseconds
    jinja2_env.filters['parse_user_email'] = filters.parse_user_email
    jinja2_env.filters['timedelta_to_minutes'] = filters.timedelta_to_minutes
    jinja2_env.filters['format_time'] = filters.format_time
    jinja2_env.filters['dictsort2'] = filters.do_dictsort
    jinja2_env.filters['tojson'] = filters.tojson
    jinja2_env.filters['comma_number'] = filters.comma_number
    jinja2_env.filters['first_words'] = filters.first_words
    jinja2_env.filters['first_words'] = filters.first_words

    jinja2_env.filters['is_true'] = filters.is_true
    jinja2_env.filters['is_false'] = filters.is_false
    jinja2_env.filters['initials'] = filters.initials
    jinja2_env.filters['int_or_float'] = filters.int_or_float
    jinja2_env.filters['markdown'] = filters.markdown_filter
    jinja2_env.globals.update(zip=zip)

    pyramid_config.include('pyramid_autoroute')
    if 'venusian.ignore' in settings:
        venusian_ingore = settings.get('venusian.ignore')
    else:
        venusian_ingore = None
    pyramid_config.scan(ignore=venusian_ingore)

    pyramid_config.add_settings({
        'TEMPLATE_DIR': os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates'),
    })


    app = pyramid_config.make_wsgi_app()
    return app
开发者ID:avalanchy,项目名称:intranet,代码行数:99,代码来源:__init__.py

示例3: main

# 需要导入模块: from intranet3.models import DBSession [as 别名]
# 或者: from intranet3.models.DBSession import configure [as 别名]
def main(global_config, **settings):
    """
    Creates wsgi app
    """
    global is_production
    is_production = (
        'DEBUG' not in settings or
        settings.get('DEBUG', '').lower() == 'false'
    )

    init_config(settings)
    init_memcache(settings)

    from intranet3.models import DBSession, Base, User
    from intranet3.utils import request, acl

    def groupfinder(userid, request):
        if userid == -1: ## cron userid
            perm = ['g:cron']
        elif userid == -2: ## task userid
            perm = ['g:task']
        else:
            user = User.query.get(userid)
            perm = ['g:%s' % g for g in user.groups]
        return perm

    engine = engine_from_config(settings)
    engine.pool._use_threadlocal = True
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    session_factory = session_factory_from_settings(settings)
    authn_policy = CustomAuthenticationPolicy(settings['SESSION_KEY'], callback=groupfinder)
    authz_policy = ACLAuthorizationPolicy()
    pyramid_config = Configurator(
        settings=settings,
        authentication_policy=authn_policy,
        authorization_policy=authz_policy,
        session_factory=session_factory,
        request_factory=request.Request,
        default_permission='view',
        root_factory=acl.Root,
    )

    pyramid_config.add_static_view('static', 'static', cache_max_age=3600)

    pyramid_config.add_route('api_globals', '/api/globals')
    pyramid_config.add_route('api_team', '/api/teams/{team_id:\d+}')
    pyramid_config.add_route('api_teams', '/api/teams')

    pyramid_config.add_route('api_board', '/api/boards/{board_id:\d+}')
    pyramid_config.add_route('api_boards', '/api/boards')
    pyramid_config.add_route('api_sprint_bugs', '/api/sprint/{sprint_id:\d+}/bugs')

    pyramid_config.add_route('api_users', '/api/users')
    pyramid_config.add_route('api_preview', '/api/preview')
    pyramid_config.add_route('api_images', '/api/images/{type:\w+}/{id:\d+}')
    pyramid_config.add_route('api_presence', 'api/presence')
    pyramid_config.add_route('api_blacklist', 'api/blacklist')
    pyramid_config.add_route('api_lateness', '/api/lateness')
    pyramid_config.add_route('api_absence', '/api/absence')
    pyramid_config.add_route('api_absence_days', '/api/absence_days')

    pyramid_config.add_renderer('.html', 'pyramid_jinja2.renderer_factory')
    pyramid_config.add_renderer(None, 'intranet3.utils.renderer.renderer_factory')
    pyramid_config.add_translation_dirs('intranet3:locale/')

    jinja2_env = pyramid_config.get_jinja2_environment()
    from intranet3.utils import filters

    jinja2_env.filters['slugify'] = filters.slugify
    jinja2_env.filters['parse_datetime_to_miliseconds'] = filters.parse_datetime_to_miliseconds
    jinja2_env.filters['parse_user_email'] = filters.parse_user_email
    jinja2_env.filters['timedelta_to_minutes'] = filters.timedelta_to_minutes
    jinja2_env.filters['format_time'] = filters.format_time
    jinja2_env.filters['dictsort2'] = filters.do_dictsort
    jinja2_env.filters['tojson'] = filters.tojson
    jinja2_env.filters['comma_number'] = filters.comma_number
    jinja2_env.filters['first_words'] = filters.first_words
    jinja2_env.filters['first_words'] = filters.first_words

    jinja2_env.filters['is_true'] = filters.is_true
    jinja2_env.filters['is_false'] = filters.is_false
    jinja2_env.filters['initials'] = filters.initials
    jinja2_env.filters['int_or_float'] = filters.int_or_float
    jinja2_env.filters['markdown'] = filters.markdown_filter
    jinja2_env.globals.update(zip=zip)

    pyramid_config.include('pyramid_autoroute')

    pyramid_config.scan()

    pyramid_config.add_settings({
        'TEMPLATE_DIR': os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates'),
    })

    if uwsgi and is_production:
        from intranet3.cron import run_cron_tasks
        run_cron_tasks()

    app = pyramid_config.make_wsgi_app()
#.........这里部分代码省略.........
开发者ID:Rhenan,项目名称:intranet-open,代码行数:103,代码来源:__init__.py


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