now handle series book numbering in the books on shelf page. Fixes BUG-22
This commit is contained in:
45
main.py
45
main.py
@@ -13,6 +13,7 @@ from flask_login import LoginManager, login_user, login_required, UserMixin, cur
|
||||
from flask_ldap3_login.forms import LDAPLoginForm
|
||||
import re
|
||||
import os
|
||||
import contextlib
|
||||
|
||||
####################################### Flask App globals #######################################
|
||||
app = Flask(__name__)
|
||||
@@ -767,9 +768,51 @@ def rem_parent_books_from_series(pid):
|
||||
@app.route("/books_on_shelf", methods=["GET"])
|
||||
@login_required
|
||||
def books_on_shelf():
|
||||
# start with all books owned, but it includes sub-books, so remove them...
|
||||
books = Book.query.join(Owned).filter(Owned.name=='Currently Owned').all()
|
||||
RemSubs(books)
|
||||
return render_template("books.html", books=books, page_title="Books on Shelf", order_by="Author(s)", show_cols='', hide_cols='' )
|
||||
|
||||
# now we order them (they are in author order, but not inside that authors list)
|
||||
|
||||
# because a book can be in multiple series, without any ordering we need to find
|
||||
# any book that is in a series, then go through each series to find the one with
|
||||
# the most books in it. THEN we need to get all those books and put them in the
|
||||
# ordered_books array, and remove them from the books array
|
||||
ordered_books=[]
|
||||
handle_parent=[]
|
||||
currently_owned = Owned.query.filter(Owned.name=='Currently Owned').one()
|
||||
print( f"co={currently_owned}" )
|
||||
for b in books:
|
||||
if b.series:
|
||||
# find biggest Series
|
||||
max_num_books=0
|
||||
for s in b.series:
|
||||
if max_num_books < s.num_books:
|
||||
max_num_books = s.num_books
|
||||
max_series_id= s.id
|
||||
|
||||
#order all books (sub-books too here!) in this series with the most books
|
||||
bsl=Book_Series_Link.query.filter( Book_Series_Link.series_id==max_series_id ).order_by(Book_Series_Link.book_num).all()
|
||||
for tmp in bsl:
|
||||
tmp_b = Book.query.get(tmp.book_id)
|
||||
# skip any books that are not owned sneaking back in
|
||||
if tmp_b.owned != currently_owned.id:
|
||||
continue
|
||||
if tmp_b.IsChild():
|
||||
# this child book wont be in books, but its parent will -> use it instead
|
||||
if tmp_b.parent[0].id not in handle_parent:
|
||||
books.remove(tmp_b.parent[0])
|
||||
ordered_books.append(tmp_b.parent[0])
|
||||
handle_parent.append(tmp_b.parent[0].id)
|
||||
else:
|
||||
if tmp_b.id not in handle_parent:
|
||||
books.remove(tmp_b)
|
||||
ordered_books.append(tmp_b)
|
||||
else:
|
||||
# book not in a series or a sub-book, so just add this book to the ordered list
|
||||
ordered_books.append(b)
|
||||
|
||||
return render_template("books.html", books=ordered_books, page_title="Books on Shelf", order_by="Author(s)", show_cols='', hide_cols='' )
|
||||
|
||||
@app.route("/unrated_books", methods=["GET"])
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user