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


Python Configurator.set_locale_negotiator方法代码示例

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


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

示例1: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def main(global_config, **settings):
    """ This function returns a WSGI application.
    """

    # TODO: make it safer. Remember it's unencrypted.
    my_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseecreet')
    authn_policy = AuthTktAuthenticationPolicy(secret='sosecret',
                                               callback=groupfinder)
    authz_policy = ACLAuthorizationPolicy()
    config = Configurator(session_factory=my_session_factory,
                          root_factory=root_factory, settings=settings,
                          authentication_policy=authn_policy,
                          authorization_policy=authz_policy)
    config.add_translation_dirs('easyblog:locale/')
    config.set_locale_negotiator(my_locale_negotiator)
    config.add_settings(encoding="UTF-8")
    # config.add_settings(languages=['fi', 'en'])
    # config.add_settings({'default_locale_name': 'fi'})
    config.add_settings(default_encoding="UTF-8")
    config.hook_zca()

    config.include('pyramid_viewgroup')

    config.add_static_view('static', 'easyblog:static/', cache_max_age=3600)
    config.scan()

    config.add_route('lang', '/lang-{code}')
    return config.make_wsgi_app()
开发者ID:tojuhaka,项目名称:easyblog,代码行数:30,代码来源:__init__.py

示例2: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def main(global_config, **settings):
    """ Return a Pyramid WSGI application. """
    settings['config_uri'] = global_config['__file__']

    config = Configurator(registry=getGlobalSiteManager())
    config.setup_registry(settings=settings)
    config.add_translation_dirs('assembl:locale/')

    def my_locale_negotiator(request):
        locale = default_locale_negotiator(request)
        available = settings['available_languages'].split()
        locale = locale if locale in available else None
        if not locale:
            locale = request.accept_language.best_match(
                available, settings.get('pyramid.default_locale_name', 'en'))
        request._LOCALE_ = locale
        return locale

    config.set_locale_negotiator(my_locale_negotiator)

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('widget', 'widget', cache_max_age=3600)

    config.add_view(maintenance_message)
    config.add_notfound_view(maintenance_message)
    return config.make_wsgi_app()
开发者ID:assembl,项目名称:assembl,代码行数:28,代码来源:maintenance.py

示例3: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    authentication_policy = AuthTktAuthenticationPolicy('seekrit', callback=groupfinder)
    authorization_policy = ACLAuthorizationPolicy()

    engine = engine_from_config(settings, prefix='sqlalchemy.')
    db_maker = sessionmaker(bind=engine)
    settings['rel_db.sessionmaker'] = db_maker

    config = Configurator(settings=settings,
                          root_factory='scielobooks.resources.RootFactory',
                          authentication_policy=authentication_policy,
                          authorization_policy=authorization_policy,
                          request_factory=MyRequest,
                          renderer_globals_factory=renderer_globals_factory)

    config.include(pyramid_zcml)
    config.load_zcml('configure.zcml')
    config.include('pyramid_mailer')
    config.include('pyramid_celery')

    config.registry['mailer'] = Mailer.from_settings(settings)
    config.registry['app_version'] = APP_VERSION

    db_uri = settings['db_uri']
    conn = couchdbkit.Server(db_uri)
    config.registry.settings['db_conn'] = conn
    config.add_subscriber(add_couch_db, NewRequest)

    config.scan('scielobooks.models')
    initialize_sql(engine)

    if settings['serve_static_files'] == 'true':
        config.add_static_view(name='static', path='static')
    config.add_static_view('deform_static', 'deform:static')
    config.add_static_view('/'.join((settings['db_uri'], settings['db_name'])), 'scielobooks:database')
    config.add_static_view(settings['fileserver_url'], 'scielobooks:fileserver')

    config.add_view(custom_forbidden_view, context=Forbidden)

    config.add_translation_dirs('scielobooks:locale/')
    config.set_locale_negotiator(custom_locale_negotiator)

    my_session_factory = UnencryptedCookieSessionFactoryConfig('itsaseekreet')
    config.set_session_factory(my_session_factory)

    application = config.make_wsgi_app()

    try:
        if settings.get('newrelic.enable', 'False').lower() == 'true':
            newrelic.agent.initialize(os.path.join(APP_PATH, '..', 'newrelic.ini'), settings['newrelic.environment'])
            return newrelic.agent.wsgi_application()(application)
        else:
            return application
    except IOError:
        config.registry.settings['newrelic.enable'] = False
        return application
