示例#1
0
def game_on_add(obj, evt):
    """ Handle add """
    try:
        addIntIdSubscriber(obj, evt)
        z3c_index(obj)
    except Exception, err:
        logger.exception(err)
示例#2
0
def indexLinks(event):
    iids = getUtility(IIntIds)
    for link in event.getLinks():
        link = removeSecurityProxy(link)
        addIntIdSubscriber(link, ObjectAddedEvent(link))
        lid = iids.getId(link)
        getLinkCatalog().index_doc(lid, link)
        link.__parent__._lids.add(lid)
示例#3
0
def indexLinks(event):
    iids = getUtility(IIntIds)
    for link in event.getLinks():
        link = removeSecurityProxy(link)
        addIntIdSubscriber(link, ObjectAddedEvent(link))
        lid = iids.getId(link)
        getLinkCatalog().index_doc(lid, link)
        link.__parent__._lids.add(lid)
示例#4
0
def getGroupContainer(sy):
    addIntIdSubscriber(sy, ObjectAddedEvent(sy))
    int_ids = getUtility(IIntIds)
    sy_id = str(int_ids.getId(sy))
    app = ISchoolToolApplication(None)
    gc = app['schooltool.group'].get(sy_id, None)
    if gc is None:
        gc = app['schooltool.group'][sy_id] = GroupContainer()
    return gc
示例#5
0
    def test_addIntIdSubscriber(self):
        from zope.lifecycleevent import ObjectAddedEvent
        from zope.intid import addIntIdSubscriber
        from zope.intid.interfaces import IIntIdAddedEvent
        from zope.site.interfaces import IFolder
        parent_folder = self.root['folder1']['folder1_1']
        folder = self.root['folder1']['folder1_1']['folder1_1_1']
        setSite(self.folder1_1)

        events = []
        objevents = []

        def appendObjectEvent(obj, event):
            objevents.append((obj, event))

        provideHandler(events.append, [IIntIdAddedEvent])
        provideHandler(appendObjectEvent, [IFolder, IIntIdAddedEvent])

        # Nothing happens for objects that can't be a keyreference
        addIntIdSubscriber(self, None)
        self.assertEqual([], events)


        # This should register the object in all utilities, not just the
        # nearest one.
        addIntIdSubscriber(folder, ObjectAddedEvent(parent_folder))

        # Check that the folder got registered
        id = self.utility.getId(folder)
        id1 = self.utility1.getId(folder)

        self.assertEqual(len(events), 1)
        self.assertEqual(events[0].original_event.object, parent_folder)
        self.assertEqual(events[0].object, folder)

        self.assertEqual(len(objevents), 1)
        self.assertEqual(objevents[0][1].original_event.object, parent_folder)
        self.assertEqual(objevents[0][1].object, folder)
        self.assertEqual(objevents[0][0], folder)

        idmap = events[0].idmap
        self.assertTrue(idmap is objevents[0][1].idmap)
        self.assertEqual(len(idmap), 2)
        self.assertEqual(idmap[self.utility], id)
        self.assertEqual(idmap[self.utility1], id1)
示例#6
0
    def test_addIntIdSubscriber(self):
        from zope.lifecycleevent import ObjectAddedEvent
        from zope.intid import addIntIdSubscriber
        from zope.intid.interfaces import IIntIdAddedEvent
        from zope.site.interfaces import IFolder
        parent_folder = self.root['folder1']['folder1_1']
        folder = self.root['folder1']['folder1_1']['folder1_1_1']
        setSite(self.folder1_1)

        events = []
        objevents = []

        def appendObjectEvent(obj, event):
            objevents.append((obj, event))

        provideHandler(events.append, [IIntIdAddedEvent])
        provideHandler(appendObjectEvent, [IFolder, IIntIdAddedEvent])

        # This should register the object in all utilities, not just the
        # nearest one.
        addIntIdSubscriber(folder, ObjectAddedEvent(parent_folder))

        # Check that the folder got registered
        id = self.utility.getId(folder)
        id1 = self.utility1.getId(folder)

        self.assertEquals(len(events), 1)
        self.assertEquals(events[0].original_event.object, parent_folder)
        self.assertEquals(events[0].object, folder)

        self.assertEquals(len(objevents), 1)
        self.assertEquals(objevents[0][1].original_event.object, parent_folder)
        self.assertEquals(objevents[0][1].object, folder)
        self.assertEquals(objevents[0][0], folder)

        idmap = events[0].idmap
        self.assert_(idmap is objevents[0][1].idmap)
        self.assertEquals(len(idmap), 2)
        self.assertEquals(idmap[self.utility], id)
        self.assertEquals(idmap[self.utility1], id1)