diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 01a6e8bd75..43cf5772f6 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -126,12 +126,14 @@ sort_columns_at_startup = None gui_pubdate_display_format = 'MMM yyyy' gui_timestamp_display_format = 'dd MMM yyyy' -#: Control sorting of titles and series in the display -# Control title and series sorting in the library view. -# If set to 'library_order', Leading articles such as The and A will be ignored. -# If set to 'strictly_alphabetic', the titles will be sorted without processing -# For example, with library_order, The Client will sort under 'C'. With -# strictly_alphabetic, the book will sort under 'T'. +#: 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 @@ -140,11 +142,15 @@ 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. If set to library_order, leading articles such as The and A will -# be put at the end -# If set to 'strictly_alphabetic', the titles will be sorted without processing -# For example, with library_order, "The Client" will become "Client, The". With -# strictly_alphabetic, it would remain "The Client". +# to device. The behavior depends on the field being processed. If processing +# 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 20c0a7e59c..9631737337 100644 --- a/src/calibre/library/save_to_disk.py +++ b/src/calibre/library/save_to_disk.py @@ -142,11 +142,19 @@ class SafeFormat(TemplateFormatter): def get_components(template, mi, id, timefmt='%b %Y', length=250, sanitize_func=ascii_filename, replace_whitespace=False, to_lowercase=False): - tsfmt = partial(title_sort, order=tweaks['save_template_title_series_sorting']) + + tsorder = tweaks['save_template_title_series_sorting'] format_args = FORMAT_ARGS.copy() format_args.update(mi.all_non_none_fields()) if mi.title: - format_args['title'] = tsfmt(mi.title) + 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'] @@ -157,7 +165,7 @@ def get_components(template, mi, id, timefmt='%b %Y', length=250, else: format_args['tags'] = '' if mi.series: - format_args['series'] = tsfmt(mi.series) + format_args['series'] = title_sort(mi.series, order=tsorder) if mi.series_index is not None: format_args['series_index'] = mi.format_series_index() else: @@ -176,7 +184,7 @@ def get_components(template, mi, id, timefmt='%b %Y', length=250, cm = custom_metadata[key] ## TODO: NEWMETA: should ratings be divided by 2? The standard rating isn't... if cm['datatype'] == 'series': - format_args[key] = tsfmt(format_args[key]) + format_args[key] = title_sort(format_args[key], order=tsorder) if key+'_index' in format_args: format_args[key+'_index'] = fmt_sidx(format_args[key+'_index']) elif cm['datatype'] == 'datetime':