mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
calibredb list: Allow specifying multiple fields for --sort-by. Fixes #1982532 [calibredb sort on multiple fields](https://bugs.launchpad.net/calibre/+bug/1982532)
This commit is contained in:
parent
d1a6bfa7b5
commit
c0884b14c4
@ -48,15 +48,17 @@ def implementation(
|
|||||||
else:
|
else:
|
||||||
fields = sorted(afields)
|
fields = sorted(afields)
|
||||||
sort_by = sort_by or 'id'
|
sort_by = sort_by or 'id'
|
||||||
if sort_by not in afields:
|
sort_fields = sort_by.split(',')
|
||||||
return f'Unknown sort field: {sort_by}'
|
for sf in sort_fields:
|
||||||
|
if sf not in afields:
|
||||||
|
return f'Unknown sort field: {sf}'
|
||||||
|
sort_spec = [(sf, ascending) for sf in sort_fields]
|
||||||
if not set(fields).issubset(afields):
|
if not set(fields).issubset(afields):
|
||||||
return 'Unknown fields: {}'.format(', '.join(set(fields) - afields))
|
return 'Unknown fields: {}'.format(', '.join(set(fields) - afields))
|
||||||
if search_text:
|
if search_text:
|
||||||
book_ids = db.multisort([(sort_by, ascending)],
|
book_ids = db.multisort(sort_spec, ids_to_sort=db.search(search_text))
|
||||||
ids_to_sort=db.search(search_text))
|
|
||||||
else:
|
else:
|
||||||
book_ids = db.multisort([(sort_by, ascending)])
|
book_ids = db.multisort(sort_spec)
|
||||||
if limit > -1:
|
if limit > -1:
|
||||||
book_ids = book_ids[:limit]
|
book_ids = book_ids[:limit]
|
||||||
data = {}
|
data = {}
|
||||||
@ -274,7 +276,7 @@ List the books available in the calibre database.
|
|||||||
'--sort-by',
|
'--sort-by',
|
||||||
default=None,
|
default=None,
|
||||||
help=_(
|
help=_(
|
||||||
'The field by which to sort the results.\nAvailable fields: {0}\nDefault: {1}'
|
'The field by which to sort the results. You can specify multiple fields by separating them with commas.\nAvailable fields: {0}\nDefault: {1}'
|
||||||
).format(', '.join(sorted(FIELDS)), 'id')
|
).format(', '.join(sorted(FIELDS)), 'id')
|
||||||
)
|
)
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user