From 83cde4af655a2e3f74b9c15185a7891506ba31b9 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Fri, 11 Feb 2011 10:43:28 +0000 Subject: [PATCH] Changes to save_to_disk to use title_sort instead of recomputing it. --- resources/default_tweaks.py | 36 ++++++++++++++++------------- src/calibre/library/save_to_disk.py | 10 ++++++-- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index aa997f8332..43cf5772f6 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -126,27 +126,31 @@ sort_columns_at_startup = None gui_pubdate_display_format = 'MMM yyyy' gui_timestamp_display_format = 'dd MMM yyyy' -#: Control how title and series names are formatted when saving to disk/sending -# to device. The behavior depends on the field being processed. If processing -# title, then if set to 'library_order', the title will be replaced with -# title_sort. If set to 'strictly_alphabetic', then the title is left unchanged. -# If processing series, then if set to 'library_order', articles such as 'The' -# and 'An' will be moved to the end. If set to 'strictly_alphabetic', the series -# will be sent without change. For example, with library_order, "The Lord of the -# Rings" will become "Lord of the Rings, The". With strictly_alphabetic, it -# would remain "The Lord of the Rings". +#: Control sorting of titles and series in the library display +# Control title and series sorting in the library view. If set to +# 'library_order', the title sort field will be used instead of the title. +# Unless you have manually edited the title sort field, leading articles such as +# The and A will be ignored. If set to 'strictly_alphabetic', the titles will be +# sorted as-is (sort by title instead of title sort). For example, with +# library_order, The Client will sort under 'C'. With strictly_alphabetic, the +# book will sort under 'T'. +# This flag affects Calibre's library display. It has no effect on devices. In +# addition, titles for books added before changing the flag will retain their +# order until the title is edited. Double-clicking on a title and hitting return +# without changing anything is sufficient to change the sort. title_series_sorting = 'library_order' #: Control formatting of title and series when used in templates # Control how title and series names are formatted when saving to disk/sending # to device. The behavior depends on the field being processed. If processing -# title, then if set to 'library_order', the title will be replaced with -# title_sort. If set to 'strictly_alphabetic', then the title is left unchanged. -# If processing series, then if set to 'library_order', articles such as 'The' -# and 'An' will be moved to the end. If set to 'strictly_alphabetic', the series -# will be sent without change. For example, with library_order, "The Lord of the -# Rings" will become "Lord of the Rings, The". With strictly_alphabetic, it -# would remain "The Lord of the Rings". +# title, then if this tweak is set to 'library_order', the title will be +# replaced with title_sort. If it is set to 'strictly_alphabetic', then the +# title will not be changed. If processing series, then if set to +# 'library_order', articles such as 'The' and 'An' will be moved to the end. If +# set to 'strictly_alphabetic', the series will be sent without change. +# For example, if the tweak is set to library_order, "The Lord of the Rings" +# will become "Lord of the Rings, The". If the tweak is set to +# strictly_alphabetic, it would remain "The Lord of the Rings". save_template_title_series_sorting = 'library_order' #: Set the list of words considered to be "articles" for sort strings diff --git a/src/calibre/library/save_to_disk.py b/src/calibre/library/save_to_disk.py index 11b8b412e3..9631737337 100644 --- a/src/calibre/library/save_to_disk.py +++ b/src/calibre/library/save_to_disk.py @@ -147,8 +147,14 @@ def get_components(template, mi, id, timefmt='%b %Y', length=250, format_args = FORMAT_ARGS.copy() format_args.update(mi.all_non_none_fields()) if mi.title: - format_args['title'] = mi.title if tsorder == 'strictly_alphabetic' \ - else mi.get('title_sort', title_sort(mi.title, order='library_order')) + if tsorder == 'strictly_alphabetic': + v = mi.title + else: + # title_sort might be missing or empty. Check both conditions + v = mi.get('title_sort', None) + if not v: + v = title_sort(mi.title, order=tsorder) + format_args['title'] = v if mi.authors: format_args['authors'] = mi.format_authors() format_args['author'] = format_args['authors']