开发者ID:fabiobatalha,项目名称:scielobooks,代码行数:60,代码来源:__init__.py

示例4: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def main(global_config, **settings):
    """ Return a Pyramid WSGI application. """
    settings['config_uri'] = global_config['__file__']

    # here we create the engine and bind it to the (not really a) session
    # factory
    configure_engine(settings)

    from views import root_factory
    config = Configurator(settings=settings, root_factory=root_factory)
    config.add_translation_dirs('assembl:locale/')
    config.set_locale_negotiator(my_locale_negotiator)
    config.add_tween(
        'assembl.tweens.virtuoso_deadlock.transient_deadlock_tween_factory',
        under="pyramid_tm.tm_tween_factory")


    config.include('.lib.zmqlib')
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)
    if not settings.get('nosecurity', False):
        # import after session to delay loading of BaseOps
        from auth import authentication_callback
        auth_policy = SessionAuthenticationPolicy(
            callback=authentication_callback)
        config.set_authentication_policy(auth_policy)
        config.set_authorization_policy(ACLAuthorizationPolicy())
    # ensure default roles and permissions at startup
    from models import get_session_maker
    from auth.models import (
        populate_default_roles, populate_default_permissions)
    with transaction.manager:
        session = get_session_maker()
        populate_default_roles(session)
        populate_default_permissions(session)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.include('cornice')  # REST services library.
    # config.include('.lib.alembic')
    # config.include('.lib.email')
    config.include('.views')

    # config.scan('.lib')
    config.scan('.views')

    # jinja2
    config.include('pyramid_jinja2')
    config.add_jinja2_extension('jinja2.ext.i18n')

    # Mailer
    config.include('pyramid_mailer')

    # Tasks
    config.include('.tasks')

    config.include('.view_def')

    return config.make_wsgi_app()
开发者ID:hellsingblack,项目名称:assembl,代码行数:59,代码来源:__init__.py

示例5: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(root_factory=root_factory, settings=settings)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_translation_dirs('tojuhaka:locale/')
    config.set_locale_negotiator(my_locale_negotiator)
    config.scan()
    return config.make_wsgi_app()
开发者ID:tojuhaka,项目名称:tojuhaka,代码行数:11,代码来源:__init__.py

示例6: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    zcml_file = settings.get('configure_zcml', 'configure.zcml')
    config = Configurator(root_factory=Root, settings=settings)
    config.include('pyramid_zcml')
    config.load_zcml(zcml_file)
    
    config.add_translation_dirs('scieloweb:locale/')
    config.set_locale_negotiator(custom_locale_negotiator)
    
    return config.make_wsgi_app()
开发者ID:fabiobatalha,项目名称:CouchDB-Web,代码行数:14,代码来源:__init__.py

示例7: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def main(global_config, **settings):
    config_secrets(settings)
    config = Configurator(settings=settings)
    config_static(config)
    config_jinja2(config)
    config_db(config, settings)
    config_routes(config)
    config_auth_policy(config, settings)
    config.set_locale_negotiator(localization)
    config_mailer(config)
    config.add_request_method(get_user,'user', reify=True)
    return config.make_wsgi_app()
开发者ID:ricardosiri68,项目名称:patchcap,代码行数:14,代码来源:__init__.py

