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


Python DBSession.configure方法代码示例

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


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

示例1: main

# 需要导入模块: from lmkp.models.meta import DBSession [as 别名]
# 或者: from lmkp.models.meta.DBSession import configure [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """

    # Used when called through Tests
    if "settings" in settings:
        settings = settings["settings"]

    engine = engine_from_config(settings, "sqlalchemy.")
    DBSession.configure(bind=engine)

    # Transform the list of valid file mime extensions from the ini file into a
    # python dict.
    # http://pyramid.readthedocs.org/en/latest/narr/environment.html#adding-a-
    # custom-setting
    file_mime_extensions = {}
    for fme in aslist(settings.get("lmkp.file_mime_extensions", {}), False):
        fme_entry = fme.split(" ")
        if len(fme_entry) != 2:
            continue
        file_mime_extensions[fme_entry[0]] = fme_entry[1]
    settings["lmkp.file_mime_extensions"] = file_mime_extensions

    _update_admin_user(DBSession, settings)

    # Customization: Determine the name of the customization
    customization = get_customization_name(settings=settings)

    # Authentication policy
    authnPolicy = CustomAuthenticationPolicy("9ZbfPv Ez-eV8LeTJVNjUhQf FXWBBi_cWKn2fqnpz3PA", callback=group_finder)
    # Authorization policy
    authzPolicy = ACLAuthorizationPolicy()

    session_factory = session_factory_from_settings(settings)

    config = Configurator(
        settings=settings, root_factory="lmkp.models.rootfactory.RootFactory", session_factory=session_factory
    )
    config.set_authentication_policy(authnPolicy)
    config.set_authorization_policy(authzPolicy)

    config.include("pyramid_beaker")

    config.include("pyramid_mako")
    config.include("pyramid_chameleon")

    # Add the directories that include the translations, also include the
    # translation directory for the customization
    config.add_translation_dirs("lmkp:locale/", "colander:locale/", "deform:locale/")
    if customization is not None:
        config.add_translation_dirs("customization/%s/locale/" % customization)

    # Add event subscribers
    config.add_subscriber(add_renderer_globals, BeforeRender)
    config.add_subscriber(add_localizer, NewRequest)

    config.add_subscriber(add_user, NewRequest)

    config.include("pyramid_mailer")

    # Add papyrus includes
    config.include(papyrus.includeme)
    config.include("pyramid_handlers")

    # Renderers
    config.add_renderer("geojson", GeoJsonRenderer())
    config.add_renderer("csv", CSVRenderer())
    config.add_renderer("json", JsonRenderer())
    config.add_renderer("javascript", JavaScriptRenderer())

    # Static views
    config.add_static_view("static", "static", cache_max_age=3600)
    config.add_static_view("formstatic", "deform:static")

    # Customization: Add the static customization folder as view
    if customization is not None:
        config.add_static_view("custom", "customization/%s/static" % customization, cache_max_age=3600)

    # Main views
    config.add_route("index", "/")
    config.add_route("administration", "/administration")
    config.add_route("map_view", "/map")
    config.add_route("grid_view", "/grid")
    config.add_route("about_view", "/about")
    config.add_route("faq_view", "/faq")
    config.add_route("showcases_view", "/showcases")
    config.add_route("partners_view", "/partners")

    # Login / Logout
    config.add_route("login", "/login", request_method="POST")
    config.add_route("login_json", "/login/json", request_method="POST")
    config.add_route("login_form", "/login", request_method="GET")
    config.add_route("reset", "/reset", request_method="POST")
    config.add_route("reset_form", "/reset", request_method="GET")
    config.add_route("logout", "/logout")

    # Translation
    config.add_route("yaml_translate_activities", "/config/scan/activities")
    config.add_route("yaml_add_activity_fields", "/config/add/activities")
    config.add_route("yaml_translate_stakeholders", "/config/scan/stakeholders")
#.........这里部分代码省略.........
开发者ID:CDE-UNIBE,项目名称:lokp,代码行数:103,代码来源:__init__.py

