From 35d92e0ab66e9b89c37a7d83de509e7c3e5dad04 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sun, 10 Jan 2021 00:21:50 +1100 Subject: [PATCH] Fixed BUG-18 -> cannot find book --- BUGs | 3 +-- main.py | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/BUGs b/BUGs index ec8696d..4a651a1 100644 --- a/BUGs +++ b/BUGs @@ -1,5 +1,4 @@ -#### BUGS (next-18) -BUG-18: delete a book, then go to that URL and you get odd DB errors, rather than book not found +#### BUGS (next-19) ### DB/back-end BUG-2: series does not deal with calcd_rating... diff --git a/main.py b/main.py index 1adc2e2..76b563a 100644 --- a/main.py +++ b/main.py @@ -439,13 +439,13 @@ def new_book(): book = Book( title=request.form['title'], owned=request.form['owned'], covertype=request.form['covertype'], condition=request.form['condition'], publisher=request.form['publisher'], year_published=request.form['year_published'], rating=request.form['rating'], notes=request.form['notes'], blurb=request.form['blurb'], genre=book_genres, author=book_authors ) db.session.add(book) db.session.commit() - # this is a sub-book we have added + # this is a sub-book we have added if 'parent_id' in request.form: db.engine.execute( "insert into book_sub_book_link ( book_id, sub_book_id, sub_book_num ) values ( {}, {}, (select COALESCE(MAX(sub_book_num),0)+1 from book_sub_book_link where book_id = {}) )".format( request.form['parent_id'], book.id, request.form['parent_id'] ) ) parent=Book.query.get(request.form['parent_id']) if len(parent.series) > 0: # we have added a sub-book to something in a series - # already, so add a bsl for the next book_num + # already, so add a bsl for the next book_num for s in parent.bsl: db.engine.execute( "insert into book_series_link ( series_id, book_id, book_num ) values ( {}, {}, (select COALESCE(MAX(book_num),0)+1 from book_series_link where series_id={}) )".format( s.series_id, book.id, s.series_id ) ) db.session.commit() @@ -593,6 +593,11 @@ def book(id): st.SetMessage(message) else: book = Book.query.get(id) + if book == None: + st.SetAlert("danger") + st.SetMessage("Cannot find Book (id={})".format(id)) + return render_template("base.html", alert=st.GetAlert(), message=st.GetMessage()) + book_form=BookForm(obj=book) author_list = GetAuthors()