[Checkins] SVN: Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/ Add a custom index interface, and adjust tests to show implementation.

Tres Seaver tseaver at palladion.com
Wed Mar 17 07:24:06 EDT 2010


Log message for revision 110016:
  Add a custom index interface, and adjust tests to show implementation.

Changed:
  U   Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/index.py
  A   Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/interfaces.py
  U   Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/tests/test_index.py

-=-
Modified: Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/index.py
===================================================================
--- Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/index.py	2010-03-17 11:19:04 UTC (rev 110015)
+++ Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/index.py	2010-03-17 11:24:05 UTC (rev 110016)
@@ -28,12 +28,12 @@
 from App.special_dtml import DTMLFile
 from App.class_init import InitializeClass
 from OFS.SimpleItem import SimpleItem
-from Products.PluginIndexes.interfaces import IUniqueValueIndex
-from Products.PluginIndexes.interfaces import ISortIndex
 from Products.ZCatalog.Lazy import LazyMap
 from zLOG import LOG
 from zLOG import WARNING
 
+from Products.RecentItemsIndex.interfaces import IRecentItemsIndex
+
 _marker = []
 
 def _getSourceValue(obj, attrname):
@@ -50,11 +50,11 @@
 class RecentItemsIndex(SimpleItem):
     """ Recent items index.
     """
-    implements(IUniqueValueIndex, ISortIndex)
+    implements(IRecentItemsIndex)
 
     meta_type = 'Recent Items Index'
 
-    # class default;  instances get Length() in their clear()
+    # class default;  instances get a Length assigned in their clear()
     numObjects = lambda: 0
 
     manage_options = (
@@ -271,7 +271,7 @@
         """
         return self._rid2value
 
-    ## Index specific methods ##
+    ## IRecentItemsIndex implementation
     def getItemCounts(self):
         """ Return a mapping of field values => item counts.
         """

Added: Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/interfaces.py
===================================================================
--- Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/interfaces.py	                        (rev 0)
+++ Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/interfaces.py	2010-03-17 11:24:05 UTC (rev 110016)
@@ -0,0 +1,40 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+from Products.PluginIndexes.interfaces import IUniqueValueIndex
+from Products.PluginIndexes.interfaces import ISortIndex
+
+class IRecentItemsIndex(IUniqueValueIndex, ISortIndex):
+    """ API for index returning only "recent" items of a given type.
+    """
+    def getItemCounts():
+        """ Return a mapping of field values => item counts.
+        """
+
+    def query(value=None, limit=None, merge=1):
+        """ Return a lazy sequence of catalog brains like a catalog search.
+
+        Return results in order, newest first, for the value(s) given.
+
+        If 'value' is omitted, return the most recent for all values.
+        
+        'limit', if passed, must be an integer value restricting the maximum
+        number of results.
+        
+        If no limit is specified, use the 'max_length' of the index as
+        the limit.
+
+        'merge' is a flag:  if true, return a lazy map of the brains.  If
+        false, return a sequence of (value, rid, fetch) tuples which can
+        be merged later.
+        """

Modified: Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/tests/test_index.py
===================================================================
--- Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/tests/test_index.py	2010-03-17 11:19:04 UTC (rev 110015)
+++ Produts.RecentItemsIndex/trunk/Products/RecentItemsIndex/tests/test_index.py	2010-03-17 11:24:05 UTC (rev 110016)
@@ -159,6 +159,17 @@
         index = self._makeOne()
         verifyObject(ISortIndex, index)
 
+    def test_class_conforms_to_IRecentItemsIndex(self):
+        from zope.interface.verify import verifyClass
+        from Products.RecentItemsIndex.interfaces import IRecentItemsIndex
+        verifyClass(IRecentItemsIndex, self._getTargetClass())
+
+    def test_instance_conforms_to_IRecentItemsIndex(self):
+        from zope.interface.verify import verifyObject
+        from Products.RecentItemsIndex.interfaces import IRecentItemsIndex
+        index = self._makeOne()
+        verifyObject(IRecentItemsIndex, index)
+
     def test_ctor_defaults(self):
         from BTrees.Length import Length
         klass = self._getTargetClass()



More information about the checkins mailing list