def test_IfIndexed(self): """ Test if an attribution is indexed at all.""" self.root['c'] = catable = Categorizable() attribution = interfaces.IAttribution(catable) attribution.attribute('cat21') zope.event.notify(ObjectModifiedEvent(catable)) from z3c.indexer.query import AnyOf from z3c.indexer.search import SearchQuery query = SearchQuery(AnyOf('attribution-set', ('cat21', ))) result = query.apply() self.assertTrue(len(result) == 1) attribution.unattribute('cat21') zope.event.notify(ObjectModifiedEvent(catable)) query = SearchQuery(AnyOf('attribution-set', ('cat21', ))) result = query.apply() self.assertTrue(len(result) == 0)
def findWorkItemsForItemAndProcessId(item, process_id): """ Returns workitems for 'item' 'process_id'.""" intids = zope.component.getUtility(IIntIds, context=getSite()) iid = intids.queryId(item, None) if not iid: return [] # maybe but we are not able to know oidsQuery = AnyOf('workflow-relevant-oids', [iid]) pidQuery = Eq('workitem-processid', process_id) query = SearchQuery(oidsQuery).And(pidQuery) return query.searchResults()
def values(self): intids = zope.component.getUtility(IIntIds, context=self.context) oid = intids.queryId(self.context) if oid: query = SearchQuery(AnyOf('workflow-relevant-oids', [oid])) res = query.apply() #raise Exception(res) for intid in res: yield intids.getObject(intid)
def test_IndexedUpToDateWhenCategoryMovedAndRenamed(self): """ Test if an attribution is indexed at all.""" self.root['c'] = catable = Categorizable() attribution = interfaces.IAttribution(catable) attribution.attribute('cat11') zope.event.notify(ObjectModifiedEvent(catable)) from zope.copypastemove.interfaces import IObjectMover mover = IObjectMover(self.categories['set1']['cat11']) mover.moveTo(self.categories['set2'], new_name='moved') zope.event.notify(ObjectModifiedEvent(catable)) from z3c.indexer.query import AnyOf from z3c.indexer.search import SearchQuery query = SearchQuery(AnyOf('attribution-set', ('cat22', ))) result = query.apply() self.assertTrue(len(result) == 0) query = SearchQuery(AnyOf('attribution-set', ('moved', ))) result = query.apply() self.assertTrue(len(result) == 1)
def test_IfIndexed(self): from zope.intid.interfaces import IIntIds intids = zope.component.getUtility(IIntIds, context=self.root) iid = intids.register(self.item) self.startWorkflow() from z3c.indexer.query import AnyOf from z3c.indexer.search import SearchQuery query = SearchQuery(AnyOf('workflow-relevant-oids', iid)) res = query.apply() self.assertTrue(len(res) == 1)
def removeAttributionSubscriber(category, event): """ Remove attributions if a category is removed.""" intids = zope.component.getUtility(IIntIds, context=category) container = zope.component.getUtility(interfaces.ICategoriesContainer, context=category) query = SearchQuery(AnyOf(ATTRIBUTION_INDEX, (category.__name__, ))) result = query.apply() for intid in result: categorizable = intids.getObject(intid) attribution = interfaces.IAttribution(categorizable) attribution.unattribute(category.__name__)
def test_IndexedUpToDateWhenCategoryRemoved(self): """ Test if an attribution is indexed at all.""" self.root['c'] = catable = Categorizable() attribution = interfaces.IAttribution(catable) attribution.attribute('cat22') del self.categories['set2']['cat22'] from z3c.indexer.query import AnyOf from z3c.indexer.search import SearchQuery query = SearchQuery(AnyOf('attribution-set', ('cat22', ))) result = query.apply() self.assertTrue(len(result) == 0)
def moveAttributionSubscriber(category, event): """ Keep an attribution up to date if a category is renamed.""" if event.oldName and event.newName: intids = zope.component.getUtility(IIntIds, context=category) container = zope.component.getUtility(interfaces.ICategoriesContainer, context=category) query = SearchQuery(AnyOf(ATTRIBUTION_INDEX, (event.oldName, ))) result = query.apply() for intid in result: categorizable = intids.getObject(intid) attribution = interfaces.IAttribution(categorizable) attribution.unattribute(event.oldName) attribution.attribute(event.newName)
def getSimilarWorkItems(self): """ See ISimilarWorkItems""" ids = [] intids = zope.component.getUtility(IIntIds, context=self.context) for obj in self.objects: intid = intids.queryId(obj, None) if intid is not None: ids.append(intid) #raise Exception(ids) query = SearchQuery(AnyOf('workflow-relevant-oids', ids)) res = query.apply() #raise Exception(res) for intid in res: if intid != intids.getId(self.context): #raise Exception(intid) yield intids.getObject(intid)
def values(self): principal_id = self.request.principal.id contributorQuery = AnyOf('workitem-contributors', (principal_id, )) worklistQuery = Eq('worklist-value', 'contributor') query = SearchQuery(contributorQuery).And(worklistQuery) return query.searchResults()