From 698740c4a730da028da91ff5afd5a230f576144e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 28 Sep 2016 09:03:51 +0530 Subject: [PATCH] Content server: /mobile fix display of undefined dates --- src/calibre/library/server/mobile.py | 8 ++++++-- src/calibre/srv/legacy.py | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/calibre/library/server/mobile.py b/src/calibre/library/server/mobile.py index 53991fe2d0..2effd855b7 100644 --- a/src/calibre/library/server/mobile.py +++ b/src/calibre/library/server/mobile.py @@ -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: diff --git a/src/calibre/srv/legacy.py b/src/calibre/srv/legacy.py index 8a34af8934..c09b0ef16e 100644 --- a/src/calibre/srv/legacy.py +++ b/src/calibre/srv/legacy.py @@ -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))