Content server: /mobile fix display of undefined dates

This commit is contained in:
Kovid Goyal 2016-09-28 09:03:51 +05:30
parent f608f1545a
commit 698740c4a7
2 changed files with 9 additions and 5 deletions

View File

@ -20,7 +20,7 @@ from calibre.ebooks.metadata import fmt_sidx
from calibre.constants import __appname__
from calibre import human_readable, isbytestring
from calibre.utils.cleantext import clean_xml_chars
from calibre.utils.date import utcfromtimestamp, as_local_time
from calibre.utils.date import utcfromtimestamp, as_local_time, is_date_undefined
from calibre.utils.filenames import ascii_filename
from calibre.utils.icu import sort_key
@ -260,7 +260,11 @@ class MobileServer(object):
no_tag_count=True)
book['title'] = record[FM['title']]
for x in ('timestamp', 'pubdate'):
book[x] = strftime('%d %b, %Y', as_local_time(record[FM[x]]))
dval = record[FM[x]]
if is_date_undefined(dval):
book[x] = ''
else:
book[x] = strftime('%d %b, %Y', as_local_time(dval))
book['id'] = record[FM['id']]
books.append(book)
for key in CKEYS:

View File

@ -17,7 +17,7 @@ from calibre.srv.errors import HTTPRedirect, HTTPBadRequest
from calibre.srv.routes import endpoint
from calibre.srv.utils import get_library_data, http_date
from calibre.utils.cleantext import clean_xml_chars
from calibre.utils.date import timestampfromdt, dt_as_local
from calibre.utils.date import timestampfromdt, dt_as_local, is_date_undefined
# /mobile {{{
def clean(x):
@ -177,8 +177,8 @@ def build_index(books, num, search, sort, order, start, total, url_base, field_m
first = E.span(u'\u202f%s %s by %s' % (book.title, series,
authors_to_string(book.authors)), class_='first-line')
div.append(first)
second = E.span(u'%s %s %s' % (strftime('%d %b, %Y', t=dt_as_local(book.timestamp).timetuple()),
tags, ctext), class_='second-line')
ds = '' if is_date_undefined(book.timestamp) else strftime('%d %b, %Y', t=dt_as_local(book.timestamp).timetuple())
second = E.span(u'%s %s %s' % (ds, tags, ctext), class_='second-line')
div.append(second)
books_table.append(E.tr(thumbnail, data))