From 4c442e1fea1d0350be70acda2ff39658d4fbda9d Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sat, 2 Jan 2021 18:53:52 +1100 Subject: [PATCH] fixed BUG-11, parent was both an array (in Book) and not an array in QuickBook, so made them arrays to keep with ORM-way --- BUGs | 38 +++++++++++++++++++------------------- main.py | 25 +++++++++++++++++-------- templates/book.html | 21 ++++++++++++++------- 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/BUGs b/BUGs index df02359..b24b687 100644 --- a/BUGs +++ b/BUGs @@ -1,28 +1,28 @@ #### BUGS -BUG-1: loan card is not in right div anymore (since series stuff?) - http://mara.ddp.net:5000/book/1513 +BUG-1: loan card is not in right div anymore (since series stuff?) + - http://mara.ddp.net:5000/book/1513 -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) +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) -BUG-3 alter a condition, covertype, etc. and its not in drop-down list (even though db look via index is correct, e.g books.html shows updated covertype) +BUG-3: alter a condition, covertype, etc. and its not in drop-down list (even though db look via index is correct, e.g books.html shows updated covertype) -BUG-4 show books, only shows first author +BUG-4: show books, only shows first author -BUG-6 author,series, etc. do not have explicit ordering like sub-books... sort of irritating / needs code and DB fix - * 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-6: author,series, etc. do not have explicit ordering like sub-books... sort of irritating / needs code and DB fix + - 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-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-8 if you add a sub-book, then fail to validate (say no genre), then it takes you back, you click a genre (BUT it has lost th eparent association), so it adds a book, not a sub-book +BUG-8: if you add a sub-book, then fail to validate (say no genre), then it takes you back, you click a genre (BUT it has lost th eparent association), so it adds a book, not a sub-book ### SHOWSTOPPERS: sub book issues, did the following steps: - http://mara.ddp.net:5000/series/112 - http://mara.ddp.net:5000/book/1282 (Mavin Manyshaped) - Add Sub-book -> BUG-9 - then to test above, I: - created a new book - created a new sub-book - Saved it, and it added to Mavin Manyshaped parent book, not the new book -> BUG 10 -BUG-9 raw DB error as blurb field is undefined -- seems the hidden fields at bottom of form are missing -BUG-10 raw DB error as blurb field is undefined -- we are not trapping this sort of DB error? +BUG-9: raw DB error as blurb field is undefined -- seems the hidden fields at bottom of form are missing +BUG-10: raw DB error as blurb field is undefined -- we are not trapping this sort of DB error? + http://mara.ddp.net:5000/series/112 + http://mara.ddp.net:5000/book/1282 (Mavin Manyshaped) + Add Sub-book -> BUG-9 + then to test above, I: + created a new book + created a new sub-book + Saved it, and it added to Mavin Manyshaped parent book, not the new book -> BUG 10 diff --git a/main.py b/main.py index cd094f7..0d7af41 100644 --- a/main.py +++ b/main.py @@ -31,6 +31,13 @@ from loan import Loan, LoanForm, LoanSchema from series import Series, SeriesForm, SeriesSchema, ListOfSeriesWithMissingBooks ####################################### CLASSES / DB model ####################################### +class QuickParentBook: + parent=[] + + def __repr__(self): + return "".format(self.parent, self.publisher, self.owned, self.covertype, self.condition, self.blurb ) + + book_author_link = db.Table('book_author_link', db.Model.metadata, db.Column('book_id', db.Integer, db.ForeignKey('book.id')), db.Column('author_id', db.Integer, db.ForeignKey('author.id')) @@ -178,7 +185,7 @@ class BookForm(FlaskForm): submit = SubmitField('Save' ) delete = SubmitField('Delete' ) add_sub = SubmitField('Add Sub-Book' ) - + rem_sub = SubmitField('Remove Sub-Book from Parent' ) ################################# helper functions ################################### def GetBookIdFromSeriesByBookNum( series_id, book_num ): @@ -339,12 +346,13 @@ def subbooks_for_book(id): return render_template("subbooks_for_book.html", sub_books=sub_book, s2=subs ) -class QuickParentBook: - parent=[] - - def __repr__(self): - return "".format(self.parent, self.publisher, self.owned, self.covertype, self.condition, self.blurb ) - +################################################################################ +# /remove_sub_book -> POST -> removes this subbook from parent +# /books (or /book/ -- if you added a sub-book of parent_id +################################################################################ +@app.route("/remove_subbook", methods=["POST"]) +def remove_sub_book(): + return redirect( '/book/{}'.format(request.form['rem_sub_parent_id']) ) ################################################################################ # /book -> GET/POST -> creates a new book and when created, takes you back to @@ -369,7 +377,7 @@ def new_book(): parent=request.form['add_sub_parent_id'] book = Book.query.get(parent) bb=QuickParentBook() - bb.parent= { 'id': parent, 'title': book.title } + bb.parent.append( { 'id': parent, 'title': book.title } ) form.publisher.default = book.publisher form.owned.default = book.owned form.condition.default = book.condition @@ -499,6 +507,7 @@ def book(id): genre_list = GetGenres() book_s = book_schema.dump(book) + print( book.parent ) return render_template("book.html", b=book, books=book_s, book_form=book_form, author_list=author_list, genre_list=genre_list, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage(), poss_series_list=ListOfSeriesWithMissingBooks() ) def GetCount( what, where ): diff --git a/templates/book.html b/templates/book.html index 05e4e53..3315347 100644 --- a/templates/book.html +++ b/templates/book.html @@ -135,10 +135,10 @@ function AddAuthorToBook(num) { - + {% endif %} {% for key in keys %} @@ -295,11 +295,18 @@ function AddAuthorToBook(num) { {{ hiddens.txt|safe }} - {% if b.parent|length == 0 and 'Edit' in page_title %} -
- - {{ book_form.add_sub( class="btn btn-outline-success offset-lg-2 col-lg-2" )}} -
+ {% if 'Edit' in page_title %} + {% if b.parent|length == 0 %} +
+ + {{ book_form.add_sub( class="btn btn-outline-success offset-lg-2 col-lg-2" )}} +
+ {% else %} +
+ + {{ book_form.rem_sub( class="btn btn-outline-danger offset-lg-2 col-lg-3" )}} +
+ {% endif %} {% endif %} {% if books.loan|length %}