fixed books on shelf BUG-16 - author missing, its now using ORM with a HACK to remove subs not via ORM, and I also fixed datatable sorting by author for books on shelf via a param past into base.html

This commit is contained in:
2021-01-09 16:54:37 +11:00
parent 40e2ac1a34
commit bccfbadb39
4 changed files with 22 additions and 7 deletions

19
main.py
View File

@@ -231,6 +231,15 @@ def AddSubs(books):
books[index].parent_id = row.book_id
books[index].sub_book_num = row.sub_book_num
# HACK: Couldn't work out ORM to excluded sub_book self-ref, so using basic python
# loop to remove sub_books from list
def RemSubs(books):
subs = db.engine.execute ( "select * from book_sub_book_link" )
for row in subs:
for i, item in enumerate(books):
if item.id == row.sub_book_id:
books.remove(item)
####################################### GLOBALS #######################################
# allow jinja2 to call these python functions directly
app.jinja_env.globals['GetCovertypeById'] = GetCovertypeById
@@ -243,6 +252,7 @@ app.jinja_env.globals['ClearStatus'] = st.ClearMessage
app.jinja_env.globals['ListOfSeriesWithMissingBooks'] = ListOfSeriesWithMissingBooks
book_schema = BookSchema()
books_schema = BookSchema(many=True)
####################################### ROUTES #######################################
@app.route("/search", methods=["POST"])
@@ -647,13 +657,14 @@ def rem_parent_books_from_series(pid):
@app.route("/books_on_shelf", methods=["GET"])
def books_on_shelf():
books = db.engine.execute("select * from book where id not in ( select sub_book_id from book_sub_book_link ) and owned = (select id from owned where name = 'Currently Owned')")
return render_template("books.html", books=books )
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='' )
@app.route("/unrated_books", methods=["GET"])
def unrated_books():
books = db.engine.execute("select * from book where rating = (select id from rating where name = 'Undefined') and owned = (select id from owned where name = 'Currently Owned')")
return render_template("books.html", books=books )
books = Book.query.join(Condition,Owned).filter(Rating.name=='Undefined',Owned.name=='Currently Owned').all()
return render_template("books.html", books=books, page_title="Books with no rating", show_cols='Rating', hide_cols='' )
@app.route("/missing_books", methods=["GET"])
def missing_books():