def test_has_right_brain_data(self): current_length = len(self.catalog._catalog.uids) obj = createObject(self.portal, 'Event', 'event', title='Some Event') self.assertEqual(current_length + 1, len(self.catalog._catalog.uids)) self.assertEqual(self.get_hook().index, {getUID(obj): obj}) self.portal.manage_delObjects(['event']) self.assertEqual(current_length, len(self.catalog._catalog.uids)) self.assertEqual(self.get_hook().remove, {getUID(obj)}) self.assertEqual(self.get_hook().index, {})
def index_positions(obj, ids): hook = getHook() if ISiteRoot.providedBy(obj): hook.positions['/'] = ids else: uid = getUID(obj) if uid is None: logger.error("Tried to index an object of None uid") return hook.positions[getUID(obj)] = ids
def index_positions(obj, ids): hook = getHook() if ISiteRoot.providedBy(obj): hook.positions['/'] = ids else: uid = getUID(obj) if uid is None: logger.error("Tried to index an object of None uid") return hook.positions[getUID(obj)] = ids
def test_has_right_brain_data(self): current_length = len(self.catalog._catalog.uids) obj = createObject(self.portal, 'Event', 'event', title='Some Event') self.assertEqual(current_length + 1, len(self.catalog._catalog.uids)) self.assertEqual(self.get_hook().index, {getUID(obj): obj}) self.portal.manage_delObjects(['event']) # uid not actually removed until this if catalog optimized processQueue() self.assertEqual(current_length, len(self.catalog._catalog.uids)) self.assertEqual(self.get_hook().remove, {getUID(obj)}) self.assertEqual(self.get_hook().index, {})
def test_rename_object(self): current_length = len(self.catalog._catalog.uids) obj = createObject(self.portal, 'Event', 'event1', title='Some Event') obj_uid = getUID(obj) self.assertEqual(current_length + 1, len(self.catalog._catalog.uids)) api.content.rename(self.portal.event1, new_id='event2') self.assertEqual(self.get_hook().remove, set()) self.assertEqual(self.get_hook().index, {obj_uid: obj})
def catalog_object(self, obj, uid=None, idxs=[], update_metadata=1, pghandler=None): mode = self.mode if mode in (DISABLE_MODE, DUAL_MODE): result = self.patched.catalog_object(obj, uid, idxs, update_metadata, pghandler) if mode == DISABLE_MODE: return result wrapped_object = None if not IIndexableObject.providedBy(obj): # This is the CMF 2.2 compatible approach, which should be used # going forward wrapper = queryMultiAdapter((obj, self.catalogtool), IIndexableObject) if wrapper is not None: wrapped_object = wrapper else: wrapped_object = obj else: wrapped_object = obj conn = self.conn catalog = self.catalog if idxs == []: idxs = catalog.indexes.keys() index_data = {} for index_name in idxs: index = getIndex(catalog, index_name) if index is not None: value = index.get_value(wrapped_object) if value in (None, 'None'): # yes, we'll index null data... value = None index_data[index_name] = value if update_metadata: metadata = {} for meta_name in catalog.names: attr = getattr(wrapped_object, meta_name, MV) if (attr is not MV and safe_callable(attr)): attr = attr() metadata[meta_name] = attr # XXX Also, always index path so we can use it with the brain # to make urls metadata['_path'] = wrapped_object.getPhysicalPath() index_data['_metadata'] = dumps(metadata) uid = getUID(obj) try: doc = conn.get(self.catalogsid, self.catalogtype, uid) self.registerInTransaction(uid, td.Actions.modify, doc) except NotFoundException: self.registerInTransaction(uid, td.Actions.add) conn.index(index_data, self.catalogsid, self.catalogtype, uid) if self.registry.auto_flush: conn.refresh()
def test_delete_object(self): obj = createObject(self.portal, 'Event', 'event_to_delete', title='Some Event') obj_uid = getUID(obj) self.portal.manage_delObjects(['event_to_delete']) self.assertEqual(self.get_hook().index, {}) self.assertEqual(self.get_hook().remove, {obj_uid})
def add_object(es, obj): hook = getHook(es) uid = getUID(obj) if uid is None: logger.error("Tried to index an object of None uid") return hook.index[uid] = obj if uid in hook.remove: hook.remove.remove(uid)
def add_object(es, obj): hook = getHook(es) uid = getUID(obj) if uid is None: logger.error("Tried to index an object of None uid") return hook.index[uid] = obj if uid in hook.remove: hook.remove.remove(uid)
def remove_object(es, obj): hook = getHook(es) uid = getUID(obj) if uid is None: logger.error("Tried to unindex an object of None uid") return hook.remove.add(uid) if uid in hook.index: del hook.index[uid]
def remove_object(es, obj): hook = getHook(es) uid = getUID(obj) if uid is None: logger.error("Tried to unindex an object of None uid") return hook.remove.add(uid) if uid in hook.index: del hook.index[uid]
def catalog_object(self, obj, uid=None, idxs=[], update_metadata=1, pghandler=None): mode = self.mode if mode in (DISABLE_MODE, DUAL_MODE): result = self.patched.catalog_object( obj, uid, idxs, update_metadata, pghandler) if mode == DISABLE_MODE: return result wrapped_object = None if not IIndexableObject.providedBy(obj): # This is the CMF 2.2 compatible approach, which should be used # going forward wrapper = queryMultiAdapter((obj, self.catalogtool), IIndexableObject) if wrapper is not None: wrapped_object = wrapper else: wrapped_object = obj else: wrapped_object = obj conn = self.conn catalog = self.catalog if idxs == []: idxs = catalog.indexes.keys() index_data = {} for index_name in idxs: index = getIndex(catalog, index_name) if index is not None: value = index.get_value(wrapped_object) if value in (None, 'None'): # yes, we'll index null data... value = None index_data[index_name] = value if update_metadata: metadata = {} for meta_name in catalog.names: attr = getattr(wrapped_object, meta_name, MV) if (attr is not MV and safe_callable(attr)): attr = attr() metadata[meta_name] = attr # XXX Also, always index path so we can use it with the brain # to make urls metadata['_path'] = wrapped_object.getPhysicalPath() index_data['_metadata'] = dumps(metadata) uid = getUID(obj) try: doc = conn.get(self.catalogsid, self.catalogtype, uid) self.registerInTransaction(uid, td.Actions.modify, doc) except NotFoundException: self.registerInTransaction(uid, td.Actions.add) conn.index(index_data, self.catalogsid, self.catalogtype, uid) if self.registry.auto_flush: conn.refresh()
def uncatalog_object(self, uid, obj=None, *args, **kwargs): mode = self.mode if mode in (DISABLE_MODE, DUAL_MODE): if self.catalog.uids.get(uid, None) is not None: result = self.patched.uncatalog_object(uid, *args, **kwargs) if mode == DISABLE_MODE: return result conn = self.conn uid = getUID(obj) try: doc = conn.get(self.catalogsid, self.catalogtype, uid) self.registerInTransaction(uid, td.Actions.delete, doc) except NotFoundException: pass try: conn.delete(self.catalogsid, self.catalogtype, uid) except NotFoundException: # already gone... Multiple calls? pass if self.registry.auto_flush: conn.refresh()
def uncatalog_object(self, uid, obj=None, *args, **kwargs): mode = self.mode if mode in (DISABLE_MODE, DUAL_MODE): if self.catalog.uids.get(uid, None) is not None: result = self.patched.uncatalog_object(uid, *args, **kwargs) if mode == DISABLE_MODE: return result conn = self.conn uid = getUID(obj) try: doc = conn.get(self.catalogsid, self.catalogtype, uid) self.registerInTransaction(uid, td.Actions.delete, doc) except NotFoundException: pass try: conn.delete(self.catalogsid, self.catalogtype, uid) except NotFoundException: # already gone... Multiple calls? pass if self.registry.auto_flush: conn.refresh()
def index_positions(obj, ids): hook = getHook() if ISiteRoot.providedBy(obj): hook.positions['/'] = ids else: hook.positions[getUID(obj)] = ids
def remove_object(es, obj): hook = getHook(es) uid = getUID(obj) hook.remove.append(uid) if uid in hook.index: del hook.index[uid]
def add_object(es, obj): hook = getHook(es) hook.index[getUID(obj)] = obj
def index_positions(obj, ids): hook = getHook() if ISiteRoot.providedBy(obj): hook.positions['/'] = ids else: hook.positions[getUID(obj)] = ids
def remove_object(es, obj): hook = getHook(es) uid = getUID(obj) hook.remove.append(uid) if uid in hook.index: del hook.index[uid]
def add_object(es, obj): hook = getHook(es) hook.index[getUID(obj)] = obj