From a6211928dfdc8535937c43db18f41ad6cb74737d Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sat, 9 Jan 2021 00:45:10 +1100 Subject: [PATCH] completed TODO-12: missing books --- README | 1 - main.py | 16 ++++++++++++++++ templates/base.html | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README b/README index 0a0cf0a..38aa76d 100644 --- a/README +++ b/README @@ -31,7 +31,6 @@ sudo docker-compose -f /srv/docker/config/docker-compose.yml up bookdb_web ########################################################### TODOS (next 27): TODO-09: show books to buy view / printable -TODO-12: show books missing from a series (I own only some of them) TODO-13: show books on wish list TODO-14: show books that need replacing TODO-15: show books I have sold diff --git a/main.py b/main.py index 215da45..f00c4c4 100644 --- a/main.py +++ b/main.py @@ -654,6 +654,22 @@ 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 ) +@app.route("/missing_books", methods=["GET"]) +def missing_books(): + tmp = db.engine.execute("select s.*, count(bsl.book_num) from book_series_link bsl, series s where bsl.book_num is not null and s.id = bsl.series_id group by s.id order by s.title") + books=[] + for t in tmp: + if t.num_books != t.count: + bsl=Book_Series_Link.query.filter( Book_Series_Link.series_id==t.id ).order_by(Book_Series_Link.book_num).all() + missing=[] + for cnt in range(1,t.num_books+1): + missing.append( cnt ) + for b in bsl: + missing.remove( b.book_num ) + # turn missing from array into string, and strip 0 and last char (the square brackets) + books.append( { 'id': t.id, 'title': t.title, 'num_books': t.num_books, 'missing': str(missing)[1:-1] } ) + return render_template("missing.html", books=books ) + @app.route("/", methods=["GET"]) def main_page(): return render_template("base.html", alert=st.GetAlert(), message=st.GetMessage()) diff --git a/templates/base.html b/templates/base.html index 210efe4..e6f9201 100644 --- a/templates/base.html +++ b/templates/base.html @@ -49,6 +49,7 @@ Show All Show Books on shelf Show Unrated_Books + Show Missing Books Show Stats