fixed BUG-17 change parent and subs werent, now are. Also removed len(child/parent) and used functions IsChild(), IsParent() as I should have
This commit is contained in:
3
BUGs
3
BUGs
@@ -1,5 +1,4 @@
|
|||||||
#### BUGS (next-17)
|
#### BUGS (next-18)
|
||||||
BUG-17: if change publisher, owned, covertype, condition, or blurb of parent book, then need to reflect that change to ALL sub books
|
|
||||||
|
|
||||||
### DB/back-end
|
### DB/back-end
|
||||||
BUG-2: series does not deal with calcd_rating...
|
BUG-2: series does not deal with calcd_rating...
|
||||||
|
|||||||
19
main.py
19
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 )
|
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.add(book)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
# this is a sub-book we have added
|
||||||
if 'parent_id' in request.form:
|
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'] ) )
|
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'])
|
parent=Book.query.get(request.form['parent_id'])
|
||||||
print( parent.series )
|
|
||||||
if len(parent.series) > 0:
|
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:
|
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.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()
|
db.session.commit()
|
||||||
@@ -485,7 +486,7 @@ def book(id):
|
|||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if 'delete' in request.form:
|
if 'delete' in request.form:
|
||||||
book = Book.query.get(id)
|
book = Book.query.get(id)
|
||||||
if len(book.child_ref) > 0:
|
if book.IsParent():
|
||||||
st.SetAlert( "danger" )
|
st.SetAlert( "danger" )
|
||||||
st.SetMessage( "This is a parent book, cannot delete it without deleting sub books first" )
|
st.SetMessage( "This is a parent book, cannot delete it without deleting sub books first" )
|
||||||
return redirect( '/book/{}'.format(book.id) )
|
return redirect( '/book/{}'.format(book.id) )
|
||||||
@@ -493,7 +494,7 @@ def book(id):
|
|||||||
st.SetAlert("success")
|
st.SetAlert("success")
|
||||||
st.SetMessage("Deleted {}".format(book.title) )
|
st.SetMessage("Deleted {}".format(book.title) )
|
||||||
pid = 0
|
pid = 0
|
||||||
if len(book.parent) > 0:
|
if book.IsChild():
|
||||||
pid = book.parent[0].id
|
pid = book.parent[0].id
|
||||||
try:
|
try:
|
||||||
db.session.delete(book)
|
db.session.delete(book)
|
||||||
@@ -548,6 +549,16 @@ def book(id):
|
|||||||
for field in request.form:
|
for field in request.form:
|
||||||
if 'bsl-book_num-' in field and field != 'bsl-book_num-NUM' and request.form[field] == 'PARENT':
|
if 'bsl-book_num-' in field and field != 'bsl-book_num-NUM' and request.form[field] == 'PARENT':
|
||||||
still_in_series=1
|
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):
|
if book.IsChild() or (book.IsParent() and not still_in_series):
|
||||||
print ("okay should raise DBox")
|
print ("okay should raise DBox")
|
||||||
|
|||||||
Reference in New Issue
Block a user