From c3eb10f51deeabe9539ccb81261edfb3282654cd Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Fri, 1 Jul 2011 16:52:49 +0100 Subject: [PATCH 1/3] Fix exception in tag browser/view when a category goes away --- src/calibre/gui2/tag_browser/view.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tag_browser/view.py b/src/calibre/gui2/tag_browser/view.py index d53167591e..159d00c083 100644 --- a/src/calibre/gui2/tag_browser/view.py +++ b/src/calibre/gui2/tag_browser/view.py @@ -575,7 +575,8 @@ class TagsView(QTreeView): # {{{ expanded_categories, state_map = self.get_state() self._model.rebuild_node_tree(state_map=state_map) for category in expanded_categories: - self.expand(self._model.index_for_category(category)) + if self._model.index_for_category(category) is not None: + self.expand(self._model.index_for_category(category)) self.show_item_at_path(path) def show_item_at_path(self, path, box=False, From 4cc19001821ac5b8ae545fe2e0e154ea44eac68e Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sat, 2 Jul 2011 11:17:03 +0100 Subject: [PATCH 2/3] Add has_cover() template function --- src/calibre/library/database2.py | 1 + src/calibre/utils/formatter_functions.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 3ebd63afde..f203f36bd9 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -963,6 +963,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): mi.cover_data = ('jpeg', cdata) else: mi.cover = self.cover(id, index_is_id=True, as_path=True) + mi.has_cover = _('Yes') if self.has_cover(id) else '' return mi def has_book(self, mi): diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 1684b9f85b..fcfd69d16d 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -679,6 +679,18 @@ class BuiltinOndevice(BuiltinFormatterFunction): return _('Yes') return '' +class BuiltinHasCover(BuiltinFormatterFunction): + name = 'has_cover' + arg_count = 0 + category = 'Get values from metadata' + __doc__ = doc = _('has_cover() -- return Yes if the book has a cover, ' + 'otherwise return the empty string') + + def evaluate(self, formatter, kwargs, mi, locals): + if mi.has_cover: + return _('Yes') + return '' + class BuiltinFirstNonEmpty(BuiltinFormatterFunction): name = 'first_non_empty' arg_count = -1 @@ -814,6 +826,7 @@ builtin_eval = BuiltinEval() builtin_first_non_empty = BuiltinFirstNonEmpty() builtin_field = BuiltinField() builtin_format_date = BuiltinFormatDate() +builtin_has_cover = BuiltinHasCover() builtin_identifier_in_list = BuiltinIdentifierInList() builtin_ifempty = BuiltinIfempty() builtin_in_list = BuiltinInList() From 816e258cfc25f6a97c31574d2daf25dc58a542bf Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sat, 2 Jul 2011 11:20:01 +0100 Subject: [PATCH 3/3] Update template language documentation --- src/calibre/manual/template_lang.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index f9824187e5..9f33bcbb9e 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -257,6 +257,7 @@ The following functions are available in addition to those described in single-f iso : the date with time and timezone. Must be the only format present. * ``eval(string)`` -- evaluates the string as a program, passing the local variables (those ``assign`` ed to). This permits using the template processor to construct complex results from local variables. + * ``has_cover()`` -- return ``Yes`` if the book has a cover, otherwise return the empty string * ``not(value)`` -- returns the string "1" if the value is empty, otherwise returns the empty string. This function works well with test or first_non_empty. You can have as many values as you want. * ``merge_lists(list1, list2, separator)`` -- return a list made by merging the items in list1 and list2, removing duplicate items using a case-insensitive compare. If items differ in case, the one in list1 is used. The items in list1 and list2 are separated by separator, as are the items in the returned list. * ``multiply(x, y)`` -- returns x * y. Throws an exception if either x or y are not numbers.