From cd7a77ff6b98e979574b1963ce4061df53a17407 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sat, 9 Jan 2021 01:13:26 +1100 Subject: [PATCH] completed TODOs 13, 14, 15, 16 - views of subsets of books. Added 2 new TODOs to enhance their output / make the views better --- README | 8 +++----- main.py | 23 ++++++++++++++++++++++- templates/base.html | 4 ++++ templates/books.html | 24 ++++++++++++++---------- templates/missing.html | 16 ++++++++++++++++ 5 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 templates/missing.html diff --git a/README b/README index 38aa76d..185ff01 100644 --- a/README +++ b/README @@ -29,12 +29,8 @@ sudo docker-compose -f /srv/docker/config/docker-compose.yml up bookdb_web MUST use form.errors when we have a validator that is fancier than not empty (year_published in book and num_books in series SO FAR) -########################################################### TODOS (next 27): +########################################################### TODOS (next 29): TODO-09: show books to buy view / printable -TODO-13: show books on wish list -TODO-14: show books that need replacing -TODO-15: show books I have sold -TODO-16: show books with poor rating TODO-17: view list of possible duplicate books by title TODO-18: consider which of the 'books maybe not valid' reports make sense still - can you even have an N/A publisher now for example? @@ -49,3 +45,5 @@ TODO-20: ORM all books load is slow TODO-21: allow a way to add a book as a child of another existing book (opposite of rem_sub_book) TODO-26: gunicorn and/or more modern non-flask??? +TODO-27: from missing, exclude any series where the only books we have are SOLD +TODO-28: make books.html have page_title? and pass in a 'print these cols'... at least for poor ratings, etc. so we can hide dud columns, and show more useful ones diff --git a/main.py b/main.py index f00c4c4..e48666d 100644 --- a/main.py +++ b/main.py @@ -666,10 +666,31 @@ def missing_books(): 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) + # 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("/wishlist", methods=["GET"]) +def wishlist(): + books = Book.query.join(Owned).filter(Owned.name=='On Wish List').all() + return render_template("books.html", books=books ) + +@app.route("/needs_replacing", methods=["GET"]) +def needs_replacing(): + books = Book.query.join(Condition,Owned).filter(Condition.name=='Needs Replacing',Owned.name=='Currently Owned').all() + return render_template("books.html", books=books ) + +@app.route("/sold", methods=["GET"]) +def sold_books(): + books = Book.query.join(Owned).filter(Owned.name=='Sold').all() + return render_template("books.html", books=books ) + +@app.route("/poor_rating", methods=["GET"]) +def poor_rating_books(): + books = Book.query.join(Rating,Owned).filter(Rating.id>6,Rating.name!='Undefined',Owned.name=='Currently Owned').all() + return render_template("books.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 e6f9201..c8cbfb1 100644 --- a/templates/base.html +++ b/templates/base.html @@ -49,7 +49,11 @@ Show All Show Books on shelf Show Unrated_Books + Show Books on wishlist Show Missing Books + Show Books that scored < 5/10 + Show Books that Need Replacing + Show Books that have been Sold Show Stats diff --git a/templates/books.html b/templates/books.html index 23d79d3..94b24ed 100644 --- a/templates/books.html +++ b/templates/books.html @@ -31,16 +31,20 @@ {% if not InDBox %} {{ GetPublisherById(book.publisher)}} - - {% set cond = GetConditionById(book.condition) %} - {% if cond == "Good" %} - - {% elif cond == "Average" %} - - {% else %} - - {% endif %} - + {% set cond = GetConditionById(book.condition) %} + {% if cond == "N/A" %} + N/A + {% else %} + + {% if cond == "Good" %} + + {% elif cond == "Average" %} + + {% elif cond == "Needs Replacing" %} + + {% endif %} + + {% endif %} {{ GetOwnedById(book.owned)}} {% endif %} {{ GetCovertypeById(book.covertype) }} diff --git a/templates/missing.html b/templates/missing.html new file mode 100644 index 0000000..4ba449c --- /dev/null +++ b/templates/missing.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block main_content %} + +

Missing Books

+ + + + + + {% for obj in books %} + + {% endfor %} + +
BooksSeriesNumber of Books in Series
{{obj.missing}}{{obj.title}}{{obj.num_books}}
+{% endblock main_content %}