當前位置: 首頁>>代碼示例>>Python>>正文


Python interfaces.IObjectWillBeAddedEvent類代碼示例

本文整理匯總了Python中OFS.interfaces.IObjectWillBeAddedEvent的典型用法代碼示例。如果您正苦於以下問題:Python IObjectWillBeAddedEvent類的具體用法?Python IObjectWillBeAddedEvent怎麽用?Python IObjectWillBeAddedEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了IObjectWillBeAddedEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: remove_ghosts

def remove_ghosts(obj, event):
    """We are going to remove a object: we need to check if its neutral
       and remove their indexes also.
    """
    if not IObjectWillBeAddedEvent.providedBy(event) \
       and (IObjectWillBeMovedEvent.providedBy(event)
            or IObjectWillBeRemovedEvent.providedBy(event)):
        if not is_shared_original(obj):
            return

        content_id = IUUID(obj).split('-')[0]
        site = getSite()
        try:
            pc = getToolByName(site, 'portal_catalog')
        except AttributeError:
            # In case we are removing the site there is no portal_catalog
            return
        language_tool = getToolByName(site, 'portal_languages')
        language_infos = language_tool.supported_langs

        for language_info in language_infos:
            brains = pc.unrestrictedSearchResults(
                UID=content_id + '-' + language_info)
            for brain in brains:
                obj.unrestrictedTraverse(brain.getPath()).unindexObject()
            brains = pc.unrestrictedSearchResults(
                UID=content_id)
            for brain in brains:
                obj.unrestrictedTraverse(brain.getPath()).unindexObject()
    if IActionSucceededEvent.providedBy(event):
        reindex_neutral(obj, event)
開發者ID:quintagroup,項目名稱:plone.app.multilingual,代碼行數:31,代碼來源:subscriber.py

示例2: onTreeSpanningComponentBeforeDelete

def onTreeSpanningComponentBeforeDelete(ob, event):
    """
    When a component that links a device to another tree is going to
    be removed, update the device's paths.
    """
    if not IObjectWillBeAddedEvent.providedBy(event):
        component = ob
        try:
            catalog = ob.getPhysicalRoot().zport.global_catalog
        except (KeyError, AttributeError):
            # Migrate script hasn't run yet; ignore indexing
            return
        device = component.device()
        if not device:
            # OS relation has already been broken; get by path
            path = component.getPrimaryPath()
            try:
                devpath = path[:path.index('devices')+2]
                device = component.unrestrictedTraverse(devpath)
            except ValueError:
                # We've done our best. Give up.
                return
        if device:
            oldpaths = devicePathsFromComponent(component)
            catalog.unindex_object_from_paths(device, oldpaths)
開發者ID:SteelHouseLabs,項目名稱:zenoss-prodbin,代碼行數:25,代碼來源:events.py

示例3: onDeviceDeleted

def onDeviceDeleted(object, event):
    # Clean up any AMQP queues we may have created for this device.

    if not IObjectWillBeAddedEvent.providedBy(event):
        connectionInfo = getUtility(IAMQPConnectionInfo)
        queueSchema = getUtility(IQueueSchema)

        # For some reason, if an error gets thrown by queue_delete, it seems
        # to break the connection, so we'll just use a separate connection
        # for each call to it.
        for queue in ('$OpenStackInboundEvent', '$OpenStackInboundPerf'):
            queueName = substitute_replacements(queueSchema._queue_nodes[queue].name,
                                                {'device': object.id})

            amqpClient = BlockingPublisher(connectionInfo, queueSchema)
            channel = amqpClient.getChannel()
            try:
                LOG.debug("Removing AMQP queue %s" % queueName)
                channel.queue_delete(queueName)
                LOG.info("Removed AMQP queue %s successfully." % queueName)
            except AMQPChannelException, e:
                # if the queue doesn't exist, don't worry about it.
                if e.amqp_reply_code == 404:
                    LOG.debug('Queue %s did not exist', queueName)
                else:
                    LOG.exception(e)

            amqpClient.close()
開發者ID:zenoss,項目名稱:ZenPacks.zenoss.OpenStackInfrastructure,代碼行數:28,代碼來源:Endpoint.py

示例4: handle_topic_deletion

