Bugfix for non existent rating, language, and user downloaded books

This commit is contained in:
Ozzie Isaacs 2023-04-18 20:53:55 +02:00
parent de4d6ec7df
commit f2369609e8
1 changed files with 17 additions and 16 deletions

View File

@ -484,7 +484,8 @@ def render_downloaded_books(page, order, user_id):
user_id = int(user_id) user_id = int(user_id)
else: else:
user_id = current_user.id user_id = current_user.id
if current_user.check_visibility(constants.SIDEBAR_DOWNLOAD): user = ub.session.query(ub.User).filter(ub.User.id == user_id).first()
if current_user.check_visibility(constants.SIDEBAR_DOWNLOAD) and user:
entries, random, pagination = calibre_db.fill_indexpage(page, entries, random, pagination = calibre_db.fill_indexpage(page,
0, 0,
db.Books, db.Books,
@ -499,7 +500,6 @@ def render_downloaded_books(page, order, user_id):
if not (calibre_db.session.query(db.Books).filter(calibre_db.common_filters()) if not (calibre_db.session.query(db.Books).filter(calibre_db.common_filters())
.filter(db.Books.id == book.Books.id).first()): .filter(db.Books.id == book.Books.id).first()):
ub.delete_download(book.Books.id) ub.delete_download(book.Books.id)
user = ub.session.query(ub.User).filter(ub.User.id == user_id).first()
return render_title_template('index.html', return render_title_template('index.html',
random=random, random=random,
entries=entries, entries=entries,
@ -618,21 +618,19 @@ def render_ratings_books(page, book_id, order):
db.Series, db.Series,
db.books_ratings_link, db.Ratings) db.books_ratings_link, db.Ratings)
title = _("Rating: None") title = _("Rating: None")
rating = -1
else: else:
name = calibre_db.session.query(db.Ratings).filter(db.Ratings.id == book_id).first() name = calibre_db.session.query(db.Ratings).filter(db.Ratings.id == book_id).first()
entries, random, pagination = calibre_db.fill_indexpage(page, 0, if name:
db.Books, entries, random, pagination = calibre_db.fill_indexpage(page, 0,
db.Books.ratings.any(db.Ratings.id == book_id), db.Books,
[order[0][0]], db.Books.ratings.any(db.Ratings.id == book_id),
True, config.config_read_column) [order[0][0]],
title = _("Rating: %(rating)s stars", rating=int(name.rating / 2)) True, config.config_read_column)
rating = name.rating title = _("Rating: %(rating)s stars", rating=int(name.rating / 2))
if title and rating <= 10: else:
return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id, abort(404)
title=title, page="ratings", order=order[1]) return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
else: title=title, page="ratings", order=order[1])
abort(404)
def render_formats_books(page, book_id, order): def render_formats_books(page, book_id, order):
@ -688,6 +686,8 @@ def render_language_books(page, name, order):
try: try:
if name.lower() != "none": if name.lower() != "none":
lang_name = isoLanguages.get_language_name(get_locale(), name) lang_name = isoLanguages.get_language_name(get_locale(), name)
if lang_name == "Unknown":
abort(404)
else: else:
lang_name = _("None") lang_name = _("None")
except KeyError: except KeyError:
@ -1036,7 +1036,8 @@ def ratings_list():
.filter(or_(db.Ratings.rating == None, db.Ratings.rating == 0)) .filter(or_(db.Ratings.rating == None, db.Ratings.rating == 0))
.filter(calibre_db.common_filters()) .filter(calibre_db.common_filters())
.count()) .count())
entries.append([db.Category(_("None"), "-1", -1), no_rating_count]) if no_rating_count:
entries.append([db.Category(_("None"), "-1", -1), no_rating_count])
entries = sorted(entries, key=lambda x: x[0].rating, reverse=not order_no) entries = sorted(entries, key=lambda x: x[0].rating, reverse=not order_no)
return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=list(), return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=list(),
title=_("Ratings list"), page="ratingslist", data="ratings", order=order_no) title=_("Ratings list"), page="ratingslist", data="ratings", order=order_no)