mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Fix a bug and a regression in sony collection series ordering
This commit is contained in:
parent
62c9c54f1f
commit
430ff00edb
@ -388,23 +388,35 @@ class XMLCache(object):
|
|||||||
debug_print('WARNING: Some elements in the JSON cache were not'
|
debug_print('WARNING: Some elements in the JSON cache were not'
|
||||||
' found in the XML cache')
|
' found in the XML cache')
|
||||||
records = [x for x in records if x is not None]
|
records = [x for x in records if x is not None]
|
||||||
ids = set()
|
# Ensure each book has an ID.
|
||||||
for rec in records:
|
for rec in records:
|
||||||
id = rec.get('id', None)
|
if rec.get('id', None) is None:
|
||||||
if id is None:
|
|
||||||
rec.set('id', str(self.max_id(root)+1))
|
rec.set('id', str(self.max_id(root)+1))
|
||||||
id = rec.get('id', None)
|
ids = [x.get('id', None) for x in records]
|
||||||
ids.add(id)
|
# Given that we set the ids, there shouldn't be any None's. But
|
||||||
# ids cannot contain None, so no reason to check
|
# better to be safe...
|
||||||
|
if None in ids:
|
||||||
|
debug_print('WARNING: Some <text> elements do not have ids')
|
||||||
|
ids = [x for x in ids if x is not None]
|
||||||
|
|
||||||
playlist = self.get_or_create_playlist(bl_index, category)
|
playlist = self.get_or_create_playlist(bl_index, category)
|
||||||
# Reduce ids to books not already in the playlist
|
# Get the books currently in the playlist. We will need them to be
|
||||||
|
# sure to put back any books that were manually added.
|
||||||
|
playlist_ids = []
|
||||||
for item in playlist:
|
for item in playlist:
|
||||||
id_ = item.get('id', None)
|
id_ = item.get('id', None)
|
||||||
if id_ is not None:
|
if id_ is not None:
|
||||||
ids.discard(id_)
|
playlist_ids.append(id_)
|
||||||
# Add the books in ids that were not already in the playlist
|
# Empty the playlist. We do this so that the playlist will have the
|
||||||
for id_ in ids:
|
# order specified by get_collections
|
||||||
|
for item in list(playlist):
|
||||||
|
playlist.remove(item)
|
||||||
|
|
||||||
|
# Get a list of ids not known by get_collections
|
||||||
|
extra_ids = [x for x in playlist_ids if x not in ids]
|
||||||
|
# Rebuild the collection in the order specified by get_collections. Then
|
||||||
|
# add the ids that get_collections didn't know about.
|
||||||
|
for id_ in ids + extra_ids:
|
||||||
item = playlist.makeelement(
|
item = playlist.makeelement(
|
||||||
'{%s}item'%self.namespaces[bl_index],
|
'{%s}item'%self.namespaces[bl_index],
|
||||||
nsmap=playlist.nsmap, attrib={'id':id_})
|
nsmap=playlist.nsmap, attrib={'id':id_})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user