def handle_topic_deletion(ob, event):
    """The ForumTopic will be moved/removed"""
    if not IObjectWillBeAddedEvent.providedBy(event):
        # Object will be removed:
        # Same as above. If the topic is deleted by mistake the statistics
        #should still be there in case of undo.
        #ob.aq_inner.aq_parent.removeTopicHits(ob.id)
        pass
開發者ID:eaudeweb,項目名稱:naaya.Products.NaayaForum,代碼行數:8,代碼來源:subscribers.py

示例5: onOrganizerBeforeDelete

def onOrganizerBeforeDelete(ob, event):
    """
    Before we delete the organizer we need to remove its references
    to the devices. 
    """
    if not IObjectWillBeAddedEvent.providedBy(event):
        for device in ob.devices.objectValuesGen():
            notify(IndexingEvent(device, idxs='path', triggered_by_zope_event=True))
開發者ID:zenoss,項目名稱:zenoss-prodbin,代碼行數:8,代碼來源:events.py

示例6: content_removed

def content_removed(content, event):
    if (event.object != content or
        IObjectWillBeAddedEvent.providedBy(event) or
        event.newParent == event.oldParent):
        return
    if IOrderableContainer.providedBy(event.oldParent):
        manager = IOrderManager(event.oldParent)
        manager.remove(content)
開發者ID:silvacms,項目名稱:Products.Silva,代碼行數:8,代碼來源:order.py

示例7: onObjectRemoved

def onObjectRemoved(ob, event):
    """
    Unindex, please.
    """
    if not IObjectWillBeAddedEvent.providedBy(event):
        object_to_unindex = _get_object_to_index(ob)
        if object_to_unindex:
            getUtility(IModelCatalog).uncatalog_object(object_to_unindex)
開發者ID:zenoss,項目名稱:zenoss-prodbin,代碼行數:8,代碼來源:events.py

示例8: onInterfaceRemoved

def onInterfaceRemoved(ob, event):
    """
    Unindex
    """

    if not IObjectWillBeAddedEvent.providedBy(event):
        macs = ob.device().getMacAddressCache()
        if ob.macaddress in macs:
            macs.remove(ob.macaddress)
開發者ID:ssbunyk,項目名稱:zenoss-prodbin,代碼行數:9,代碼來源:subscribers.py

示例9: unindexBeforeDelete

def unindexBeforeDelete(ob, event):
    """
    Multisubscriber for IIndexed + IObjectWillBeMovedEvent
    """
    if not IObjectWillBeAddedEvent.providedBy(event):
        if isinstance(ob, IpInterface):
            beforeDeleteIpInterface(ob, event)
        else:
            ob.unindex_object()
開發者ID:ssbunyk,項目名稱:zenoss-prodbin,代碼行數:9,代碼來源:subscribers.py

示例10: handle_forum_deletion

def handle_forum_deletion(ob, event):
    """The Forum will be moved/removed"""
    if not IObjectWillBeAddedEvent.providedBy(event):
        # Object will be removed:

        #Statistics db should  not be removed.
        #If forum is undeleted then the statistics should still be there.
        #ob._removeStatisticsContainer()
        pass
開發者ID:eaudeweb,項目名稱:naaya.Products.NaayaForum,代碼行數:9,代碼來源:subscribers.py

示例11: related_change_on_moving

def related_change_on_moving(obj, event):
    """ Set local roles on related objects before moving """
    if IObjectWillBeAddedEvent.providedBy(event) or IObjectWillBeRemovedEvent.providedBy(event):  # not move
        return
    if event.oldParent and event.newParent and event.oldParent == event.newParent:  # rename
        return
    (fti_config, fti) = fti_configuration(obj)
    if 'static_config' not in fti_config:
        return
    related_role_removal(obj, get_state(obj), fti_config)
開發者ID:collective,項目名稱:dexterity.localroles,代碼行數:10,代碼來源:subscriber.py

