Template language: Fix zero valued series indices not formatting correctly

Fixes #1247348 [Template does not show correct result with series_index[0]](https://bugs.launchpad.net/calibre/+bug/1247348)

Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
Kovid Goyal 2013-11-03 10:20:08 +05:30
commit 0a6e52b034
2 changed files with 7 additions and 5 deletions

View File

@ -33,8 +33,7 @@ class SafeFormat(TemplateFormatter):
b = self.book.get_user_metadata(key, False)
except:
b = None
if b and ((b['datatype'] == 'int' and self.book.get(key, 0) == 0) or
(b['datatype'] == 'float' and self.book.get(key, 0.0) == 0.0)):
if b and b['datatype'] in {'int', 'float'} and self.book.get(key, None) is None:
v = ''
else:
v = self.book.format_field(key, series_with_index=False)[1]

View File

@ -504,9 +504,12 @@ class FieldMetadata(dict):
return [k for k in self._tb_cats.iterkeys() if self.is_ignorable_field(k)]
def is_series_index(self, key):
m = self[key]
return (m['datatype'] == 'float' and key.endswith('_index') and
key[:-6] in self)
try:
m = self._tb_cats[key]
return (m['datatype'] == 'float' and key.endswith('_index') and
key[:-6] in self._tb_cats)
except (KeyError, ValueError, TypeError, AttributeError):
return False
def key_to_label(self, key):
if 'label' not in self._tb_cats[key]: