mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
c1a4f18e8f
commit
55db0eb600
@ -339,27 +339,8 @@ class Cache(object):
|
|||||||
return self.backend.cover(path, as_file=as_file, as_image=as_image,
|
return self.backend.cover(path, as_file=as_file, as_image=as_image,
|
||||||
as_path=as_path)
|
as_path=as_path)
|
||||||
|
|
||||||
@api
|
|
||||||
def sanitize_sort_field_name(self, field):
|
|
||||||
field = self.field_metadata.search_term_to_field_key(field.lower().strip())
|
|
||||||
# translate some fields to their hidden equivalent
|
|
||||||
field = {'title': 'sort', 'authors':'author_sort'}.get(field, field)
|
|
||||||
return field
|
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def sort(self, field, ascending, subsort=False):
|
def multisort(self, fields):
|
||||||
self._multisort([(field, ascending)])
|
|
||||||
|
|
||||||
@read_api
|
|
||||||
def multisort(self, fields=[], subsort=False):
|
|
||||||
fields = [(self.sanitize_sort_field_name(x), bool(y)) for x, y in fields]
|
|
||||||
keys = self.field_metadata.sortable_field_keys()
|
|
||||||
fields = [x for x in fields if x[0] in keys]
|
|
||||||
if subsort and 'sort' not in [x[0] for x in fields]:
|
|
||||||
fields += [('sort', True)]
|
|
||||||
if not fields:
|
|
||||||
fields = [('timestamp', False)]
|
|
||||||
|
|
||||||
all_book_ids = frozenset(self._all_book_ids())
|
all_book_ids = frozenset(self._all_book_ids())
|
||||||
get_metadata = partial(self._get_metadata, get_user_categories=False)
|
get_metadata = partial(self._get_metadata, get_user_categories=False)
|
||||||
|
|
||||||
|
@ -9,6 +9,12 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
def sanitize_sort_field_name(field_metadata, field):
|
||||||
|
field = field_metadata.search_term_to_field_key(field.lower().strip())
|
||||||
|
# translate some fields to their hidden equivalent
|
||||||
|
field = {'title': 'sort', 'authors':'author_sort'}.get(field, field)
|
||||||
|
return field
|
||||||
|
|
||||||
class View(object):
|
class View(object):
|
||||||
|
|
||||||
def __init__(self, cache):
|
def __init__(self, cache):
|
||||||
@ -35,6 +41,10 @@ class View(object):
|
|||||||
self._map = list(self.cache.all_book_ids())
|
self._map = list(self.cache.all_book_ids())
|
||||||
self._map_filtered = list(self._map)
|
self._map_filtered = list(self._map)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def field_metadata(self):
|
||||||
|
return self.cache.field_metadata
|
||||||
|
|
||||||
def _get_id(self, idx, index_is_id=True):
|
def _get_id(self, idx, index_is_id=True):
|
||||||
ans = idx if index_is_id else self.index_to_id(idx)
|
ans = idx if index_is_id else self.index_to_id(idx)
|
||||||
return ans
|
return ans
|
||||||
@ -83,4 +93,17 @@ class View(object):
|
|||||||
ans.append(self.cache._author_data(id_))
|
ans.append(self.cache._author_data(id_))
|
||||||
return tuple(ans)
|
return tuple(ans)
|
||||||
|
|
||||||
|
def multisort(self, fields=[], subsort=False):
|
||||||
|
fields = [(sanitize_sort_field_name(self.field_metadata, x), bool(y)) for x, y in fields]
|
||||||
|
keys = self.field_metadata.sortable_field_keys()
|
||||||
|
fields = [x for x in fields if x[0] in keys]
|
||||||
|
if subsort and 'sort' not in [x[0] for x in fields]:
|
||||||
|
fields += [('sort', True)]
|
||||||
|
if not fields:
|
||||||
|
fields = [('timestamp', False)]
|
||||||
|
|
||||||
|
sorted_book_ids = self.cache.multisort(fields)
|
||||||
|
sorted_book_ids
|
||||||
|
# TODO: change maps
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user