Catalogs: Auto generate author sort when missing

This commit is contained in:
Kovid Goyal 2010-01-26 10:00:06 -07:00
commit 9ba8790663

View File

@ -840,7 +840,7 @@ class EPUB_MOBI(CatalogPlugin):
this_title['title_sort'] = self.generateSortTitle(title) this_title['title_sort'] = self.generateSortTitle(title)
this_title['author'] = " & ".join(record['authors']) this_title['author'] = " & ".join(record['authors'])
this_title['author_sort'] = record['author_sort'] if len(record['author_sort']) \ this_title['author_sort'] = record['author_sort'] if len(record['author_sort']) \
else this_title['author'] else self.author_to_author_sort(this_title['author'])
this_title['id'] = record['id'] this_title['id'] = record['id']
if record['publisher']: if record['publisher']:
this_title['publisher'] = re.sub('&', '&', record['publisher']) this_title['publisher'] = re.sub('&', '&', record['publisher'])
@ -1983,6 +1983,14 @@ class EPUB_MOBI(CatalogPlugin):
outfile.write(self.ncxSoup.prettify()) outfile.write(self.ncxSoup.prettify())
# Helpers # Helpers
def author_to_author_sort(self, author):
tokens = author.split()
tokens = tokens[-1:] + tokens[:-1]
if len(tokens) > 1:
tokens[0] += ','
return ' '.join(tokens)
def convertHTMLEntities(self, s): def convertHTMLEntities(self, s):
matches = re.findall("&#\d+;", s) matches = re.findall("&#\d+;", s)
if len(matches) > 0: if len(matches) > 0: