From aae81c3d24c03d761dca59d4469f9d8c2b0ff1df Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 11 Jul 2021 12:52:35 +0200 Subject: [PATCH] Fix #2048 (Display book title in reader) --- cps/jinjia.py | 5 +---- cps/templates/detail.html | 2 +- cps/templates/read.html | 2 +- cps/templates/readcbr.html | 2 +- cps/templates/readdjvu.html | 2 +- cps/templates/readpdf.html | 2 +- cps/templates/readtxt.html | 2 +- cps/web.py | 17 +++++++++++------ 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/cps/jinjia.py b/cps/jinjia.py index de34cc86..23f727ab 100644 --- a/cps/jinjia.py +++ b/cps/jinjia.py @@ -113,10 +113,7 @@ def yesno(value, yes, no): @jinjia.app_template_filter('formatfloat') def formatfloat(value, decimals=1): - formatedstring = '%d' % value - if (value % 1) != 0: - formatedstring = ('%s.%d' % (formatedstring, (value % 1) * 10**decimals)).rstrip('0') - return formatedstring + return ('{0:.' + str(decimals) + 'g}').format(value) @jinjia.app_template_filter('formatseriesindex') diff --git a/cps/templates/detail.html b/cps/templates/detail.html index e5a67cde..ccad60c2 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -122,7 +122,7 @@ {% endif %} {% if entry.series|length > 0 %} -

{{_('Book')}} {{entry.series_index}} {{_('of')}} {{entry.series[0].name}}

+

{{_('Book')}} {{entry.series_index|formatfloat(2)}} {{_('of')}} {{entry.series[0].name}}

{% endif %} {% if entry.languages.__len__() > 0 %} diff --git a/cps/templates/read.html b/cps/templates/read.html index b38f783c..3d2566e0 100644 --- a/cps/templates/read.html +++ b/cps/templates/read.html @@ -3,7 +3,7 @@ - ePub Reader + {{_('epub Reader')}} | {{title}} diff --git a/cps/templates/readcbr.html b/cps/templates/readcbr.html index bad5f1f6..411e3fdd 100644 --- a/cps/templates/readcbr.html +++ b/cps/templates/readcbr.html @@ -1,10 +1,10 @@ - Comic Reader + {{_('Comic Reader')}} | {{title}} diff --git a/cps/templates/readdjvu.html b/cps/templates/readdjvu.html index c192ffcb..9771b7c9 100644 --- a/cps/templates/readdjvu.html +++ b/cps/templates/readdjvu.html @@ -7,7 +7,7 @@ -Djvu HTML5 browser demo +{{_('DJVU Reader')}} | {{title}} diff --git a/cps/templates/readpdf.html b/cps/templates/readpdf.html index 7af417ea..586625cc 100644 --- a/cps/templates/readpdf.html +++ b/cps/templates/readpdf.html @@ -26,7 +26,7 @@ See https://github.com/adobe-type-tools/cmap-resources - {{_('PDF reader')}} + {{_('PDF Reader')}} | {{title}} diff --git a/cps/templates/readtxt.html b/cps/templates/readtxt.html index da862fb2..ea294948 100644 --- a/cps/templates/readtxt.html +++ b/cps/templates/readtxt.html @@ -3,7 +3,7 @@ - {{_('Basic txt Reader')}} + {{_('txt Reader')}} | {{title}} diff --git a/cps/web.py b/cps/web.py index ba3c5ae3..a14afb68 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1680,28 +1680,33 @@ def read_book(book_id, book_format): ub.Bookmark.format == book_format.upper())).first() if book_format.lower() == "epub": log.debug(u"Start epub reader for %d", book_id) - return render_title_template('read.html', bookid=book_id, title=_(u"Read a Book"), bookmark=bookmark) + return render_title_template('read.html', bookid=book_id, title=book.title, bookmark=bookmark) elif book_format.lower() == "pdf": log.debug(u"Start pdf reader for %d", book_id) - return render_title_template('readpdf.html', pdffile=book_id, title=_(u"Read a Book")) + return render_title_template('readpdf.html', pdffile=book_id, title=book.title) elif book_format.lower() == "txt": log.debug(u"Start txt reader for %d", book_id) - return render_title_template('readtxt.html', txtfile=book_id, title=_(u"Read a Book")) + return render_title_template('readtxt.html', txtfile=book_id, title=book.title) elif book_format.lower() == "djvu": log.debug(u"Start djvu reader for %d", book_id) - return render_title_template('readdjvu.html', djvufile=book_id, title=_(u"Read a Book")) + return render_title_template('readdjvu.html', djvufile=book_id, title=book.title) else: for fileExt in constants.EXTENSIONS_AUDIO: if book_format.lower() == fileExt: entries = calibre_db.get_filtered_book(book_id) log.debug(u"Start mp3 listening for %d", book_id) return render_title_template('listenmp3.html', mp3file=book_id, audioformat=book_format.lower(), - title=_(u"Read a Book"), entry=entries, bookmark=bookmark) + entry=entries, bookmark=bookmark) for fileExt in ["cbr", "cbt", "cbz"]: if book_format.lower() == fileExt: all_name = str(book_id) + title = book.title + if len(book.series): + title = title + " - " + book.series[0].name + if book.series_index: + title = title + " #" + '{0:.2g}'.format(book.series_index) log.debug(u"Start comic reader for %d", book_id) - return render_title_template('readcbr.html', comicfile=all_name, title=_(u"Read a Book"), + return render_title_template('readcbr.html', comicfile=all_name, title=title, extension=fileExt) log.debug(u"Oops! Selected book title is unavailable. File does not exist or is not accessible") flash(_(u"Oops! Selected book title is unavailable. File does not exist or is not accessible"), category="error")