[Zope-CVS] CVS: Products/QueueCatalog - QueueCatalog.py:1.6

Shane Hathaway shane@cvs.zope.org
Mon, 30 Sep 2002 10:58:53 -0400


Update of /cvs-repository/Products/QueueCatalog
In directory cvs.zope.org:/tmp/cvs-serv21262

Modified Files:
	QueueCatalog.py 
Log Message:
- Added to QueueCatalog the option to process the queue after every
  item removal event.  This makes sense for a lot of applications
  that rarely remove items.

- Added indexObject(), unindexObject(), and reindexObject() so
  QueueCatalogs can look like CMF portal_catalogs.


=== Products/QueueCatalog/QueueCatalog.py 1.5 => 1.6 ===
--- Products/QueueCatalog/QueueCatalog.py:1.5	Thu Sep 26 14:02:26 2002
+++ Products/QueueCatalog/QueueCatalog.py	Mon Sep 30 10:58:51 2002
@@ -81,8 +81,11 @@
       
     """
 
+    security = ClassSecurityInformation()
+
     _immediate_indexes = ()  # The names of indexes to update immediately
     _location = None
+    _immediate_removal = 1   # Flag: don't queue removal
     title = ''
 
     # When set, _v_catalog_cache is a tuple containing the wrapped ZCatalog
@@ -127,6 +130,13 @@
         self._immediate_indexes = tuple(map(str, indexes))
 
 
+    def getImmediateRemoval(self):
+        return self._immediate_removal
+
+    def setImmediateRemoval(self, flag):
+        self._immediate_removal = not not flag
+
+
     def getZCatalog(self, method=''):
         ZC = None
         REQUEST = getattr(self, 'REQUEST', None)
@@ -229,6 +239,7 @@
         self._update(uid, event)
 
         if self._immediate_indexes:
+            # Update some of the indexes immediately.
             catalog.catalog_object(obj, uid, self._immediate_indexes)
 
 
@@ -242,6 +253,10 @@
 
         self._update(uid, REMOVED)
 
+        if self._immediate_removal:
+            self.process()
+
+
     def process(self):
         "Process pending events"
         catalog = self.getZCatalog()
@@ -259,6 +274,32 @@
                     obj = catalog.unrestrictedTraverse(uid)
                     catalog.catalog_object(obj, uid)
 
+    #
+    # CMF catalog tool methods.
+    #
+    security.declarePrivate('indexObject')
+    def indexObject(self, object):
+        """Add to catalog.
+        """
+        self.catalog_object(object)
+
+    security.declarePrivate('unindexObject')
+    def unindexObject(self, object):
+        """Remove from catalog.
+        """
+        url = '/'.join(ob.getPhysicalPath())
+        self.uncatalog_object(url)
+
+    security.declarePrivate('reindexObject')
+    def reindexObject(self, object, idxs=[]):
+        """Update catalog after object data has changed.
+
+        The optional idxs argument is a list of specific indexes
+        to update (all of them by default).
+        """
+        # Punt for now and ignore idxs.
+        self.catalog_object(object)
+
     # Provide web pages. It would be nice to use views, but Zope 2.6
     # just isn't ready for views. :( In particular, we'd have to fake
     # out the PageTemplateFiles in some brittle way to make them do
@@ -270,11 +311,12 @@
         return self._location or ''
 
     def manage_edit(self, title='', location='', immediate_indexes=(),
-                    RESPONSE=None):
+                    immediate_removal=0, RESPONSE=None):
         """ Edit the instance """
         self.title = title
         self.setLocation(location or None)
         self.setImmediateIndexes(immediate_indexes)
+        self.setImmediateRemoval(immediate_removal)
 
         if RESPONSE is not None:
             RESPONSE.redirect('%s/manage_editForm?manage_tabs_message='
@@ -320,8 +362,6 @@
         +SimpleItem.manage_options
         )
 
-    security = ClassSecurityInformation()
-
     security.declareObjectPublic()
     # Disallow access to subobjects with no security assertions.
     security.setDefaultAccess('deny')
@@ -335,7 +375,8 @@
         'View management screens',
         'manage_editForm', 'manage_edit',
         'manage_queue', 'manage_getLocation',
-        'manage_size', 'getIndexInfo', 'getImmediateIndexes'
+        'manage_size', 'getIndexInfo', 'getImmediateIndexes',
+        'getImmediateRemoval',
         )
     
 def cataloged(catalog, path):