# Flon is a package for enabling hand picked Five features in Plone # Copyright (C) 2004 Enfold Systems, LLC # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # """ $Id: __init__.py,v 1.2 2004/07/14 22:23:16 dreamcatcher Exp $ """ from Acquisition import aq_inner, aq_parent from Products.ProxyIndex.ProxyIndex import ProxyIndex from Products.ZCatalog.Catalog import Catalog _marker = [] def updateProxyIndexMetadata(index, object, documentId): # What we do here is to try to find a metadata # element with the same name as the index, and if # found, update it with the indexed value. name = index.getId() catalog = aq_parent(aq_inner(index)) # Names is a tuple with the metadata names names = list(catalog.names) if not name in names: return value = index.getEntryForObject(documentId, default=_marker) if value is _marker: return # Data is a IOBTree where the key is the documentId # and the value is a tuple with the values for the # respective attributes. data = catalog.data idx = names.index(name) metadata = list(data[documentId]) # Only update if the value has changed. if metadata[idx] != value: metadata[idx] = value data[documentId] = tuple(metadata) def index_object(self, documentId, obj, threshold=None): res = self._flon_index_object(documentId, obj, threshold) updateProxyIndexMetadata(self, obj, documentId) return res def updateMetadata(self, obj, uid): idx = self._flon_updateMetadata(obj, uid) for name in self.indexes.keys(): x = self.getIndex(name) if isinstance(x, ProxyIndex): updateProxyIndexMetadata(x, obj, idx) return idx if not hasattr(ProxyIndex, '_flon_index_object'): ProxyIndex._flon_index_object = ProxyIndex.index_object ProxyIndex.index_object = index_object if not hasattr(Catalog, '_flon_updateMetadata'): Catalog._flon_updateMetadata = Catalog.updateMetadata Catalog.updateMetadata = updateMetadata