fix BUG-23 (subbook/series confusion), also remove warnings about sql alchemy overlaps, and had to fix bug I introduced when editing a book where the drop-downs no longer had content based on data in form, and stopped messing with books list when iterating over it, python != c :) so using another list called processed to know if the books do not need to be processed (again) - this finally fixed books on shelf
This commit is contained in:
1
BUGs
1
BUGs
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#### BUGS (next-23)
|
#### BUGS (next-23)
|
||||||
BUG-21: parent series now showing all books (thomas covenant series)
|
BUG-21: parent series now showing all books (thomas covenant series)
|
||||||
BUG-23: saving a book with a sub? or maybe just saving more than once? is complaining about removing from a series that we have never added
|
|
||||||
|
|
||||||
### DB/back-end
|
### DB/back-end
|
||||||
|
|
||||||
|
|||||||
41
main.py
41
main.py
@@ -99,8 +99,12 @@ class Book_Series_Link(db.Model):
|
|||||||
return "<book_id: {}, series_id: {}, book_num: {}>".format(self.book_id, self.series_id, self.book_num)
|
return "<book_id: {}, series_id: {}, book_num: {}>".format(self.book_id, self.series_id, self.book_num)
|
||||||
|
|
||||||
def SeriesBookNum(series_id, book_id):
|
def SeriesBookNum(series_id, book_id):
|
||||||
bsl=Book_Series_Link.query.filter( Book_Series_Link.book_id==book_id, Book_Series_Link.series_id==series_id ).all()
|
bsl=Book_Series_Link.query.filter( Book_Series_Link.book_id==book_id, Book_Series_Link.series_id==series_id ).first()
|
||||||
return bsl[0].book_num
|
if bsl:
|
||||||
|
return bsl.book_num
|
||||||
|
else:
|
||||||
|
print( f"WARNING: tried to find book number in this series for: book_id={book_id}, series_id={series_id} but no db data for it" )
|
||||||
|
return 0
|
||||||
|
|
||||||
class Book_Sub_Book_Link(db.Model):
|
class Book_Sub_Book_Link(db.Model):
|
||||||
__tablename__ = "book_sub_book_link"
|
__tablename__ = "book_sub_book_link"
|
||||||
@@ -119,7 +123,7 @@ class Book(db.Model):
|
|||||||
genre = db.relationship('Genre', secondary=book_genre_link )
|
genre = db.relationship('Genre', secondary=book_genre_link )
|
||||||
loan = db.relationship('Loan', secondary=Book_Loan_Link.__table__);
|
loan = db.relationship('Loan', secondary=Book_Loan_Link.__table__);
|
||||||
series = db.relationship('Series', secondary=Book_Series_Link.__table__);
|
series = db.relationship('Series', secondary=Book_Series_Link.__table__);
|
||||||
bsl = db.relationship('Book_Series_Link' )
|
bsl = db.relationship('Book_Series_Link', overlaps="series" )
|
||||||
year_published = db.Column(db.Integer)
|
year_published = db.Column(db.Integer)
|
||||||
condition = db.Column(db.Integer, db.ForeignKey('condition.id'))
|
condition = db.Column(db.Integer, db.ForeignKey('condition.id'))
|
||||||
covertype = db.Column(db.Integer, db.ForeignKey('covertype.id'))
|
covertype = db.Column(db.Integer, db.ForeignKey('covertype.id'))
|
||||||
@@ -133,7 +137,7 @@ class Book(db.Model):
|
|||||||
# take actual parent book as there is no real associated sub_book_num data and can just use it
|
# take actual parent book as there is no real associated sub_book_num data and can just use it
|
||||||
parent = db.relationship('Book', secondary=Book_Sub_Book_Link.__table__, primaryjoin="Book.id==Book_Sub_Book_Link.sub_book_id", secondaryjoin="Book.id==Book_Sub_Book_Link.book_id" )
|
parent = db.relationship('Book', secondary=Book_Sub_Book_Link.__table__, primaryjoin="Book.id==Book_Sub_Book_Link.sub_book_id", secondaryjoin="Book.id==Book_Sub_Book_Link.book_id" )
|
||||||
# but use child_ref as sub_book_num is per book, and I can't connect an empty array of sub_book_nums to a child book array in "child"
|
# but use child_ref as sub_book_num is per book, and I can't connect an empty array of sub_book_nums to a child book array in "child"
|
||||||
child_ref = db.relationship('Book_Sub_Book_Link', secondary=Book_Sub_Book_Link.__table__, primaryjoin="Book.id==Book_Sub_Book_Link.book_id", secondaryjoin="Book.id==Book_Sub_Book_Link.sub_book_id", order_by="Book_Sub_Book_Link.sub_book_num" )
|
child_ref = db.relationship('Book_Sub_Book_Link', secondary=Book_Sub_Book_Link.__table__, primaryjoin="Book.id==Book_Sub_Book_Link.book_id", secondaryjoin="Book.id==Book_Sub_Book_Link.sub_book_id", order_by="Book_Sub_Book_Link.sub_book_num", overlaps="parent" )
|
||||||
|
|
||||||
|
|
||||||
def IsParent(self):
|
def IsParent(self):
|
||||||
@@ -590,6 +594,11 @@ def new_book():
|
|||||||
@login_required
|
@login_required
|
||||||
def book(id):
|
def book(id):
|
||||||
book_form = BookForm(request.form)
|
book_form = BookForm(request.form)
|
||||||
|
book_form.publisher.choices = [(c.id, c.name) for c in Publisher.query.order_by('name')]
|
||||||
|
book_form.owned.choices=[(c.id, c.name) for c in Owned.query.order_by('id')]
|
||||||
|
book_form.covertype.choices=[(c.id, c.name) for c in Covertype.query.order_by('id')]
|
||||||
|
book_form.condition.choices=[(c.id, c.name) for c in Condition.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
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@@ -670,9 +679,11 @@ def book(id):
|
|||||||
child_book.condition=book.condition
|
child_book.condition=book.condition
|
||||||
child_book.blurb=book.blurb
|
child_book.blurb=book.blurb
|
||||||
|
|
||||||
if book.IsChild() or (book.IsParent() and not still_in_series):
|
# if removing_series has something in it, then handle it
|
||||||
|
if (len(removing_series) > 0) and (book.IsChild() or (book.IsParent() and not still_in_series)):
|
||||||
print ("okay should raise DBox")
|
print ("okay should raise DBox")
|
||||||
print ("{}".format( removing_series ))
|
print ("{}".format( removing_series ))
|
||||||
|
print (f"still_in_series={still_in_series}" )
|
||||||
if book.IsParent():
|
if book.IsParent():
|
||||||
CheckSeriesChange={'type':'parent', 'pid': book.id, 'bid': book.id, 'removing_series': removing_series }
|
CheckSeriesChange={'type':'parent', 'pid': book.id, 'bid': book.id, 'removing_series': removing_series }
|
||||||
else:
|
else:
|
||||||
@@ -717,6 +728,11 @@ def book(id):
|
|||||||
return render_template("base.html", alert=st.GetAlert(), message=st.GetMessage())
|
return render_template("base.html", alert=st.GetAlert(), message=st.GetMessage())
|
||||||
|
|
||||||
book_form=BookForm(obj=book)
|
book_form=BookForm(obj=book)
|
||||||
|
book_form.publisher.choices = [(c.id, c.name) for c in Publisher.query.order_by('name')]
|
||||||
|
book_form.owned.choices=[(c.id, c.name) for c in Owned.query.order_by('id')]
|
||||||
|
book_form.covertype.choices=[(c.id, c.name) for c in Covertype.query.order_by('id')]
|
||||||
|
book_form.condition.choices=[(c.id, c.name) for c in Condition.query.order_by('id')]
|
||||||
|
book_form.rating.choices=[(c.id, c.name) for c in Rating.query.order_by('id')]
|
||||||
|
|
||||||
author_list = GetAuthors()
|
author_list = GetAuthors()
|
||||||
genre_list = GetGenres()
|
genre_list = GetGenres()
|
||||||
@@ -802,14 +818,12 @@ def books_on_shelf():
|
|||||||
books = Book.query.join(Owned).filter(Owned.name=='Currently Owned').all()
|
books = Book.query.join(Owned).filter(Owned.name=='Currently Owned').all()
|
||||||
RemSubs(books)
|
RemSubs(books)
|
||||||
|
|
||||||
# now we order them (they are in author order, but not inside that authors list)
|
|
||||||
|
|
||||||
# because a book can be in multiple series, without any ordering we need to find
|
# because a book can be in multiple series, without any ordering we need to find
|
||||||
# any book that is in a series, then go through each series to find the one with
|
# any book that is in a series, then go through each series to find the one with
|
||||||
# the most books in it. THEN we need to get all those books and put them in the
|
# the most books in it. THEN we need to get all those books and put them in the
|
||||||
# ordered_books array, and remove them from the books array
|
# ordered_books array, and remove them from the books array
|
||||||
ordered_books=[]
|
ordered_books=[]
|
||||||
handle_parent=[]
|
processed=[]
|
||||||
currently_owned = Owned.query.filter(Owned.name=='Currently Owned').one()
|
currently_owned = Owned.query.filter(Owned.name=='Currently Owned').one()
|
||||||
for b in books:
|
for b in books:
|
||||||
if b.series:
|
if b.series:
|
||||||
@@ -829,14 +843,15 @@ def books_on_shelf():
|
|||||||
continue
|
continue
|
||||||
if tmp_b.IsChild():
|
if tmp_b.IsChild():
|
||||||
# this child book wont be in books, but its parent will -> use it instead
|
# this child book wont be in books, but its parent will -> use it instead
|
||||||
if tmp_b.parent[0].id not in handle_parent:
|
# mark parent from books so we dont process it twice
|
||||||
books.remove(tmp_b.parent[0])
|
if tmp_b.parent[0].id not in processed:
|
||||||
|
processed.append(tmp_b.id)
|
||||||
|
processed.append(tmp_b.parent[0].id)
|
||||||
ordered_books.append(tmp_b.parent[0])
|
ordered_books.append(tmp_b.parent[0])
|
||||||
handle_parent.append(tmp_b.parent[0].id)
|
|
||||||
else:
|
else:
|
||||||
if tmp_b.id not in handle_parent:
|
if tmp_b.id not in processed:
|
||||||
books.remove(tmp_b)
|
|
||||||
ordered_books.append(tmp_b)
|
ordered_books.append(tmp_b)
|
||||||
|
processed.append(tmp_b.id)
|
||||||
else:
|
else:
|
||||||
# book not in a series or a sub-book, so just add this book to the ordered list
|
# book not in a series or a sub-book, so just add this book to the ordered list
|
||||||
ordered_books.append(b)
|
ordered_books.append(b)
|
||||||
|
|||||||
Reference in New Issue
Block a user