From d4d37b96e33af8e5a1c9384239fba36d4c0fbbbe Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sat, 1 Jul 2023 15:11:00 +1000 Subject: [PATCH] fix dataTables ordering when I dont expect it to for books on shelf view --- main.py | 15 ++++++++++----- templates/base.html | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index a6b19e7..5d64682 100644 --- a/main.py +++ b/main.py @@ -909,7 +909,7 @@ def books_on_shelf(): # start with all books owned by title, but it includes sub-books, so remove them... # books = Book.query.join(Owned).filter(Owned.name=='Currently Owned').order_by(Book.title).all() - books = Book.query.join(Owned,Book_Author_Link,Author).filter(Owned.name=='Currently Owned',Book_Author_Link.author_num==1).order_by(Author.surname,Author.firstnames,Book.title).all() + books = Book.query.join(Owned).join(Book_Author_Link).join(Author).filter(Owned.name=='Currently Owned').filter(Book_Author_Link.author_num==1).order_by(Author.surname,Author.firstnames,Book.title).all() RemSubs(books) # because a book can be in multiple series, without any ordering we need to find @@ -951,6 +951,8 @@ def books_on_shelf(): 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='' ) + for o in ordered_books: + print( f"ord: {o.title}" ) return render_template("books.html", books=ordered_books, page_title="Books on Shelf", order_by="", show_cols='', hide_cols='' ) @app.route("/unrated_books", methods=["GET"]) @@ -1026,13 +1028,16 @@ def poor_rating_books(): @app.route("/fix_an") @login_required def fix_an(): + print("A") books=Book.query.all(); + print("B") for b in books: + print( f"process {b.title}") cnt=1 - for a in b.author: - bal=Book_Author_Link.query.filter(Book_Author_Link.book_id==b.id,Book_Author_Link.author_id==a.id,Book_Author_Link.author_num == 0 ).first() - bal.author_num=cnt - db.session.add(bal) + for a in b.bals: + print( f"process bal {cnt} for {b.title}") + a.author_num=cnt + db.session.add(a) cnt+=1 db.session.commit() return render_template("base.html", alert="success", message="Fixed author numbering" ) diff --git a/templates/base.html b/templates/base.html index a351464..d23a86d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -149,7 +149,7 @@ {% if 'Author(s)' in order_by %} {% set o = "'order': [[ 1, 'asc' ]]," %} {% else %} - {% set o = "" %} + {% set o = "'order': '', " %} {% endif %} document.bookdb_dt = $('#book_table').DataTable( { 'pageLength': 20, {{o|safe}} 'lengthMenu': [[10, 20, 50, -1], [10, 20, 50, "All"]] } ); } );