reword BUG-42 to be more specific, BUG-41 allowing duplicate series links fixed
This commit is contained in:
6
BUGs
6
BUGs
@@ -1,9 +1,5 @@
|
|||||||
#### BUGS (next-46)
|
#### BUGS (next-46)
|
||||||
|
|
||||||
BUG-41: failed to add a book with 2 x same series - implement same fix as for duplicate authors (search for processed_bal) - should
|
BUG-42: can add a sub_book_num for a series that has already been taken (or is invalid, e.g. 9999) -- DB does not enforce either
|
||||||
actually turn processed_bal into a function, as its used twice, then do similar for series
|
|
||||||
|
|
||||||
BUG-42: bug-7 removed as bug-41 covers the more useful version of this AND what we also need (this bug) is not allowing adding a
|
|
||||||
sub_book_num for a series that has already been taken -- not sure the DB enforces either
|
|
||||||
|
|
||||||
BUG-45: create a new book, fail (say for now year), and it loses the series you already set in the new html
|
BUG-45: create a new book, fail (say for now year), and it loses the series you already set in the new html
|
||||||
|
|||||||
72
main.py
72
main.py
@@ -579,6 +579,36 @@ def RemoveDuplicateAuthorInForm( request ):
|
|||||||
message="Removed duplicate Author!!!"
|
message="Removed duplicate Author!!!"
|
||||||
return ret, message
|
return ret, message
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Go through request.form, find series and remove any that are duplicates as
|
||||||
|
# that is not allowed / DB integrity issue. This just sets a message that
|
||||||
|
# will allow the book to be create/saved still, but the duplicate series will
|
||||||
|
# be removed
|
||||||
|
def RemoveDuplicateSeriesInForm( book, request ):
|
||||||
|
processed=[]
|
||||||
|
message=""
|
||||||
|
|
||||||
|
cnt=1
|
||||||
|
while f'bsl-book_id-{cnt}' in request.form:
|
||||||
|
print( f"cnt={cnt}, found series id = {request.form[f'bsl-series_id-{cnt}']} " )
|
||||||
|
if request.form[ f"bsl-series_id-{cnt}"] not in processed:
|
||||||
|
if book.IsParent():
|
||||||
|
newbsl=Book_Series_Link( book_id=book.id, series_id=request.form[f'bsl-series_id-{cnt}'] )
|
||||||
|
else:
|
||||||
|
newbsl=Book_Series_Link( book_id=book.id, series_id=request.form[f'bsl-series_id-{cnt}'], book_num=request.form[f'bsl-book_num-{cnt}'] )
|
||||||
|
|
||||||
|
# add the contains (null for book_num) bsl for the parent book
|
||||||
|
if book.IsChild():
|
||||||
|
parent_bsl=Book_Series_Link( book_id=book.parent[0].id, series_id=request.form[f'bsl-series_id-{cnt}'] )
|
||||||
|
db.session.add(parent_bsl)
|
||||||
|
|
||||||
|
db.session.add(newbsl)
|
||||||
|
processed.append( request.form[ f"bsl-series_id-{cnt}"] )
|
||||||
|
else:
|
||||||
|
message="Removed duplicate Series!!!"
|
||||||
|
cnt += 1
|
||||||
|
db.session.commit()
|
||||||
|
return message
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# /book -> GET/POST -> creates a new book and when created, takes you back to
|
# /book -> GET/POST -> creates a new book and when created, takes you back to
|
||||||
@@ -656,20 +686,13 @@ def new_book():
|
|||||||
newbsl=Book_Series_Link( book_id=book.id, series_id=s.series_id, book_num=max_bn+1 )
|
newbsl=Book_Series_Link( book_id=book.id, series_id=s.series_id, book_num=max_bn+1 )
|
||||||
db.session.add(newbsl)
|
db.session.add(newbsl)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
message=RemoveDuplicateSeriesInForm( book, request )
|
||||||
if message == "":
|
if message == "":
|
||||||
st.SetMessage( "Created new Book ({})".format(book.title) )
|
st.SetMessage( "Created new Book ({})".format(book.title) )
|
||||||
else:
|
else:
|
||||||
st.SetAlert("warning")
|
st.SetAlert("warning")
|
||||||
st.SetMessage( f"Created new Book ({book.title})<br>BUT {message}" )
|
st.SetMessage( f"Created new Book ({book.title})<br>BUT {message}" )
|
||||||
|
|
||||||
cnt=1
|
|
||||||
for field in request.form:
|
|
||||||
if 'bsl-book_id-' in field and field != 'bsl-book_id-NUM':
|
|
||||||
cnt=int(re.findall( '\d+', field )[0])
|
|
||||||
newbsl=Book_Series_Link( book_id=book.id, series_id=request.form[ f"bsl-series_id-{cnt}"], book_num=request.form[ f"bsl-book_num-{cnt}"] )
|
|
||||||
db.session.add(newbsl)
|
|
||||||
db.session.commit()
|
|
||||||
cnt=cnt+1
|
|
||||||
return redirect( '/book/{}'.format(book.id) )
|
return redirect( '/book/{}'.format(book.id) )
|
||||||
else:
|
else:
|
||||||
alert="danger"
|
alert="danger"
|
||||||
@@ -815,22 +838,23 @@ def book(id):
|
|||||||
if book.IsChild():
|
if book.IsChild():
|
||||||
Book_Series_Link.query.filter(Book_Series_Link.book_id == book.parent[0].id ).delete()
|
Book_Series_Link.query.filter(Book_Series_Link.book_id == book.parent[0].id ).delete()
|
||||||
|
|
||||||
cnt=1
|
# cnt=1
|
||||||
for field in request.form:
|
# for field in request.form:
|
||||||
if 'bsl-book_id-' in field and field != 'bsl-book_id-NUM':
|
# if 'bsl-book_id-' in field and field != 'bsl-book_id-NUM':
|
||||||
cnt=int(re.findall( '\d+', field )[0])
|
# cnt=int(re.findall( '\d+', field )[0])
|
||||||
if book.IsParent():
|
# if book.IsParent():
|
||||||
newbsl=Book_Series_Link( book_id=request.form[f'bsl-book_id-{cnt}'],
|
# newbsl=Book_Series_Link( book_id=request.form[f'bsl-book_id-{cnt}'],
|
||||||
series_id=request.form[f'bsl-series_id-{cnt}'] )
|
# series_id=request.form[f'bsl-series_id-{cnt}'] )
|
||||||
else:
|
# else:
|
||||||
newbsl=Book_Series_Link( book_id=request.form[f'bsl-book_id-{cnt}'],
|
# newbsl=Book_Series_Link( book_id=request.form[f'bsl-book_id-{cnt}'],
|
||||||
series_id=request.form[f'bsl-series_id-{cnt}'],
|
# series_id=request.form[f'bsl-series_id-{cnt}'],
|
||||||
book_num=request.form[f'bsl-book_num-{cnt}'] )
|
# book_num=request.form[f'bsl-book_num-{cnt}'] )
|
||||||
# add the contains (null for book_num) bsl for the parent book
|
# # add the contains (null for book_num) bsl for the parent book
|
||||||
if book.IsChild():
|
# if book.IsChild():
|
||||||
parent_bsl=Book_Series_Link( book_id=book.parent[0].id, series_id=request.form[f'bsl-series_id-{cnt}'] )
|
# parent_bsl=Book_Series_Link( book_id=book.parent[0].id, series_id=request.form[f'bsl-series_id-{cnt}'] )
|
||||||
db.session.add(parent_bsl)
|
# db.session.add(parent_bsl)
|
||||||
db.session.add(newbsl)
|
# db.session.add(newbsl)
|
||||||
|
message=RemoveDuplicateSeriesInForm( book, request )
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# reset rating on this/these series as the book has changed (and maybe the rating has changed)
|
# reset rating on this/these series as the book has changed (and maybe the rating has changed)
|
||||||
|
|||||||
Reference in New Issue
Block a user