From 336ae4b67fe9452312f3fde1f208792a339143ea Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Mon, 4 Jan 2021 22:28:35 +1100 Subject: [PATCH] TODO-6 (add books to loan) is now complete, so loans are now fully functional... the whole pybook is now at least functional, more features/validation to come :) --- BUGs | 3 ++- README | 2 +- main.py | 23 ++++++++++++++++++----- templates/base.html | 2 +- templates/books.html | 7 +++++-- templates/books_for_loan.html | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 10 deletions(-) diff --git a/BUGs b/BUGs index ca2a8f5..b3e90a7 100644 --- a/BUGs +++ b/BUGs @@ -1,4 +1,4 @@ -#### BUGS +#### BUGS (next-13) BUG-2: series does not deal with calcd_rating... - (on edit could, recalc as a catch-all, and obviously if we change a single book's rating, we should re-calc) @@ -8,3 +8,4 @@ BUG-6: author,series, etc. do not have explicit ordering like sub-books... sort - add/remove authors, and after save they are ordered by author.id, not order of addition (prob. needs book_author_link to have an auth_num) BUG-7: if you remove a series from a book, it won't appear in the series drop-down if it is the first 'missing' book in that series -- either reset the list, or show all series always? +BUG-12: remove loaned out books from results of search for books to add to a loan diff --git a/README b/README index a935d3c..dcf2e56 100644 --- a/README +++ b/README @@ -37,7 +37,6 @@ TODO-4: removing a subbook from a series - dont allow it & say remove sub book form parent book before we can act on this. OR: - popup with: this is a subbook, you want to remove the parent & all its sub books from the series? TODO-5: should deleting really just ask if want to mark it as SOLD? -TODO-6: need to add books to loan (on loan page, and via a book search?) TODO-8: show books on shelf list TODO-9: show books to buy view / printable TODO-11: show unrated books (with toggle to exclude those with missing in a series) @@ -56,3 +55,4 @@ TODO-19: icons on wish list, etc.? (not sure I really want them, but if so) TODO-20: ORM all books load is slow - should I lazy load all books (ajax the 2nd->last pages in, or not use ORM, and do a quick db.execute()....) TODO-21: allow a way to add a book as a child of another existing book (opposite of rem_sub_book) + diff --git a/main.py b/main.py index 02d5e37..54508c5 100644 --- a/main.py +++ b/main.py @@ -561,18 +561,31 @@ def stats(): @app.route("/rem_books_from_loan/", methods=["POST"]) def rem_books_from_loan(id): - print( "rem_books_from_loan for loan: {}".format( id ) ) for field in request.form: rem_id=int(re.findall( '\d+', field )[0]) - print( "field: {} -- so removing book id: {}".format( field, rem_id ) ) try: db.engine.execute("delete from book_loan_link where book_id = {} and loan_id = {}".format( rem_id, id )) db.session.commit() - except: + except SQLAlchemyError as e: st.SetAlert("danger") - st.SetMessage("Failed to remove books from loan!") + st.SetMessage("Failed to remove books from loan! -- {}".format( e.orig )) - print( "now redirect to /loan/{}".format(id) ) + print ("NOT SURE WHAT TO DO if we dont want output" ) + return redirect("/loan/{}".format(id)) + +@app.route("/add_books_to_loan/", methods=["POST"]) +def add_books_to_loan(id): + for field in request.form: + add_id=int(re.findall( '\d+', field )[0]) + try: + db.engine.execute("insert into book_loan_link (book_id, loan_id) values ( {}, {} )".format( add_id, id )) + print("insert into book_loan_link (book_id, loan_id) values ( {}, {} )".format( add_id, id )) + db.session.commit() + except SQLAlchemyError as e: + st.SetAlert("danger") + st.SetMessage("Failed to add books to loan! -- {}".format( e.orig )) + + print ("NOT SURE WHAT TO DO if we dont want output" ) return redirect("/loan/{}".format(id)) @app.route("/", methods=["GET"]) diff --git a/templates/base.html b/templates/base.html index 0f218fe..1593561 100644 --- a/templates/base.html +++ b/templates/base.html @@ -43,7 +43,7 @@
- +
diff --git a/templates/books.html b/templates/books.html index cba512a..23d79d3 100644 --- a/templates/books.html +++ b/templates/books.html @@ -3,8 +3,11 @@ {% if not InDBox %}

All Books

+ {% set tab_id = 'book_table' %} +{% else %} + {% set tab_id = 'addsel_table' %} {% endif %} - +
{% if not InDBox %} @@ -42,7 +45,7 @@ {% endif %} {% if InDBox %} - + {% endif %} {% endfor %} diff --git a/templates/books_for_loan.html b/templates/books_for_loan.html index 1d5d452..1410901 100644 --- a/templates/books_for_loan.html +++ b/templates/books_for_loan.html @@ -5,10 +5,17 @@ $('#bfl-remsel-btn').attr('disabled',false) } + function DeactivateBFLRemSelButton() + { + $('#bfl-remsel-btn').addClass('disabled') + $('#bfl-remsel-btn').attr('disabled',true) + } + function RemoveSelFromLoan() { var params=$("#book_table :input").serializeArray() $.post( "/rem_books_from_loan/" + {{loan_id}}, params, function(data) { + DeactivateBFLRemSelButton() $('#bfl-existing').load('/books_for_loan/' + {{loan_id}}, { 'InDBox' : 1 } ) } ) } @@ -18,10 +25,36 @@ $('#dbox').modal('show') $.post( "/books_for_loan/" + {{loan_id}}, function(data) {$('#bfl-existing').html(data) } ); } + function FindNewBFL() { $.post( "/search",{ 'term': $('#bfl-search-term').val(), 'InDBox': 1 }, function(data) { $('#bfl-new').html(data) ; $('#bfl-addsel-btn').show() } ); } + + function ActivateBFLAddSelButton() + { + $('#bfl-addsel-btn').removeClass('disabled') + $('#bfl-addsel-btn').attr('disabled',false) + } + + function DeactivateBFLAddSelButton() + { + $('#bfl-addsel-btn').addClass('disabled') + $('#bfl-addsel-btn').attr('disabled',true) + $('#bfl-addsel-btn').attr('style','display:none') + } + + function AddSelToLoan() + { + var params=$("#addsel_table :input").serializeArray() + $.post( "/add_books_to_loan/" + {{loan_id}}, params, function(data) { + DeactivateBFLAddSelButton() + DeactivateBFLRemSelButton() + $('#bfl-search-term').val('') + $('#bfl-new').html('') + $('#bfl-existing').load('/books_for_loan/' + {{loan_id}}, { 'InDBox' : 1 } ) + } ) + } {% if not InDBox %}
TitleAuthor(s){{ GetCovertypeById(book.covertype) }}