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