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


Python events.subscriber方法代码示例

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


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

示例1: init_application

# 需要导入模块: from pyramid import events [as 别名]
# 或者: from pyramid.events import subscriber [as 别名]
def init_application(event):
    app = event.object
    registry = app.registry
    request = Request.blank('/application_created') # path is meaningless
    request.registry = registry
    manager.push({'registry': registry, 'request': request})
    # Set up sms service backend
    registry.registerAdapter(
        factory=OvhService,
        required=(IRequest,),
        provided=ISMSService)
    root = app.root_factory(request)
    # A transaction.commit() just happened here if this is the first time we
    # start. This is just after all RootAdded subscribers are executed.
    request.root = root
    # other init functions
    if getattr(root, 'locale', None) is None:
        try:
            # This code is actually an evolve step for old novaideo instances.
            # The root.locale is set in the RootAdded subscriber above
            # for new instances.
            root.locale = registry.settings.get('pyramid.default_locale_name')
            transaction.commit()
        except ConflictError:
            # We have a conflict error in case of serveral workers, just abort
            transaction.abort()

    init_contents(registry)  # there is no changes in ZODB here
    # invite initial user if first deployment
    if getattr(root, 'first_invitation_to_add', False):
        # LOGO_FILENAME='marianne.svg' for example
        logo = os.getenv('LOGO_FILENAME', '')
        if logo:
            logo_path = os.path.join(
                os.path.dirname(__file__), 'static', 'images', logo)
            if os.path.exists(logo_path):
                buf = open(logo_path, mode='rb')
                log_file = File(
                    fp=buf, filename=logo, mimetype='image/svg+xml')
                root.setproperty('picture', log_file)

        title = os.getenv('INITIAL_USER_TITLE', '')
        first_name = os.getenv('INITIAL_USER_FIRSTNAME', '')
        last_name = os.getenv('INITIAL_USER_LASTNAME', '')
        email = os.getenv('INITIAL_USER_EMAIL', '')
        phone = os.getenv('INITIAL_USER_PHONE', '')
        if first_name and last_name and (phone or email):
            _invite_first_user(
                root, request, title,
                first_name, last_name, email, phone)

        del root.first_invitation_to_add
        # This is a change in ZODB, but it's ok, it is executed only the first
        # time when we only have one worker.

    transaction.commit()
    manager.pop() 
开发者ID:ecreall,项目名称:nova-ideo,代码行数:59,代码来源:subscribers.py


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