From 558758391ea0565e9a8c1adcf22e3ed38eb13c39 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Benoi=CC=82t=20Pin?= Date: Wed, 13 Aug 2014 18:01:47 +0200 Subject: [PATCH 1/1] =?utf8?q?Autre=20approche=20pour=20la=20surcharge?= =?utf8?q?=C2=A0:=20on=20surcharge=20=C2=AB=C2=A0catalog=5Fobject=C2=A0?= =?utf8?q?=C2=BB,=20une=20m=C3=A9thode=20plus=20basse=20de=20l'API.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- catalog.py | 69 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/catalog.py b/catalog.py index f2736cb..69bb701 100644 --- a/catalog.py +++ b/catalog.py @@ -74,17 +74,10 @@ class CatalogTool(BaseCatalogTool) : return getattr(self, _VOLATILE_SOLR_NAME) security.declarePrivate('solrAdd') - def solrAdd(self, object, idxs=[], uid=None) : - if IIndexableObject.providedBy(object): - w = object - else: - w = queryMultiAdapter( (object, self), IIndexableObject ) - if w is None: - # BBB - w = IndexableObjectWrapper(object, self) - - uid = uid if uid else self.__url(object) - idxs = idxs if idxs !=[] else self.delegatedIndexes + def solrAdd(self, w, uid, idxs) : + idxs = idxs if idxs else self.delegatedIndexes + # Filter out delegated indexes + idxs = [i for i in idxs if i in self.delegatedIndexes] data = {'id' : uid} for name in idxs : attr = getattr(w, name, '') @@ -92,29 +85,45 @@ class CatalogTool(BaseCatalogTool) : c = self._getSolrConnection() c.add(**data) - # PortalCatalog api overloads - security.declareProtected(ModifyPortalContent, 'indexObject') - def indexObject(self, object) : - """ Add to catalog and send to Solr """ - super(CatalogTool, self).indexObject(object) - self.solrAdd(object) - - security.declarePrivate('reindexObject') - def reindexObject(self, object, idxs=[], update_metadata=1, uid=None): - super(CatalogTool, self).reindexObject(object, - idxs=idxs, - update_metadata=update_metadata, - uid=uid) - if idxs != []: + def catalog_object(self, obj, uid=None, idxs=None, update_metadata=1, + pghandler=None): + # Wraps the object with workflow and accessibility + # information just before cataloging. + if IIndexableObject.providedBy(obj): + w = obj + else: + w = queryMultiAdapter( (obj, self), IIndexableObject ) + if w is None: + # BBB + w = IndexableObjectWrapper(obj, self) + + idxs_ = idxs + if idxs: # Filter out invalid indexes. valid_indexes = self._catalog.indexes.keys() - idxs = [i for i in idxs if i in valid_indexes and i in self.delegatedIndexes] - else : - idxs = self.delegatedIndexes + idxs_ = [i for i in idxs if i in valid_indexes] + + super(CatalogTool, self).catalog_object(w, uid, idxs_, update_metadata, pghandler) + self.solrAdd(w, uid, idxs) + + security.declarePrivate('reindexObject') + def reindexObject(self, object, idxs=[], update_metadata=1, uid=None): + """Update catalog after object data has changed. + + The optional idxs argument is a list of specific indexes + to update (all of them by default). + + The update_metadata flag controls whether the object's + metadata record is updated as well. + + If a non-None uid is passed, it will be used as the catalog uid + for the object instead of its physical path. + """ + if uid is None: + uid = self.__url(object) - if idxs : - self.solrAdd(object, idxs=idxs, uid=uid) + self.catalog_object(object, uid, idxs, update_metadata) security.declarePrivate('unindexObject') def unindexObject(self, object): -- 2.20.1