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

2
BUGs
View File

@@ -1,4 +1,4 @@
#### BUGS (next-16)
#### BUGS (next-17)
### DB/back-end
BUG-2: series does not deal with calcd_rating...

1
README
View File

@@ -30,7 +30,6 @@ sudo docker-compose -f /srv/docker/config/docker-compose.yml up bookdb_web
########################################################### TODOS (next 29):
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
TODO-27: from missing, exclude any series where the only books we have are SOLD
TODO-05: should deleting really just ask if want to mark it as SOLD? IN FACT, make delete button disabled until its sold... (and a tooltip to explain)
TODO-09: show books to buy view / printable

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():

View File

@@ -122,7 +122,12 @@
<script src="https://cdn.datatables.net/1.10.22/js/dataTables.bootstrap4.min.js"></script>
<script>
$(document).ready(function() {
$('#book_table').DataTable( { 'pageLength': 20, 'lengthMenu': [[10, 20, 50, -1], [10, 20, 50, "All"]] } );
{% if 'Author(s)' in order_by %}
{% set o = "'order': [[ 1, 'asc' ]]," %}
{% else %}
{% set o = "" %}
{% endif %}
document.bookdb_dt = $('#book_table').DataTable( { 'pageLength': 20, {{o|safe}} 'lengthMenu': [[10, 20, 50, -1], [10, 20, 50, "All"]] } );
} );
</script>
{%block script_content %}{% endblock script_content %}