From e5593d9a7f4bd66d1c68ad0afecb237dd09a9312 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sat, 16 Mar 2019 21:14:01 +0100 Subject: [PATCH] Integrated author in sorting functions --- cps/templates/author.html | 16 ++++++- cps/templates/detail.html | 2 +- cps/templates/discover.html | 4 +- cps/templates/index.html | 8 ++-- cps/templates/list.html | 2 +- cps/templates/search.html | 4 +- cps/templates/shelf.html | 4 +- cps/templates/shelfdown.html | 2 +- cps/web.py | 81 +++++++++++++++++++----------------- 9 files changed, 70 insertions(+), 53 deletions(-) diff --git a/cps/templates/author.html b/cps/templates/author.html index ce97d846..4f6d54e2 100644 --- a/cps/templates/author.html +++ b/cps/templates/author.html @@ -22,6 +22,18 @@ {% if author is not none %}

{{_("In Library")}}

{% endif %} +
{% if entries[0] %} {% for entry in entries %} @@ -45,7 +57,7 @@ {% if not loop.first %} & {% endif %} - {{author.name.replace('|',',')|shortentitle(30)}} + {{author.name.replace('|',',')|shortentitle(30)}} {% if loop.last %} (...) {% endif %} @@ -53,7 +65,7 @@ {% if not loop.first %} & {% endif %} - {{author.name.replace('|',',')|shortentitle(30)}} + {{author.name.replace('|',',')|shortentitle(30)}} {% endif %} {% endfor %}

diff --git a/cps/templates/detail.html b/cps/templates/detail.html index 6cd61379..fcc4ac5f 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -99,7 +99,7 @@

{{entry.title|shortentitle(40)}}

{% for author in entry.authors %} - {{author.name.replace('|',',')}} + {{author.name.replace('|',',')}} {% if not loop.last %} & {% endif %} diff --git a/cps/templates/discover.html b/cps/templates/discover.html index d23f32d7..650bdeda 100644 --- a/cps/templates/discover.html +++ b/cps/templates/discover.html @@ -22,7 +22,7 @@ {% if not loop.first %} & {% endif %} - {{author.name.replace('|',',')|shortentitle(30)}} + {{author.name.replace('|',',')|shortentitle(30)}} {% if loop.last %} (...) {% endif %} @@ -30,7 +30,7 @@ {% if not loop.first %} & {% endif %} - {{author.name.replace('|',',')|shortentitle(30)}} + {{author.name.replace('|',',')|shortentitle(30)}} {% endif %} {% endfor %}

diff --git a/cps/templates/index.html b/cps/templates/index.html index 478379ae..19cd8447 100755 --- a/cps/templates/index.html +++ b/cps/templates/index.html @@ -25,7 +25,7 @@ web. {% for entry in random %} {% if not loop.first %} & {% endif %} - {{author.name.replace('|',',')|shortentitle(30)}} + {{author.name.replace('|',',')|shortentitle(30)}} {% if loop.last %} (...) {% endif %} @@ -33,7 +33,7 @@ web. {% for entry in random %} {% if not loop.first %} & {% endif %} - {{author.name.replace('|',',')|shortentitle(30)}} + {{author.name.replace('|',',')|shortentitle(30)}} {% endif %} {% endfor %}

@@ -92,7 +92,7 @@ web. {% for entry in random %} {% if not loop.first %} & {% endif %} - {{author.name.replace('|',',')|shortentitle(30)}} + {{author.name.replace('|',',')|shortentitle(30)}} {% if loop.last %} (...) {% endif %} @@ -100,7 +100,7 @@ web. {% for entry in random %} {% if not loop.first %} & {% endif %} - {{author.name.replace('|',',')|shortentitle(30)}} + {{author.name.replace('|',',')|shortentitle(30)}} {% endif %} {% endfor %} {% for format in entry.data %} diff --git a/cps/templates/list.html b/cps/templates/list.html index 709b7e32..542104d0 100644 --- a/cps/templates/list.html +++ b/cps/templates/list.html @@ -19,7 +19,7 @@ {% for entry in entries %}
{{entry.count}}
-
+
{% if entry.name %}
{% for number in range(entry.name) %} diff --git a/cps/templates/search.html b/cps/templates/search.html index 8706d42e..60b5b1dd 100644 --- a/cps/templates/search.html +++ b/cps/templates/search.html @@ -50,7 +50,7 @@ {% if not loop.first %} & {% endif %} - {{author.name.replace('|',',')|shortentitle(30)}} + {{author.name.replace('|',',')|shortentitle(30)}} {% if loop.last %} (...) {% endif %} @@ -58,7 +58,7 @@ {% if not loop.first %} & {% endif %} - {{author.name.replace('|',',')|shortentitle(30)}} + {{author.name.replace('|',',')|shortentitle(30)}} {% endif %} {% endfor %}

diff --git a/cps/templates/shelf.html b/cps/templates/shelf.html index 0e379750..24aff3b4 100644 --- a/cps/templates/shelf.html +++ b/cps/templates/shelf.html @@ -35,7 +35,7 @@ {% if not loop.first %} & {% endif %} - {{author.name.replace('|',',')|shortentitle(30)}} + {{author.name.replace('|',',')|shortentitle(30)}} {% if loop.last %} (...) {% endif %} @@ -43,7 +43,7 @@ {% if not loop.first %} & {% endif %} - {{author.name.replace('|',',')|shortentitle(30)}} + {{author.name.replace('|',',')|shortentitle(30)}} {% endif %} {% endfor %}