示例8: make_app

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def make_app(global_config, **settings):
    session_factory = session_factory_from_settings(settings)
    config = Configurator(settings=settings,
                          request_factory=Request,
                          session_factory=session_factory)

    config.add_route('index', '/')
    config.add_view('mnemos.views.index', route_name='index',
                     renderer='mnemos:templates/index.pt')
    config.add_route('add', '/add')
    config.add_view('mnemos.views.add_form', route_name='add',
                    renderer='mnemos:templates/add.pt',
                    request_method='GET')
    config.add_view('mnemos.views.add', route_name='add',
                    renderer='mnemos:templates/add.pt',
                    request_method='POST')
    config.add_route('view', '/contacts/{contact_id}')
    config.add_view('mnemos.views.view', route_name='view',
                    renderer='mnemos:templates/view.pt')
    config.add_route('edit', '/contacts/{contact_id}/edit')
    config.add_view('mnemos.views.edit', route_name='edit',
                    renderer='mnemos:templates/view.pt',
                    request_method='POST')
    config.add_route('remove', '/contacts/{contact_id}/remove')
    config.add_view('mnemos.views.remove', route_name='remove',
                    request_method='POST')
    config.add_route('ajax_search', '/ajax_search')
    config.add_view('mnemos.views.ajax_search', route_name='ajax_search',
                    xhr=True, renderer='json')
    config.add_route('birthdays', '/birthdays')
    config.add_view('mnemos.views.birthdays', route_name='birthdays',
                    renderer='mnemos:templates/birthdays.pt')
    config.add_route('map', '/map')
    config.add_view('mnemos.views.map_view', route_name='map',
                    renderer='mnemos:templates/map.pt')
    config.add_route('contacts_in_bbox', '/contacts-in-bbox')
    config.add_view('mnemos.views.contacts_in_bbox',
                    route_name='contacts_in_bbox',
                    renderer='json')
    config.add_route('export', '/export')
    config.add_view('mnemos.views.export_form',
                    route_name='export',
                    request_method='GET',
                    renderer='mnemos:templates/export.pt')
    config.add_view('mnemos.views.export',
                    route_name='export',
                    request_method='POST',
                    renderer='mnemos:templates/exported.pt')
    config.add_static_view('static', 'static')
    config.add_translation_dirs('mnemos:locale')
    config.set_locale_negotiator('mnemos.i18n.locale_negotiator')
    return config.make_wsgi_app()
开发者ID:dbaty,项目名称:Mnemos,代码行数:54,代码来源:app.py

示例9: make_app

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def make_app(global_config, **settings):
    """Return the WSGI application."""
    nginx_upload_progress = settings.get(
        'poulda.nginx_upload_progress', 'false').lower() == 'true'
    if not nginx_upload_progress:
        from poulda.models import initialize_db
        initialize_db(settings['poulda.db_url'])
    config = Configurator(settings=settings)
    config.include('pyramid_chameleon')

    # Authentication and authorization policies
    auth_policy = AuthTktAuthenticationPolicy(settings['poulda.secret'])
    config.set_authentication_policy(auth_policy)
    authz_policy = AuthorizationPolicy()
    config.set_authorization_policy(authz_policy)

    # Views
    config.set_default_permission(PERMISSION_UPLOAD)
    config.add_static_view('static', 'static')
    config.add_route('home', '/')
    config.add_view('poulda.views.home',
                    route_name='home',
                    permission=NO_PERMISSION_REQUIRED)
    config.add_route('upload_form', '/upload', request_method='GET')
    config.add_view('poulda.views.upload_form', route_name='upload_form')
    config.add_route('upload', '/upload', request_method='POST')
    if nginx_upload_progress:
        upload_view = 'poulda.views.upload_with_nginx_upload_progress'
    else:
        upload_view = 'poulda.views.upload'
    config.add_view(upload_view, route_name='upload')
    if not nginx_upload_progress:
        # We need this view only if Nginx Upload Progress has been
        # disabled.
        config.add_route('progress', '/progress')
        config.add_view('poulda.views.progress', route_name='progress',
                        renderer='json')
    config.add_route('success', '/success')
    config.add_view('poulda.views.success', route_name='success')
    config.add_route('login', '/login', request_method='POST')
    config.add_view('poulda.views.login', route_name='login',
                    permission=NO_PERMISSION_REQUIRED)
    config.add_route('logout', '/logout')
    config.add_view('poulda.views.logout', route_name='logout')
    config.add_view('poulda.views.forbidden', context=HTTPForbidden,
                    permission=NO_PERMISSION_REQUIRED)

    # Internationalization
    config.add_translation_dirs('poulda:locale')
    config.set_locale_negotiator('poulda.i18n.locale_negotiator')

    return config.make_wsgi_app()