示例12: test_events

    def test_events(self):
        from OFS.interfaces import IObjectWillBeAddedEvent
        from zope.component import adapter
        from zope.component import provideHandler
        from zope.container.interfaces import IContainerModifiedEvent
        from zope.container.interfaces import IObjectAddedEvent
        from zope.lifecycleevent.interfaces import IObjectCreatedEvent
        events = []

        @adapter(IObjectCreatedEvent)
        def _handleObjectCreated(event):
            events.append(event)
        provideHandler(_handleObjectCreated)

        @adapter(IObjectWillBeAddedEvent)
        def _handleObjectWillBeAdded(event):
            events.append(event)
        provideHandler(_handleObjectWillBeAdded)

        @adapter(IObjectAddedEvent)
        def _handleObjectAdded(event):
            events.append(event)
        provideHandler(_handleObjectAdded)

        @adapter(IContainerModifiedEvent)
        def _handleContainerModified(event):
            events.append(event)
        provideHandler(_handleContainerModified)

        self.ti.constructInstance(self.f, 'foo')
        self.assertEquals(len(events), 4)

        evt = events[0]
        self.failUnless(IObjectCreatedEvent.providedBy(evt))
        self.assertEquals(evt.object, self.f.foo)

        evt = events[1]
        self.failUnless(IObjectWillBeAddedEvent.providedBy(evt))
        self.assertEquals(evt.object, self.f.foo)
        self.assertEquals(evt.oldParent, None)
        self.assertEquals(evt.oldName, None)
        self.assertEquals(evt.newParent, self.f)
        self.assertEquals(evt.newName, 'foo')

        evt = events[2]
        self.failUnless(IObjectAddedEvent.providedBy(evt))
        self.assertEquals(evt.object, self.f.foo)
        self.assertEquals(evt.oldParent, None)
        self.assertEquals(evt.oldName, None)
        self.assertEquals(evt.newParent, self.f)
        self.assertEquals(evt.newName, 'foo')

        evt = events[3]
        self.failUnless(IContainerModifiedEvent.providedBy(evt))
        self.assertEquals(evt.object, self.f)
開發者ID:goschtl,項目名稱:zope,代碼行數:55,代碼來源:test_TypesTool.py

示例13: onComponentRemoved

def onComponentRemoved(ob, event):
    if not IObjectWillBeAddedEvent.providedBy(event):
        spec = get_component_field_spec(ob.meta_type)
        if spec is None:
            return
        catalog = spec.get_catalog(ob, ob.meta_type)
        uid = '/'.join(ob.getPrimaryPath())
        if catalog.getrid(uid) is None:
            # Avoid "tried to uncatalog nonexistent object" warnings
            return
        catalog.uncatalog_object(uid)
開發者ID:zenoss,項目名稱:zenoss-prodbin,代碼行數:11,代碼來源:component_catalog.py

示例14: onDeviceDeleted

def onDeviceDeleted(object, event):
    '''
    Clean up the dangling reference to a device if that device has been removed.
    (Note: we may re-create the device automatically next time someone calls
    self.ensure_proxy_device, though)
    '''
    if not IObjectWillBeAddedEvent.providedBy(event) and not IObjectWillBeMovedEvent.providedBy(event):
        if hasattr(object, 'openstackProxyComponentUUID'):
            component = GUIDManager(object.dmd).getObject(getattr(object, 'openstackProxyComponentUUID', None))
            if component:
                component.release_proxy_device()
            object.openstackProxyComponentUUID = None
開發者ID:zenoss,項目名稱:ZenPacks.zenoss.OpenStackInfrastructure,代碼行數:12,代碼來源:DeviceProxyComponent.py

示例15: related_change_on_moving

def related_change_on_moving(obj, event):
    """ Set local roles on related objects before moving """
    if IObjectWillBeAddedEvent.providedBy(event) or IObjectWillBeRemovedEvent.providedBy(event):  # not move
        return
    if event.oldParent and event.newParent and event.oldParent == event.newParent:  # rename
        return
    (fti_config, fti) = fti_configuration(obj)
    if not fti_config:
        return
    for (name, f) in get_localrole_fields(fti):
        if name not in fti_config:
            continue
        related_role_removal(obj, get_state(obj), fti_config[name], name)
開發者ID:collective,項目名稱:dexterity.localrolesfield,代碼行數:13,代碼來源:subscriber.py


注:本文中的OFS.interfaces.IObjectWillBeAddedEvent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。