fixed BUG-30 duplicate authors

This commit is contained in:
2023-07-05 22:20:08 +10:00
parent 7edc4babd9
commit 56ae9d81ae
2 changed files with 33 additions and 9 deletions

6
BUGs
View File

@@ -1,6 +1,6 @@
#### BUGS (next-41) #### BUGS (next-42)
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-30: failed to add a book with 2 x same author (need to catch error BUG-41: failed to add a book with 2 x same series - implement same fix as
or maybe mess with author list to remove duplicate potentials?) for duplicate authors (search for processed_bals)

36
main.py
View File

@@ -577,13 +577,19 @@ def new_book():
bals=[] bals=[]
auth_cnt=1 auth_cnt=1
processed_bal=[]
message=""
if request.method == 'POST': if request.method == 'POST':
# handle author info for new book # handle author info for new book
for el in request.form: for el in request.form:
if 'author-' in el: if 'author-' in el:
bals.append( Book_Author_Link( author_id=request.form[el], author_num=auth_cnt ) ) if not request.form[el] in processed_bal:
auth_cnt+=1 bals.append( Book_Author_Link( author_id=request.form[el], author_num=auth_cnt ) )
processed_bal.append( request.form[el] )
auth_cnt+=1
else:
message="Removed duplicate author!!!"
# handle genre info for new book # handle genre info for new book
for genre in genre_list: for genre in genre_list:
@@ -637,7 +643,12 @@ 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()
st.SetMessage( "Created new Book ({})".format(book.title) ) if message == None:
st.SetMessage( "Created new Book ({})".format(book.title) )
else:
st.SetAlert("warning")
st.SetMessage( f"Created new Book ({book.title})<br>BUT {message}" )
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':
@@ -723,6 +734,10 @@ def book(id):
book_form.rating.choices=[(c.id, c.name) for c in Rating.query.order_by('id')] book_form.rating.choices=[(c.id, c.name) for c in Rating.query.order_by('id')]
page_title='Edit Book' page_title='Edit Book'
CheckSeriesChange=None CheckSeriesChange=None
processed_bal=[]
alert="success"
message=""
if request.method == 'POST': if request.method == 'POST':
if 'delete' in request.form: if 'delete' in request.form:
redirect_to=DeleteBook(id) redirect_to=DeleteBook(id)
@@ -757,8 +772,13 @@ def book(id):
cnt=1 cnt=1
for el in request.form: for el in request.form:
if 'author-' in el: if 'author-' in el:
book.bals.append( Book_Author_Link( author_id=request.form[el], book_id=id, author_num=cnt ) ) if not request.form[el] in processed_bal:
cnt += 1 book.bals.append( Book_Author_Link( author_id=request.form[el], book_id=id, author_num=cnt ) )
processed_bal.append( request.form[el] )
cnt += 1
else:
alert="warning"
message="removed duplicate author!!!"
# go through form, if we have removed a series, then copy data out of form to be passed into html for a pop-up # go through form, if we have removed a series, then copy data out of form to be passed into html for a pop-up
removing_series=[] removing_series=[]
@@ -820,7 +840,11 @@ def book(id):
s.calcd_rating = CalcAvgRating(s.id) s.calcd_rating = CalcAvgRating(s.id)
cnt=cnt+1 cnt=cnt+1
db.session.commit() db.session.commit()
st.SetMessage( "Successfully Updated Book (id={})".format(id) ) if message == None:
st.SetMessage( f"Successfully Updated Book (id={id})" )
else:
st.SetAlert("warning")
st.SetMessage( f"Successfully Updated Book (id={id})<br>BUT {message}" )
else: else:
st.SetAlert("danger") st.SetAlert("danger")
message=f"Failed to update Book (id={id}). " message=f"Failed to update Book (id={id}). "