示例2: main

# 需要导入模块: from lmkp.models.meta import DBSession [as 别名]
# 或者: from lmkp.models.meta.DBSession import configure [as 别名]
def main(global_config, ** settings):
    """ This function returns a Pyramid WSGI application.
    """
    
    # Used when called through Tests
    if 'settings' in settings:
        settings = settings['settings']
        
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    
    # Transform the list of valid file mime extensions from the ini file into a
    # python dict.
    # http://pyramid.readthedocs.org/en/latest/narr/environment.html#adding-a-custom-setting
    file_mime_extensions = {}
    for fme in aslist(settings.get('lmkp.file_mime_extensions', {}), False):
        fme_entry = fme.split(' ')
        if len(fme_entry) != 2:
            continue
        file_mime_extensions[fme_entry[0]] = fme_entry[1]
    settings['lmkp.file_mime_extensions'] = file_mime_extensions

    _update_admin_user(DBSession, settings)

    # Customization: Determine the name of the customization
    customization = getCustomizationName(settings)

    # Authentication policy
    authnPolicy = CustomAuthenticationPolicy('9ZbfPv Ez-eV8LeTJVNjUhQf FXWBBi_cWKn2fqnpz3PA', callback=group_finder)
    # Authorization policy
    authzPolicy = ACLAuthorizationPolicy()

    session_factory = session_factory_from_settings(settings)

    config = Configurator(settings=settings,
                          root_factory='lmkp.models.rootfactory.RootFactory',
                          session_factory=session_factory)
    config.set_authentication_policy(authnPolicy)
    config.set_authorization_policy(authzPolicy)

    config.include('pyramid_beaker')

    # Add the directories that include the translations, also include the
    # translation directory for the customization
    config.add_translation_dirs(
        'lmkp:locale/',
        'colander:locale/',
        'deform:locale/'
    )
    if customization is not None:
        config.add_translation_dirs(
            'customization/%s/locale/' % customization
        )

    # Add event subscribers
    config.add_subscriber(add_renderer_globals, BeforeRender)
    config.add_subscriber(add_localizer, NewRequest)

    config.add_subscriber(add_user, NewRequest)

    config.include('pyramid_mailer')

    # Add papyrus includes
    config.include(papyrus.includeme)
    config.include('pyramid_handlers')
    # Return a JavaScript model
    #config.add_route('taggroups_model', 'static/app/model/TagGroup.js')
    #config.add_renderer('geojson', GeoJSON())
    config.add_renderer('geojson', GeoJsonRenderer())
    config.add_renderer('csv', CSVRenderer())
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('formstatic', 'deform:static')

    # Customization: Add the static customization folder as view
    if customization is not None:
        config.add_static_view('custom', 'customization/%s/static' %
            customization, cache_max_age=3600)

    config.add_route('index', '/')
    config.add_route('administration', '/administration')
    config.add_route('login', '/login', request_method='POST')
    config.add_route('login_form', '/login', request_method='GET')
    config.add_route('reset', '/reset', request_method='POST')
    config.add_route('reset_form', '/reset', request_method='GET')
    config.add_route('logout', '/logout')

    config.add_route('translation', '/translation')

    # Embedded start page
    config.add_route('embedded_index', '/embedded/{profile}')
    config.add_route('enclosing_demo_site', '/enclosing_demo_site')

    # Returns configuration parameters as JSON objects
    config.add_route('yaml_translate_activities', '/config/scan/activities')
    config.add_route('yaml_add_activity_fields', '/config/add/activities')

    config.add_route('yaml_translate_stakeholders', '/config/scan/stakeholders')
    config.add_route('yaml_add_stakeholder_fields', '/config/add/stakeholders')

    config.add_route('config', '/config/form/{parameter}')
#.........这里部分代码省略.........
开发者ID:sinnwerkstatt,项目名称:lokp,代码行数:103,代码来源:__init__.py


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