From fb768388748aa777139dec2e64ce537940e6c87b Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Fri, 31 Dec 2010 06:48:44 +0000 Subject: [PATCH] Fix display of names in partition mode --- resources/default_tweaks.py | 6 +++--- src/calibre/gui2/tag_view.py | 3 +-- src/calibre/utils/formatter.py | 6 ++++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index a2a9a0a043..9f663a21b4 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -77,9 +77,9 @@ categories_use_field_for_author_name = 'author' # sort: the sort value. For authors, this is the author_sort for that author # category: the category (e.g., authors, series) that the item is in. categories_collapse_more_than = 50 -categories_collapsed_name_template = '{first.name:shorten(4,'',0)}{last.name::shorten(4,'',0)| - |}' -categories_collapsed_rating_template = '{first.avg_rating:4.2f}{last.avg_rating:4.2f| - |}' -categories_collapsed_popularity_template = '{first.count:d}{last.count:d| - |}' +categories_collapsed_name_template = '{first.name:shorten(4,'',0)} - {last.name::shorten(4,'',0)}' +categories_collapsed_rating_template = '{first.avg_rating:4.2f:ifempty(0)} - {last.avg_rating:4.2f:ifempty(0)}' +categories_collapsed_popularity_template = '{first.count:d} - {last.count:d}' categories_collapse_model = 'first letter' # Set whether boolean custom columns are two- or three-valued. diff --git a/src/calibre/gui2/tag_view.py b/src/calibre/gui2/tag_view.py index a9ba22f768..247904bb8e 100644 --- a/src/calibre/gui2/tag_view.py +++ b/src/calibre/gui2/tag_view.py @@ -674,7 +674,6 @@ class TagsModel(QAbstractItemModel): # {{{ if data is None: return False row_index = -1 - empty_tag = Tag('') collapse = tweaks['categories_collapse_more_than'] collapse_model = tweaks['categories_collapse_model'] if sort_by == 'name': @@ -726,7 +725,7 @@ class TagsModel(QAbstractItemModel): # {{{ if cat_len > idx + collapse: d['last'] = data[r][idx+collapse-1] else: - d['last'] = empty_tag + d['last'] = data[r][cat_len-1] name = eval_formatter.safe_format(collapse_template, d, 'TAG_VIEW', None) sub_cat = TagTreeItem(parent=category, diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index 7587a334e8..4fe8ad2e4f 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -371,6 +371,12 @@ class TemplateFormatter(string.Formatter): raise Exception('get_value must be implemented in the subclass') def format_field(self, val, fmt): + # ensure we are dealing with a string. + if isinstance(val, (int, float)): + if val: + val = unicode(val) + else: + val = '' # Handle conditional text fmt, prefix, suffix = self._explode_format_string(fmt)