Vieux vieux bug…
[Plinn.git] / catalog.py
index 05cbd59..f2736cb 100644 (file)
@@ -5,7 +5,7 @@ from Products.CMFCore.interfaces import IIndexableObject
 from Products.CMFCore.CatalogTool import CatalogTool as BaseCatalogTool
 from Products.CMFCore.CatalogTool import IndexableObjectWrapper
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from Products.CMFCore.CatalogTool import CatalogTool as BaseCatalogTool
 from Products.CMFCore.CatalogTool import IndexableObjectWrapper
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
-from Products.CMFCore.permissions import ModifyPortalContent
+from Products.CMFCore.permissions import ModifyPortalContent, ManagePortal
 from zope.component import queryMultiAdapter
 from Products.ZCatalog.Catalog import Catalog
 import transaction
 from zope.component import queryMultiAdapter
 from Products.ZCatalog.Catalog import Catalog
 import transaction
@@ -22,17 +22,20 @@ _VOLATILE_SOLR_NAME = '_v_solrConnection'
 
 class SolrTransactionHook :
     ''' commit solr couplé sur le commit de la ZODB '''
 
 class SolrTransactionHook :
     ''' commit solr couplé sur le commit de la ZODB '''
-    def __init__(self, context) :
+    def __init__(self, context, con) :
         self.context = context
         self.context = context
+        self.con = con
     
     def __call__(self, status) :
     
     def __call__(self, status) :
-        con = getattr(self.context, _VOLATILE_SOLR_NAME)
         if status :
         if status :
-            con.commit()
-            con.close()
+            self.con.commit()
+            self.con.close()
         else :
         else :
-            con.close()
-        delattr(self.context, _VOLATILE_SOLR_NAME)
+            self.con.close()
+        try :
+            delattr(self.context, _VOLATILE_SOLR_NAME)
+        except AttributeError :
+            pass
 
 class CatalogTool(BaseCatalogTool) :
     meta_type = 'Plinn Catalog'
 
 class CatalogTool(BaseCatalogTool) :
     meta_type = 'Plinn Catalog'
@@ -40,7 +43,8 @@ class CatalogTool(BaseCatalogTool) :
     manage_options = (BaseCatalogTool.manage_options[:5] +
                       ({'label' : 'Solr', 'action' : 'manage_solr'},) +
                       BaseCatalogTool.manage_options[5:])
     manage_options = (BaseCatalogTool.manage_options[:5] +
                       ({'label' : 'Solr', 'action' : 'manage_solr'},) +
                       BaseCatalogTool.manage_options[5:])
-    manage_solr = PageTemplateFile('www/manage_solr', globals())
+    manage_solr = PageTemplateFile('www/manage_solr.pt', globals(), __name__='manage_solr')
+    
     
     
     def __init__(self, idxs=[]) :
     
     
     def __init__(self, idxs=[]) :
@@ -49,12 +53,24 @@ class CatalogTool(BaseCatalogTool) :
         self.solr_url = 'http://localhost:8983/solr'
         self.delegatedIndexes = ('Title', 'Description', 'SearchableText')
     
         self.solr_url = 'http://localhost:8983/solr'
         self.delegatedIndexes = ('Title', 'Description', 'SearchableText')
     
+    security.declarePublic('getDelegatedIndexes')
+    def getDelegatedIndexes(self) :
+        """ read the method name """
+        return self.delegatedIndexes
+    
+    security.declareProtected(ManagePortal, 'setDelegatedIndexes')
+    def setDelegatedIndexes(self, indexes, REQUEST=None) :
+        """setDelegatedIndexes documentation"""
+        self.delegatedIndexes = tuple([i.strip() for i in indexes if i.strip()])
+        if REQUEST :
+            REQUEST.RESPONSE.redirect(self.absolute_url() + '/manage_solr?manage_tabs_message=Saved changes.')
+    
     def _getSolrConnection(self) :
         if not hasattr(self, _VOLATILE_SOLR_NAME) :
             con = SolrConnection(self.solr_url)
             setattr(self, _VOLATILE_SOLR_NAME, con)
             txn = transaction.get()
     def _getSolrConnection(self) :
         if not hasattr(self, _VOLATILE_SOLR_NAME) :
             con = SolrConnection(self.solr_url)
             setattr(self, _VOLATILE_SOLR_NAME, con)
             txn = transaction.get()
-            txn.addAfterCommitHook(SolrTransactionHook(self))
+            txn.addAfterCommitHook(SolrTransactionHook(self, con))
         return getattr(self, _VOLATILE_SOLR_NAME)
     
     security.declarePrivate('solrAdd')
         return getattr(self, _VOLATILE_SOLR_NAME)
     
     security.declarePrivate('solrAdd')