mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit metadata dialog: Fix auto-generation/validation of author sort values not working when only changing case of the author name. Fixes #1623593 [Changing upper- to lower-case doesn't work correct](https://bugs.launchpad.net/calibre/+bug/1623593)
This commit is contained in:
parent
fb183bc6c6
commit
54aaebe8be
@ -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))
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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())
|
||||
|
Loading…
x
Reference in New Issue
Block a user