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 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 _cleanup(self, **kwargs): """ Cleanup thumbs """ index = 0 now = datetime.now(bucharest) logger.info('cleanup old images started ...') geQuery = Le('stiam.ro.effective', now) query = SearchQuery(geQuery) brains = query.apply() intids = queryUtility(IIntIds) if not intids: logger.warn('No intids utility. Cleanup aborted.') return index for docid in brains: try: doc = intids.getObject(docid) except KeyError, err: logger.exception(err) continue for image in doc.values(): if not IImage.providedBy(image): continue if IBlobImage.providedBy(image): continue try: del doc[image.__name__] except Exception, err: logger.exception(err) continue index += 1 # Transaction commit if index % 20 == 0: logger.info('Commit transaction %s', index) transaction.commit()