Fix #7124, collections becoming unsorted when using manual management

This commit is contained in:
Charles Haley 2010-10-11 10:42:29 +01:00
parent 62b9a893f9
commit bcd1d79352

View File

@ -124,7 +124,6 @@ class CollectionsBookList(BookList):
collections = {} collections = {}
# This map of sets is used to avoid linear searches when testing for # This map of sets is used to avoid linear searches when testing for
# book equality # book equality
collections_lpaths = {}
for book in self: for book in self:
# Make sure we can identify this book via the lpath # Make sure we can identify this book via the lpath
lpath = getattr(book, 'lpath', None) lpath = getattr(book, 'lpath', None)
@ -198,20 +197,22 @@ class CollectionsBookList(BookList):
cat_name = category cat_name = category
if cat_name not in collections: if cat_name not in collections:
collections[cat_name] = [] collections[cat_name] = {}
collections_lpaths[cat_name] = set()
if lpath in collections_lpaths[cat_name]:
continue
collections_lpaths[cat_name].add(lpath)
if is_series: if is_series:
collections[cat_name].append( if doing_dc:
(book, book.get(attr+'_index', sys.maxint))) collections[cat_name][lpath] = \
(book, book.get('series_index', sys.maxint))
else: else:
collections[cat_name].append( collections[cat_name][lpath] = \
(book, book.get('title_sort', 'zzzz'))) (book, book.get(attr+'_index', sys.maxint))
else:
if lpath not in collections[cat_name]:
collections[cat_name][lpath] = \
(book, book.get('title_sort', 'zzzz'))
# Sort collections # Sort collections
result = {} result = {}
for category, books in collections.items(): for category, lpaths in collections.items():
books = lpaths.values()
books.sort(cmp=lambda x,y:cmp(x[1], y[1])) books.sort(cmp=lambda x,y:cmp(x[1], y[1]))
result[category] = [x[0] for x in books] result[category] = [x[0] for x in books]
return result return result