From b6da3c3153e893c52b166163f1e4426da0a1d695 Mon Sep 17 00:00:00 2001 From: Jack Darlington Date: Thu, 2 Mar 2017 23:56:07 +0000 Subject: [PATCH] Fix for read/unread for anonymous users --- cps/templates/detail.html | 2 ++ cps/web.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cps/templates/detail.html b/cps/templates/detail.html index 9920046d..9fc6def3 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -107,6 +107,7 @@

{% endif %} + {% if not g.user.is_anonymous() %}

Read @@ -119,6 +120,7 @@

+ {% endif %} {% if entry.comments|length > 0 and entry.comments[0].text|length > 0%} diff --git a/cps/web.py b/cps/web.py index 44355cd0..c4045ba1 100755 --- a/cps/web.py +++ b/cps/web.py @@ -1141,9 +1141,12 @@ def show_book(id): #return render_title_template('detail.html', entry=entries, cc=cc, # title=entries.title, books_shelfs=book_in_shelfs) - matching_have_read_book=ub.session.query(ub.ReadBook).filter(ub.and_(ub.ReadBook.user_id == int(current_user.id), + if not current_user.is_anonymous(): + matching_have_read_book=ub.session.query(ub.ReadBook).filter(ub.and_(ub.ReadBook.user_id == int(current_user.id), ub.ReadBook.book_id == id)).all() - have_read=len(matching_have_read_book) > 0 and matching_have_read_book[0].is_read + have_read=len(matching_have_read_book) > 0 and matching_have_read_book[0].is_read + else: + have_read=None return render_title_template('detail.html', entry=entries, cc=cc, title=entries.title, books_shelfs=book_in_shelfs, have_read=have_read)