[Checkins] SVN: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py avoid hardcoding two-sort-index restriction in two places

Hano Schlichting cvs-admin at zope.org
Sat Apr 7 16:08:41 UTC 2012


Log message for revision 125083:
  avoid hardcoding two-sort-index restriction in two places
  

Changed:
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py

-=-
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py	2012-04-07 15:57:52 UTC (rev 125082)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py	2012-04-07 16:08:38 UTC (rev 125083)
@@ -666,8 +666,10 @@
         # result set in sorted order if merge is true otherwise
         # returns a list of (sortkey, uid, getter_function) tuples
         index2 = None
+        sort_index_length = 1
         if isinstance(sort_index, list):
-            if len(sort_index) > 1:
+            sort_index_length = len(sort_index)
+            if sort_index_length > 1:
                 index2 = sort_index[1]
             sort_index = sort_index[0]
         _self__getitem__ = self.__getitem__
@@ -713,12 +715,14 @@
         # determine sort_spec
         if isinstance(reverse, list):
             sort_spec = [r and -1 or 1 for r in reverse]
-            # limit to current maximum of two indexes
-            sort_spec = sort_spec[:2]
+            # limit to current maximum of sort indexes
+            sort_spec = sort_spec[:sort_index_length]
             # use first sort order for choosing the algorithm
             reverse = reverse[0]
         else:
-            sort_spec = [reverse and -1 or 1, reverse and -1 or 1]
+            sort_spec = []
+            for i in xrange(sort_index_length):
+                sort_spec.append(reverse and -1 or 1)
 
         if merge and limit is None and (
             rlen > (len(sort_index) * (rlen / 100 + 1))):



More information about the checkins mailing list