diff --git a/BUGs b/BUGs index a2dcb3c..f03b5da 100644 --- a/BUGs +++ b/BUGs @@ -1,5 +1,4 @@ -#### BUGS (next-17) -BUG-17: if change publisher, owned, covertype, condition, or blurb of parent book, then need to reflect that change to ALL sub books +#### BUGS (next-18) ### DB/back-end BUG-2: series does not deal with calcd_rating... diff --git a/main.py b/main.py index 62adaba..1adc2e2 100644 --- a/main.py +++ b/main.py @@ -439,12 +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 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']) - print( parent.series ) if len(parent.series) > 0: - print ("I think this means we have added a sub-book to something in a series already" ) + # we have added a sub-book to something in a series + # 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() @@ -485,7 +486,7 @@ def book(id): if request.method == 'POST': if 'delete' in request.form: book = Book.query.get(id) - if len(book.child_ref) > 0: + if book.IsParent(): st.SetAlert( "danger" ) st.SetMessage( "This is a parent book, cannot delete it without deleting sub books first" ) return redirect( '/book/{}'.format(book.id) ) @@ -493,7 +494,7 @@ def book(id): st.SetAlert("success") st.SetMessage("Deleted {}".format(book.title) ) pid = 0 - if len(book.parent) > 0: + if book.IsChild(): pid = book.parent[0].id try: db.session.delete(book) @@ -548,6 +549,16 @@ def book(id): for field in request.form: if 'bsl-book_num-' in field and field != 'bsl-book_num-NUM' and request.form[field] == 'PARENT': still_in_series=1 + # go through children, and force sync any changes of physical parts of parent book + tmp_book=book_schema.dump(book) + for ch_ref in tmp_book['child_ref']: + ch_bid=GetBookIdFromBookSubBookLinkByIdAndSubBookNum( book.id, ch_ref['sub_book_num'] ) + child_book=Book.query.get(ch_bid) + child_book.publisher=book.publisher + child_book.owned=book.owned + child_book.covertype=book.covertype + child_book.condition=book.condition + child_book.blurb=book.blurb if book.IsChild() or (book.IsParent() and not still_in_series): print ("okay should raise DBox")