开发者ID:BurritoBazooka,项目名称:Poulda,代码行数:54,代码来源:app.py

示例10: make_app

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def make_app(global_settings, **settings):
    """Set up and return the WSGI application."""
    config = Configurator(settings=settings)

    # Third-party includes
    config.include('pyramid_chameleon')

    # Initialize database and ORM
    db_verbose = settings.get('brouz.db_verbose', 'false').lower() == 'true'
    initialize_sql(settings['brouz.db_url'], echo=db_verbose)

    # Sessions
    session_secret = settings['brouz.secret']
    session_factory = UnencryptedCookieSessionFactoryConfig(session_secret)
    config.set_session_factory(session_factory)

    # Routes and views
    config.add_static_view('static', 'static')
    config.add_static_view('static-deform', 'deform:static')
    config.add_route('home', '/')
    config.add_view('.views.home', route_name='home')
    config.add_route('reports', '/reports')
    config.add_route('reports_specific_year', '/reports/{year}')
    config.add_view('brouz.views.reports', route_name='reports')
    config.add_view('brouz.views.reports', route_name='reports_specific_year')
    config.add_route('add-unique', '/add-unique')
    config.add_view('brouz.views.add_unique_form', route_name='add-unique',
                    request_method='GET')
    config.add_view('brouz.views.add_unique', route_name='add-unique',
                    request_method='POST')
    config.add_route('add-composite', '/add-composite')
    config.add_view('brouz.views.add_composite_form',
                    route_name='add-composite', request_method='GET')
    config.add_view('brouz.views.add_composite', route_name='add-composite',
                    request_method='POST')
    config.add_route('autocomplete', '/autocomplete/{field}')
    config.add_view('brouz.views.autocomplete', route_name='autocomplete',
                    renderer='json')
    config.add_route('edit', '/edit/{transaction_id}')
    config.add_view('brouz.views.edit_form', route_name='edit',
                    request_method='GET')
    config.add_view('brouz.views.edit', route_name='edit',
                    request_method='POST')
    config.add_route('delete', '/delete/{transaction_id}',
                     request_method='POST')
    config.add_view('brouz.views.delete', route_name='delete')

    # Internationalization
    config.add_translation_dirs('brouz:locale')
    config.set_locale_negotiator('brouz.i18n.locale_negotiator')

    return config.make_wsgi_app()
开发者ID:dbaty,项目名称:Brouz,代码行数:54,代码来源:app.py

示例11: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    # configure SQLAlchemy
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    config = Configurator(settings=settings)
    # configure the root factory (used for Auth & Auth)
    root_factory = RootFactory
    config.set_root_factory(root_factory)
    # configure session
    session_factory = session_factory_from_settings(settings)
    config.set_session_factory(session_factory)
    # configure auth & auth
    config.include(anuket.add_authorization)
    # set an auth_user object
    config.set_request_property(get_auth_user, 'auth_user', reify=True)

    # configure subscribers
##    config.include(anuket.subscribers)
##Comented to avoid crsf check
##TODO bring back CSRF
    from pyramid.events import BeforeRender, NewRequest
    config.add_subscriber(anuket.subscribers.add_renderer_globals, BeforeRender)
    config.add_subscriber(anuket.subscribers.add_localizer, NewRequest)


    # configure static views
    config.include(anuket.add_static_views)
    # configure routes
    config.include(anuket.views.root)
    config.include(anuket.views.tools)
    config.include(anuket.views.user)

