Fix exception when rendering empty fields

This commit is contained in:
Kovid Goyal 2017-05-19 10:57:09 +05:30
parent 2d403e9d64
commit 039f585533
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -138,6 +138,8 @@ def render_metadata(mi, table, book_id): # {{{
comments = {} comments = {}
def add_row(name, val, is_searchable=False, is_html=False, join=None): def add_row(name, val, is_searchable=False, is_html=False, join=None):
if val is undefined or val is None:
return
def add_val(v): def add_val(v):
if not v.appendChild: if not v.appendChild:
v += '' v += ''
@ -297,11 +299,13 @@ def render_metadata(mi, table, book_id): # {{{
func(field, fm, name, val) func(field, fm, name, val)
else: else:
if datatype is 'text' or datatype is 'enumeration': if datatype is 'text' or datatype is 'enumeration':
if val is not undefined and val is not None:
join = fm.is_multiple.list_to_ui if fm.is_multiple else None join = fm.is_multiple.list_to_ui if fm.is_multiple else None
add_row(name, val, join=join, is_searchable=field) add_row(name, val, join=join, is_searchable=field)
elif datatype is 'bool': elif datatype is 'bool':
add_row(name, _('Yes') if val else _('No')) add_row(name, _('Yes') if val else _('No'))
elif datatype is 'int' or datatype is 'float': elif datatype is 'int' or datatype is 'float':
if val is not undefined and val is not None:
fmt = (fm.display or {}).number_format fmt = (fm.display or {}).number_format
if fmt: if fmt:
val = fmt.format(val) val = fmt.format(val)