From 3c9f8b151d299f316469661c425380f9cce679a0 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 1 Oct 2017 18:41:19 +0200 Subject: [PATCH] added check for anonymous session in read_books, otherwise current_user.id is not defined --- cps/web.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cps/web.py b/cps/web.py index 70903812..c35d978e 100755 --- a/cps/web.py +++ b/cps/web.py @@ -1713,15 +1713,21 @@ def feed_get_cover(book_id): def render_read_books(page, are_read, as_xml=False): - readBooks = ub.session.query(ub.ReadBook).filter(ub.ReadBook.user_id == int(current_user.id)).filter(ub.ReadBook.is_read == True).all() - readBookIds = [x.book_id for x in readBooks] - if are_read: - db_filter = db.Books.id.in_(readBookIds) - else: - db_filter = ~db.Books.id.in_(readBookIds) + if not current_user.is_anonymous(): + readBooks = ub.session.query(ub.ReadBook).filter(ub.ReadBook.user_id == int(current_user.id)).filter(ub.ReadBook.is_read == True).all() + readBookIds = [x.book_id for x in readBooks] + if are_read: + db_filter = db.Books.id.in_(readBookIds) + else: + db_filter = ~db.Books.id.in_(readBookIds) + + entries, random, pagination = fill_indexpage(page, db.Books, + db_filter, db.Books.timestamp.desc()) + else: + entries = [] + random = False + pagination = Pagination(page, 1, 0) - entries, random, pagination = fill_indexpage(page, db.Books, - db_filter, db.Books.timestamp.desc()) if as_xml: xml = render_title_template('feed.xml', entries=entries, pagination=pagination) response = make_response(xml)