Пример #1
0
    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()
Пример #2
0
    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()
Пример #3
0
 def registerInTransaction(self, uid, action, doc={}):
     if not self.tdata.registered:
         self.tdata.register(self)
     conn = self.conn
     data = {
         'transaction_id': self.tdata.tid,
         'data': dumps(doc),
         'order': self.tdata.counter,
         'action': action,
         'uid': uid
     }
     conn.index(data, self.catalogsid, self.trns_catalogtype)
     self.tdata.counter += 1
Пример #4
0
 def registerInTransaction(self, uid, action, doc={}):
     if not self.tdata.registered:
         self.tdata.register(self)
     conn = self.conn
     data = {
         'transaction_id': self.tdata.tid,
         'data': dumps(doc),
         'order': self.tdata.counter,
         'action': action,
         'uid': uid
     }
     conn.index(data, self.catalogsid, self.trns_catalogtype)
     self.tdata.counter += 1