diff --git a/BUGs b/BUGs
index e546aa0..2ac38a2 100644
--- a/BUGs
+++ b/BUGs
@@ -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-30: failed to add a book with 2 x same author (need to catch error
- or maybe mess with author list to remove duplicate potentials?)
+BUG-41: failed to add a book with 2 x same series - implement same fix as
+ for duplicate authors (search for processed_bals)
diff --git a/main.py b/main.py
index 2a0a665..5266f25 100644
--- a/main.py
+++ b/main.py
@@ -577,13 +577,19 @@ def new_book():
bals=[]
auth_cnt=1
+ processed_bal=[]
+ message=""
if request.method == 'POST':
# handle author info for new book
for el in request.form:
if 'author-' in el:
- bals.append( Book_Author_Link( author_id=request.form[el], author_num=auth_cnt ) )
- auth_cnt+=1
+ if not request.form[el] in processed_bal:
+ 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
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 )
db.session.add(newbsl)
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})
BUT {message}" )
+
cnt=1
for field in request.form:
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')]
page_title='Edit Book'
CheckSeriesChange=None
+ processed_bal=[]
+ alert="success"
+ message=""
+
if request.method == 'POST':
if 'delete' in request.form:
redirect_to=DeleteBook(id)
@@ -757,8 +772,13 @@ def book(id):
cnt=1
for el in request.form:
if 'author-' in el:
- book.bals.append( Book_Author_Link( author_id=request.form[el], book_id=id, author_num=cnt ) )
- cnt += 1
+ if not request.form[el] in processed_bal:
+ 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
removing_series=[]
@@ -820,7 +840,11 @@ def book(id):
s.calcd_rating = CalcAvgRating(s.id)
cnt=cnt+1
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})
BUT {message}" )
else:
st.SetAlert("danger")
message=f"Failed to update Book (id={id}). "