Пример #1
0
def addIntIdSubscriber(ob, event):
    """A subscriber to ObjectAddedEvent

    Registers the object added in all unique id utilities and fires
    an event for the catalogs.
    """
    factorytool = getToolByName(ob, 'portal_factory', None)
    if factorytool is not None and factorytool.isTemporary(ob):
        # Ignore objects marked as temporary in the CMFPlone portal_factory
        # tool
        return

    utilities = tuple(getAllUtilitiesRegisteredFor(IIntIds))
    if utilities:  # assert that there are any utilites
        key = None
        try:
            key = IKeyReference(ob, None)
        except NotYet:
            pass

        # Register only objects that adapt to key reference
        if key is not None:
            for utility in utilities:
                utility.register(key)
            # Notify the catalogs that this object was added.
            notify(IntIdAddedEvent(ob, event))
def addIntIdSubscriber(ob, event):
    """A subscriber to ObjectAddedEvent

    Registers the object added in all unique id utilities and fires
    an event for the catalogs.
    """
    utilities = tuple(zope.component.getAllUtilitiesRegisteredFor(IIntIds))
    if utilities:  # assert that there are any utilites
        idmap = {}
        for utility in utilities:
            idmap[utility] = utility.register(ob)
        # Notify the catalogs that this object was added.
        zope.event.notify(IntIdAddedEvent(ob, event, idmap))
Пример #3
0
def addIntIdSubscriber(ob, event):
    """A subscriber to ObjectAddedEvent

    Registers the object added in all unique id utilities and fires
    an event for the catalogs.
    """
    utilities = tuple(getAllUtilitiesRegisteredFor(IIntIds))
    if utilities:  # assert that there are any utilites
        key = IKeyReference(ob, None)
        # Register only objects that adapt to key reference
        if key is not None:
            idmap = {}
            for utility in utilities:
                idmap[utility] = utility.register(key)
            # Notify the catalogs that this object was added.
            notify(IntIdAddedEvent(ob, event, idmap))
Пример #4
0
def evolveLinks(connection, oids):
    int_ids = getSite()._sm.getUtility(IIntIds)

    states = {}
    for n, oid in enumerate(oids):
        try:
            link = connection.get(oid)
        except KeyError:
            continue
        links = link.__parent__._links
        if (link.__name__ not in links or links[link.__name__] is not link):
            # this is a record of a replaced link, skip.
            continue
        key = IKeyReference(link)
        idmap = {int_ids: int_ids.register(key)}

        this = link.__parent__.__parent__
        thishash = (
            hash(IKeyReference(this)),
            hash(link.my_role),
            hash(IKeyReference(link.target)),
            hash(link.role),
            hash(link.rel_type),
        )
        backhash = (
            hash(IKeyReference(link.target)),
            hash(link.role),
            hash(IKeyReference(this)),
            hash(link.my_role),
            hash(link.rel_type),
        )

        if backhash in states:
            link.shared = states[thishash] = states[backhash]
        else:
            assert thishash not in states
            states[thishash] = link.shared = OOBTree()
            link.shared['X'] = link.__dict__.get('extra_info')
        if 'extra_info' in link.__dict__:
            del link.__dict__['extra_info']
        if isinstance(link.rel_type, TemporalURIObject):
            link.shared['tmp'] = ()

        notify(IntIdAddedEvent(link, ObjectAddedEvent(link), idmap))

        if n % 10000 == 9999:
            transaction.savepoint(optimistic=True)
Пример #5
0
def handle_added_object(event):
    """Notify IntId utility for added objects

    This subscriber is used for all persistent objects to be registered
    in all locally registered IIntIds utilities.
    """
    utilities = tuple(get_all_utilities_registered_for(IIntIds))
    if utilities:
        # assert that there are any utilities
        try:
            key = IKeyReference(event.object, None)
        except NotYet:
            pass
        else:
            # Register only objects that adapt to key reference
            if key is not None:
                idmap = {}
                for utility in utilities:
                    idmap[utility] = utility.register(key)
                # Notify the catalogs that this object was added.
                get_current_registry().notify(
                    IntIdAddedEvent(event.object, event, idmap))