Skip to content

Commit 3bad97c

Browse files
author
Richard Jones
committed
fix anydbm filtering
1 parent 4489f65 commit 3bad97c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

roundup/backends/back_anydbm.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.144 2004-05-04 00:16:06 richard Exp $
18+
#$Id: back_anydbm.py,v 1.145 2004-05-05 00:17:13 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in a
2020
database chosen by anydbm. It is guaranteed to always be available in python
2121
versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
@@ -1736,6 +1736,10 @@ def filter(self, search_matches, filterspec, sort=(None,None),
17361736
k.append(v)
17371737
matches = k
17381738

1739+
# always sort by id if no other sort is specified
1740+
if sort == (None, None):
1741+
sort = ('+', 'id')
1742+
17391743
# add sorting information to the match entries
17401744
directions = []
17411745
for dir, prop in sort, group:
@@ -1771,8 +1775,9 @@ def filter(self, search_matches, filterspec, sort=(None,None),
17711775
v = link.get(v, key)
17721776
entry.insert(0, v)
17731777

1774-
if directions:
1775-
# sort using the first one or two columns
1778+
if '-' in directions:
1779+
# one or more of the sort specs is in reverse order, so we have
1780+
# to use this icky function to sort
17761781
def sortfun(a, b, directions=directions, n=range(len(directions))):
17771782
for i in n:
17781783
if a[i] == b[i]: continue
@@ -1783,6 +1788,9 @@ def sortfun(a, b, directions=directions, n=range(len(directions))):
17831788
# for consistency, sort by the id if the items are equal
17841789
return cmp(a[-2], b[-2])
17851790
matches.sort(sortfun)
1791+
else:
1792+
# sorting is in the normal direction
1793+
matches.sort()
17861794

17871795
# pull the id out of the individual entries
17881796
matches = [entry[-2] for entry in matches]

0 commit comments

Comments
 (0)