#TODO improve this
    from begotemp.views import geo_zone, geo_group, geo_rock
    config.include(geo_zone)
    config.include(geo_group)
    config.include(geo_rock)
    ## configure views
    config.scan('anuket')
    config.scan()



    config.add_translation_dirs('anuket:locale')
    config.set_locale_negotiator('anuket.lib.i18n.locale_negotiator')

    return config.make_wsgi_app()
开发者ID:miniwark,项目名称:begotemp,代码行数:52,代码来源:__init__.py

示例12: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def main(global_config, **settings):
    config_secrets(settings)
    config = Configurator(settings=settings)
    #config.include('pyramid_celery')
    #config.configure_celery(global_config['__file__'])
    config_static(config, settings['storage'])
    config_jinja2(config)
    config_db(config, settings)
    config_routes(config)
    config_auth_policy(config, settings)
    config.set_locale_negotiator(localization)
    #config_mailer(config)
    config.add_request_method(get_user,'user', reify=True)
    return config.make_wsgi_app()
开发者ID:MirichST,项目名称:patchcap,代码行数:16,代码来源:__init__.py

示例13: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('locale', '/locale')
    config.scan()
    config.add_translation_dirs('pyramid_i18n_howto:locale')
    config.add_subscriber('pyramid_i18n_howto.i18n.add_renderer_globals',
                          'pyramid.events.BeforeRender')
    config.add_subscriber('pyramid_i18n_howto.i18n.add_localizer',
                          'pyramid.events.NewRequest')
    config.set_locale_negotiator(custom_locale_negotiator)
    return config.make_wsgi_app()
开发者ID:ddellaquila,项目名称:pyramid_i18n_howto,代码行数:17,代码来源:__init__.py

示例14: base_configure

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def base_configure(global_config, **settings):

    for key, value in conf_defaults.items():
        settings.setdefault(key, value)

    _resolve_dotted(settings)

    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    
    authentication_policy = AuthTktAuthenticationPolicy(settings['leirirekkari.secret'], callback=groupfinder)
    authorization_policy = ACLAuthorizationPolicy()
    
    config = Configurator(settings=settings, root_factory=Root)

    config.set_request_property(get_user, 'user', reify=True)

    config.set_authentication_policy(authentication_policy)
    config.set_authorization_policy(authorization_policy)
    config.set_default_permission('view')

#    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view(name=settings['leirirekkari.static_name'], path=settings['leirirekkari.static_path'], cache_max_age=3600)
    config.add_forbidden_view(forbidden)
    config.add_notfound_view(notfound, append_slash=True)
    
    config.add_translation_dirs('leirirekkari:locale/')

    config.set_locale_negotiator(leirirekkari_locale_negotiator)
    
    config.add_subscriber('leirirekkari.subscribers.add_localizer', 'pyramid.events.NewRequest')
    config.add_subscriber('leirirekkari.subscribers.add_renderer_globals', 'pyramid.events.BeforeRender')
    config.add_subscriber('leirirekkari.subscribers.breadcrumb_subscriber', 'pyramid.events.NewRequest')
    
    config.include('pyramid_mailer')
    
    session_factory = settings['leirirekkari.session_factory'][0](**settings)
    config.set_session_factory(session_factory)
    
    # Include modules listed in 'leirirekkari.base_includes':
    for module in settings['leirirekkari.base_includes']:
        config.include(module)
    config.commit()
    
    config.scan()

    return config
开发者ID:netblade,项目名称:saraste_leirirekkari,代码行数:49,代码来源:__init__.py

示例15: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_locale_negotiator [as 别名]
def main(_, **settings):
    config = Configurator(settings=settings)

    config.add_subscriber('rembish_org.subscribers.add_localizer', NewRequest)
    config.add_subscriber(
        'rembish_org.subscribers.add_renderer_globals', BeforeRender)
    config.add_subscriber('rembish_org.subscribers.save_locale', NewResponse)

    config.add_translation_dirs('rembish_org:locale')
    config.set_locale_negotiator(locale_negotiator)

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('cv', '/curriculum-vitae')
    config.scan()

    return config.make_wsgi_app()
开发者ID:rembish,项目名称:rembish-org-web,代码行数:19,代码来源:__init__.py


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