This commit is contained in:
Kovid Goyal 2011-01-18 08:52:31 -07:00
commit b731eb7bf9
2 changed files with 28 additions and 30 deletions

View File

@ -6,6 +6,8 @@ __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
''' '''
These templates control the content of titles displayed in the various sections
Available fields: Available fields:
{title} Title of the book {title} Title of the book
{series} Series name {series} Series name
@ -14,6 +16,7 @@ __docformat__ = 'restructuredtext en'
{rating_parens} Rating, in parentheses {rating_parens} Rating, in parentheses
{pubyear} Year the book was published {pubyear} Year the book was published
{pubyear_parens} Year the book was published, in parentheses {pubyear_parens} Year the book was published, in parentheses
''' '''
# Books by Author # Books by Author
by_authors_normal_title_template = '{title} {pubyear_parens}' by_authors_normal_title_template = '{title} {pubyear_parens}'

View File

@ -19,6 +19,7 @@ from calibre.ebooks.oeb.base import XHTML_NS
from calibre.ptempfile import PersistentTemporaryDirectory from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.utils.config import config_dir from calibre.utils.config import config_dir
from calibre.utils.date import format_date, isoformat, now as nowf from calibre.utils.date import format_date, isoformat, now as nowf
from calibre.utils.icu import capitalize
from calibre.utils.logging import default_log as log from calibre.utils.logging import default_log as log
from calibre.utils.zipfile import ZipFile, ZipInfo from calibre.utils.zipfile import ZipFile, ZipInfo
from calibre.utils.magick.draw import thumbnail from calibre.utils.magick.draw import thumbnail
@ -1026,17 +1027,12 @@ class EPUB_MOBI(CatalogPlugin):
self.__totalSteps += 3 self.__totalSteps += 3
# Load section list templates # Load section list templates
templates = ['by_authors_normal_title_template', templates = []
'by_authors_series_title_template', with open(P('catalog/section_list_templates.py'), 'r') as f:
'by_titles_normal_title_template', for line in f:
'by_titles_series_title_template', t = re.match("(by_.+_template)",line)
'by_series_title_template', if t:
'by_genres_normal_title_template', templates.append(t.group(1))
'by_genres_series_title_template',
'by_recently_added_normal_title_template',
'by_recently_added_series_title_template',
'by_month_added_normal_title_template',
'by_month_added_series_title_template']
execfile(P('catalog/section_list_templates.py'), locals()) execfile(P('catalog/section_list_templates.py'), locals())
for t in templates: for t in templates:
setattr(self,t,eval(t)) setattr(self,t,eval(t))
@ -1440,7 +1436,9 @@ class EPUB_MOBI(CatalogPlugin):
# Exit if author matches previous, but author_sort doesn't match # Exit if author matches previous, but author_sort doesn't match
if author[0] == current_author[0]: if author[0] == current_author[0]:
error_msg = _(''' error_msg = _('''
Inconsistent Author Sort values for Author '{0}' ('{1}' <> '{2}'), unable to build catalog.\n Inconsistent Author Sort values for Author '{0}':
'{1}' <> '{2}',
unable to build catalog.\n
Select all books by '{0}', apply correct Author Sort value in Edit Metadata dialog, Select all books by '{0}', apply correct Author Sort value in Edit Metadata dialog,
then rebuild the catalog.\n''').format(author[0],author[1],current_author[1]) then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
self.opts.log.warn('\n*** Metadata error ***') self.opts.log.warn('\n*** Metadata error ***')
@ -1449,17 +1447,13 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
self.error.append('Metadata error') self.error.append('Metadata error')
self.error.append(error_msg) self.error.append(error_msg)
return False return False
current_author = author
self.booksByAuthor = sorted(self.booksByAuthor, key=self.booksByAuthorSorter_author_sort) self.booksByAuthor = sorted(self.booksByAuthor, key=self.booksByAuthorSorter_author_sort)
# for book in self.booksByAuthor:
# print '{0:<10} {1:<5} {2:<20} {3:<20} {4:<20} {5:<20}'.format(book['series'], book['series_index'], book['title'],
# book['author'], book['authors'],book['author_sort'])
# print
# Build the unique_authors set from existing data # Build the unique_authors set from existing data
authors = [(record['author'], record['author_sort'].capitalize()) for record in self.booksByAuthor] authors = [(record['author'], capitalize(record['author_sort'])) for record in self.booksByAuthor]
# authors[] contains a list of all book authors, with multiple entries for multiple books by author # authors[] contains a list of all book authors, with multiple entries for multiple books by author
# authors[]: (([0]:friendly [1]:sort)) # authors[]: (([0]:friendly [1]:sort))
@ -1565,7 +1559,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
this_title['rating'] = record['rating'] if record['rating'] else 0 this_title['rating'] = record['rating'] if record['rating'] else 0
if re.match('0100-01-01',str(record['pubdate'].date())): if re.match('0101-01-01',str(record['pubdate'].date())):
this_title['date'] = None this_title['date'] = None
else: else:
this_title['date'] = strftime(u'%B %Y', record['pubdate'].timetuple()) this_title['date'] = strftime(u'%B %Y', record['pubdate'].timetuple())
@ -2682,7 +2676,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
#aTag.insert(0,'%d. %s &middot; %s' % (book['series_index'],escape(book['title']), ' & '.join(book['authors']))) #aTag.insert(0,'%d. %s &middot; %s' % (book['series_index'],escape(book['title']), ' & '.join(book['authors'])))
# Reassert 'date' since this is the result of a new search # Reassert 'date' since this is the result of a new search
if re.match('0100-01-01',str(book['pubdate'].date())): if re.match('0101-01-01',str(book['pubdate'].date())):
book['date'] = None book['date'] = None
else: else:
book['date'] = strftime(u'%B %Y', book['pubdate'].timetuple()) book['date'] = strftime(u'%B %Y', book['pubdate'].timetuple())
@ -2756,7 +2750,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
this_book = {} this_book = {}
this_book['author'] = book['author'] this_book['author'] = book['author']
this_book['title'] = book['title'] this_book['title'] = book['title']
this_book['author_sort'] = book['author_sort'].capitalize() this_book['author_sort'] = capitalize(book['author_sort'])
this_book['read'] = book['read'] this_book['read'] = book['read']
this_book['tags'] = book['tags'] this_book['tags'] = book['tags']
this_book['id'] = book['id'] this_book['id'] = book['id']
@ -3901,14 +3895,14 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
Sort non-series books before series books Sort non-series books before series books
''' '''
if not book['series']: if not book['series']:
key = '%s %s' % (book['author_sort'].capitalize(), key = '%s %s' % (capitalize(book['author_sort']),
book['title_sort'].capitalize()) capitalize(book['title_sort']))
else: else:
index = book['series_index'] index = book['series_index']
integer = int(index) integer = int(index)
fraction = index-integer fraction = index-integer
series_index = '%04d%s' % (integer, str('%0.4f' % fraction).lstrip('0')) series_index = '%04d%s' % (integer, str('%0.4f' % fraction).lstrip('0'))
key = '%s ~%s %s' % (book['author_sort'].capitalize(), key = '%s ~%s %s' % (capitalize(book['author_sort']),
self.generateSortTitle(book['series']), self.generateSortTitle(book['series']),
series_index) series_index)
return key return key
@ -3919,7 +3913,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
''' '''
if not book['series']: if not book['series']:
key = '%s %s' % (self.author_to_author_sort(book['author']), key = '%s %s' % (self.author_to_author_sort(book['author']),
book['title_sort'].capitalize()) capitalize(book['title_sort']))
else: else:
index = book['series_index'] index = book['series_index']
integer = int(index) integer = int(index)
@ -4313,10 +4307,11 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
formats = ' &middot; '.join(formats) formats = ' &middot; '.join(formats)
# Date of publication # Date of publication
pubdate = book['date'] if book['date']:
pubmonth, pubyear = pubdate.split() pubdate = book['date']
if pubyear == '101': pubmonth, pubyear = pubdate.split()
pubdate = pubmonth = pubyear = '' else:
pubdate = pubyear = pubmonth = ''
# Thumb # Thumb
_soup = BeautifulSoup('<html>',selfClosingTags=['img']) _soup = BeautifulSoup('<html>',selfClosingTags=['img'])
@ -4570,7 +4565,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
if self.letter_or_symbol(word[0]) != word[0]: if self.letter_or_symbol(word[0]) != word[0]:
if word[0] > 'A' or (ord('9') < ord(word[0]) < ord('A')) : if word[0] > 'A' or (ord('9') < ord(word[0]) < ord('A')) :
translated.append('/') translated.append('/')
translated.append(word.capitalize()) translated.append(capitalize(word))
else: else:
if re.search('[0-9]+',word[0]): if re.search('[0-9]+',word[0]):