mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
When automatically computing author sort from author's name, if the name contains certain words like Inc., Company, Team, etc. use the author name as the sort string directly. The list of such words can be controlled via Preferences->Tweaks. Fixes #797895 (author name sort order copy keywords)
This commit is contained in:
parent
2c33b9b409
commit
967285b9f6
@ -62,10 +62,16 @@ authors_completer_append_separator = False
|
||||
# The author name suffixes are words that are ignored when they occur at the
|
||||
# end of an author name. The case of the suffix is ignored and trailing
|
||||
# periods are automatically handled.
|
||||
# The author name copy words are a set of words which if they occur in an
|
||||
# author name cause the automatically geenrated author sort string to be
|
||||
# identical to the author name. This means that the sort for a string like Acme
|
||||
# Inc. will be Acme Inc. instead of Inc., Acme
|
||||
author_sort_copy_method = 'comma'
|
||||
author_name_suffixes = ('Jr', 'Sr', 'Inc', 'Ph.D', 'Phd',
|
||||
'MD', 'M.D', 'I', 'II', 'III', 'IV',
|
||||
'Junior', 'Senior')
|
||||
author_name_copywords = ('Corporation', 'Company', 'Co.', 'Agency', 'Council',
|
||||
'Committee', 'Inc.', 'Institute', 'Society', 'Club', 'Team')
|
||||
|
||||
#: Use author sort in Tag Browser
|
||||
# Set which author field to display in the tags pane (the list of authors,
|
||||
|
@ -36,8 +36,15 @@ def author_to_author_sort(author, method=None):
|
||||
return author
|
||||
if method is None:
|
||||
method = tweaks['author_sort_copy_method']
|
||||
|
||||
ltoks = frozenset(x.lower() for x in tokens)
|
||||
copy_words = frozenset(x.lower() for x in tweaks['author_name_copywords'])
|
||||
if ltoks.intersection(copy_words):
|
||||
method = u'copy'
|
||||
|
||||
if method == u'copy':
|
||||
return author
|
||||
|
||||
suffixes = set([x.lower() for x in tweaks['author_name_suffixes']])
|
||||
suffixes |= set([x+u'.' for x in suffixes])
|
||||
|
||||
|
@ -308,7 +308,7 @@ class AuthorSortEdit(EnLineEdit):
|
||||
LABEL = _('Author s&ort:')
|
||||
|
||||
def __init__(self, parent, authors_edit, autogen_button, db,
|
||||
copy_a_to_as_action, copy_as_to_a_action):
|
||||
copy_a_to_as_action, copy_as_to_a_action, a_to_as, as_to_a):
|
||||
EnLineEdit.__init__(self, parent)
|
||||
self.authors_edit = authors_edit
|
||||
self.db = db
|
||||
@ -333,6 +333,8 @@ class AuthorSortEdit(EnLineEdit):
|
||||
autogen_button.clicked.connect(self.auto_generate)
|
||||
copy_a_to_as_action.triggered.connect(self.auto_generate)
|
||||
copy_as_to_a_action.triggered.connect(self.copy_to_authors)
|
||||
a_to_as.triggered.connect(self.author_to_sort)
|
||||
as_to_a.triggered.connect(self.sort_to_author)
|
||||
self.update_state()
|
||||
|
||||
@dynamic_property
|
||||
@ -389,10 +391,21 @@ class AuthorSortEdit(EnLineEdit):
|
||||
|
||||
def auto_generate(self, *args):
|
||||
au = unicode(self.authors_edit.text())
|
||||
au = re.sub(r'\s+et al\.$', '', au)
|
||||
au = re.sub(r'\s+et al\.$', '', au).strip()
|
||||
authors = string_to_authors(au)
|
||||
self.current_val = self.db.author_sort_from_authors(authors)
|
||||
|
||||
def author_to_sort(self, *args):
|
||||
au = unicode(self.authors_edit.text())
|
||||
au = re.sub(r'\s+et al\.$', '', au).strip()
|
||||
if au:
|
||||
self.current_val = au
|
||||
|
||||
def sort_to_author(self, *args):
|
||||
aus = self.current_val
|
||||
if aus:
|
||||
self.authors_edit.current_val = [aus]
|
||||
|
||||
def initialize(self, db, id_):
|
||||
self.current_val = db.author_sort(id_, index_is_id=True)
|
||||
|
||||
|
@ -130,10 +130,15 @@ class MetadataSingleDialogBase(ResizableDialog):
|
||||
ac = m.addAction(QIcon(I('forward.png')), _('Set author sort from author'))
|
||||
ac2 = m.addAction(QIcon(I('back.png')), _('Set author from author sort'))
|
||||
ac3 = m.addAction(QIcon(I('user_profile.png')), _('Manage authors'))
|
||||
ac4 = m.addAction(QIcon(I('next.png')),
|
||||
_('Copy author to author sort'))
|
||||
ac5 = m.addAction(QIcon(I('previous.png')),
|
||||
_('Copy author sort to author'))
|
||||
|
||||
b.setMenu(m)
|
||||
self.authors = AuthorsEdit(self, ac3)
|
||||
self.author_sort = AuthorSortEdit(self, self.authors, b, self.db, ac,
|
||||
ac2)
|
||||
ac2, ac4, ac5)
|
||||
self.basic_metadata_widgets.extend([self.authors, self.author_sort])
|
||||
|
||||
self.swap_title_author_button = QToolButton(self)
|
||||
|
Loading…
x
Reference in New Issue
Block a user