diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index be3a5ab5fb..bbf8858241 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -1448,15 +1448,15 @@ class Cache(object): return _get_next_series_num_for_list(tuple(series_indices), unwrap=False) @read_api - def author_sort_from_authors(self, authors): + def author_sort_from_authors(self, authors, key_func=icu_lower): '''Given a list of authors, return the author_sort string for the authors, preferring the author sort associated with the author over the computed string. ''' table = self.fields['authors'].table result = [] - rmap = {icu_lower(v):k for k, v in table.id_map.iteritems()} + rmap = {key_func(v):k for k, v in table.id_map.iteritems()} for aut in authors: - aid = rmap.get(icu_lower(aut), None) + aid = rmap.get(key_func(aut), None) result.append(author_to_author_sort(aut) if aid is None else table.asort_map[aid]) return ' & '.join(filter(None, result)) diff --git a/src/calibre/db/legacy.py b/src/calibre/db/legacy.py index 7e51abd317..ad6541bc79 100644 --- a/src/calibre/db/legacy.py +++ b/src/calibre/db/legacy.py @@ -903,7 +903,7 @@ LibraryDatabase.metadata_for_field = MT(lambda self, field:self.field_metadata.g # }}} # Miscellaneous API {{{ -for meth in ('get_next_series_num_for', 'has_book', 'author_sort_from_authors'): +for meth in ('get_next_series_num_for', 'has_book',): def getter(meth): def func(self, x): return getattr(self.new_api, meth)(x) @@ -917,6 +917,7 @@ LibraryDatabase.saved_search_delete = MT(lambda self, x:self.new_api.saved_searc LibraryDatabase.saved_search_add = MT(lambda self, x, y:self.new_api.saved_search_add(x, y)) LibraryDatabase.saved_search_rename = MT(lambda self, x, y:self.new_api.saved_search_rename(x, y)) LibraryDatabase.commit_dirty_cache = MT(lambda self: self.new_api.commit_dirty_cache()) +LibraryDatabase.author_sort_from_authors = MT(lambda self, x: self.new_api.author_sort_from_authors(x)) # Cleaning is not required anymore LibraryDatabase.clean = LibraryDatabase.clean_custom = MT(lambda self:None) LibraryDatabase.clean_standard_field = MT(lambda self, field, commit=False:None) diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py index 4c15363dfe..9df65d453a 100644 --- a/src/calibre/gui2/metadata/basic_widgets.py +++ b/src/calibre/gui2/metadata/basic_widgets.py @@ -486,10 +486,13 @@ class AuthorSortEdit(EnLineEdit, ToMetadataMixin): self.first_time = False self.update_state() + def author_sort_from_authors(self, authors): + return self.db.new_api.author_sort_from_authors(authors, key_func=lambda x: x) + def update_state(self, *args): au = unicode(self.authors_edit.text()) au = re.sub(r'\s+et al\.$', '', au) - au = self.db.author_sort_from_authors(string_to_authors(au)) + au = self.author_sort_from_authors(string_to_authors(au)) normal = au == self.current_val col = OK_COLOR if normal else ERR_COLOR @@ -517,7 +520,7 @@ class AuthorSortEdit(EnLineEdit, ToMetadataMixin): au = unicode(self.authors_edit.text()) au = re.sub(r'\s+et al\.$', '', au).strip() authors = string_to_authors(au) - self.current_val = self.db.author_sort_from_authors(authors) + self.current_val = self.author_sort_from_authors(authors) def author_to_sort(self, *args): au = unicode(self.authors_edit.text())