diff --git a/cps/templates/shelfdown.html b/cps/templates/shelfdown.html index 53c845e0..b2ac947f 100644 --- a/cps/templates/shelfdown.html +++ b/cps/templates/shelfdown.html @@ -37,7 +37,7 @@

{{entry.title|shortentitle}}

{% for author in entry.authors %} - {{author.name.replace('|',',')}} + {{author.name.replace('|',',')}} {% if not loop.last %} & {% endif %} diff --git a/cps/web.py b/cps/web.py index 589f93e3..69d1fcd4 100644 --- a/cps/web.py +++ b/cps/web.py @@ -464,19 +464,20 @@ def index(page): title=_(u"Recently Added Books"), page="root") -@web.route('//', defaults={'page': 1}) -@web.route('///') +@web.route('//', defaults={'page': 1, 'book_id': 1}) +@web.route('///', defaults={'page': 1}) +@web.route('////') @login_required_if_no_ano -def books_list(data,sort, page): +def books_list(data, sort, book_id, page): order = [db.Books.timestamp.desc()] if sort == 'pubnew': order = [db.Books.pubdate.desc()] if sort == 'pubold': order = [db.Books.pubdate] if sort == 'abc': - [db.Books.sort] + order = [db.Books.sort] if sort == 'zyx': - [db.Books.sort.desc()] + order = [db.Books.sort.desc()] if sort == 'new': order = [db.Books.timestamp.desc()] if sort == 'old': @@ -503,38 +504,44 @@ def books_list(data,sort, page): elif data == "read": return render_read_books(page, True, order=order) elif data == "hot": - if current_user.check_visibility(ub.SIDEBAR_HOT): - if current_user.show_detail_random(): - random = db.session.query(db.Books).filter(common_filters()) \ - .order_by(func.random()).limit(config.config_random_books) - else: - random = false() - off = int(int(config.config_books_per_page) * (page - 1)) - all_books = ub.session.query(ub.Downloads, ub.func.count(ub.Downloads.book_id)).order_by( - ub.func.count(ub.Downloads.book_id).desc()).group_by(ub.Downloads.book_id) - hot_books = all_books.offset(off).limit(config.config_books_per_page) - entries = list() - for book in hot_books: - downloadBook = db.session.query(db.Books).filter(common_filters()).filter( - db.Books.id == book.Downloads.book_id).first() - if downloadBook: - entries.append(downloadBook) - else: - ub.delete_download(book.Downloads.book_id) - # ub.session.query(ub.Downloads).filter(book.Downloads.book_id == ub.Downloads.book_id).delete() - # ub.session.commit() - numBooks = entries.__len__() - pagination = Pagination(page, config.config_books_per_page, numBooks) - return render_title_template('index.html', random=random, entries=entries, pagination=pagination, - title=_(u"Hot Books (most downloaded)"), page="hot") - else: - abort(404) + return render_hot_books(page) + elif data == "author": + return render_author_books(page, book_id, order) else: entries, random, pagination = fill_indexpage(page, db.Books, True, order) return render_title_template('index.html', random=random, entries=entries, pagination=pagination, title=_(u"Books"), page="newest") +def render_hot_books(page): + if current_user.check_visibility(ub.SIDEBAR_HOT): + if current_user.show_detail_random(): + random = db.session.query(db.Books).filter(common_filters()) \ + .order_by(func.random()).limit(config.config_random_books) + else: + random = false() + off = int(int(config.config_books_per_page) * (page - 1)) + all_books = ub.session.query(ub.Downloads, ub.func.count(ub.Downloads.book_id)).order_by( + ub.func.count(ub.Downloads.book_id).desc()).group_by(ub.Downloads.book_id) + hot_books = all_books.offset(off).limit(config.config_books_per_page) + entries = list() + for book in hot_books: + downloadBook = db.session.query(db.Books).filter(common_filters()).filter( + db.Books.id == book.Downloads.book_id).first() + if downloadBook: + entries.append(downloadBook) + else: + ub.delete_download(book.Downloads.book_id) + # ub.session.query(ub.Downloads).filter(book.Downloads.book_id == ub.Downloads.book_id).delete() + # ub.session.commit() + numBooks = entries.__len__() + pagination = Pagination(page, config.config_books_per_page, numBooks) + return render_title_template('index.html', random=random, entries=entries, pagination=pagination, + title=_(u"Hot Books (most downloaded)"), page="hot") + else: + abort(404) + + @web.route("/author") @login_required_if_no_ano def author_list(): @@ -547,18 +554,16 @@ def author_list(): .group_by(func.upper(func.substr(db.Authors.sort,1,1))).all() for entry in entries: entry.Authors.name = entry.Authors.name.replace('|', ',') - return render_title_template('list.html', entries=entries, folder='web.author', charlist=charlist, - title=u"Author list", page="authorlist") + return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=charlist, + title=u"Author list", page="authorlist", data='author') else: abort(404) -@web.route("/author/", defaults={'page': 1}) -@web.route("/author//") -@login_required_if_no_ano -def author(book_id, page): +# ToDo wrong order function +def render_author_books(page, book_id, order): entries, __, pagination = fill_indexpage(page, db.Books, db.Books.authors.any(db.Authors.id == book_id), - [db.Series.name, db.Books.series_index], db.books_series_link, db.Series) + [order[0], db.Series.name, db.Books.series_index], db.books_series_link, db.Series) if entries is None: flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error") return redirect(url_for("web.index"))