move parent[] to parent as the array was never needed, removed some dead code, clarified another example of new BUG-46
This commit is contained in:
36
main.py
36
main.py
@@ -152,7 +152,7 @@ class Book(db.Model):
|
||||
modified = db.Column(db.DateTime)
|
||||
|
||||
# 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", uselist=False )
|
||||
# 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", overlaps="parent" )
|
||||
|
||||
@@ -166,7 +166,7 @@ class Book(db.Model):
|
||||
return False
|
||||
|
||||
def IsChild(self):
|
||||
if len(self.parent):
|
||||
if self.parent:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -444,7 +444,7 @@ def CalcMoveForBookInSeries( id, bid, dir ):
|
||||
|
||||
# if book2 is a sub book, then we need its parent as book2 instead, as we have to move the whole book as one
|
||||
if book2.IsChild():
|
||||
book2 = Book.query.get( book2.parent[0].id )
|
||||
book2 = Book.query.get( book2.parent.id )
|
||||
|
||||
# By here: book1 is parent or normal book we are swapping with book2 which is parent or normal book
|
||||
b1_numsb = book1.NumSubBooks()
|
||||
@@ -598,7 +598,7 @@ def RemoveDuplicateSeriesInForm( book, request ):
|
||||
|
||||
# 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}'] )
|
||||
parent_bsl=Book_Series_Link( book_id=book.parent.id, series_id=request.form[f'bsl-series_id-{cnt}'] )
|
||||
db.session.add(parent_bsl)
|
||||
|
||||
db.session.add(newbsl)
|
||||
@@ -735,7 +735,7 @@ def DeleteBook(id):
|
||||
st.SetMessage("Deleted {}".format(book.title) )
|
||||
pid = 0
|
||||
if book.IsChild():
|
||||
pid = book.parent[0].id
|
||||
pid = book.parent.id
|
||||
try:
|
||||
ClearAuthorsForBook(book.id)
|
||||
db.session.delete(book)
|
||||
@@ -828,30 +828,14 @@ def book(id):
|
||||
CheckSeriesChange={'type':'parent', 'pid': book.id, 'bid': book.id, 'removing_series': removing_series }
|
||||
# saving a child / sub_book, consider series
|
||||
if book.IsChild() and len(removing_series) > 0:
|
||||
CheckSeriesChange={'type':'child', 'pid': book.parent[0].id, 'bid': book.id, 'removing_series': removing_series }
|
||||
CheckSeriesChange={'type':'child', 'pid': book.parent.id, 'bid': book.id, 'removing_series': removing_series }
|
||||
else:
|
||||
# either we are a normal book (no parent/child), OR not removing a series, might be adding though, so easiest is to
|
||||
# delete all bsls and then add them back based on the request.form
|
||||
Book_Series_Link.query.filter(Book_Series_Link.book_id == book.id ).delete()
|
||||
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.id ).delete()
|
||||
|
||||
# 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])
|
||||
# if book.IsParent():
|
||||
# newbsl=Book_Series_Link( book_id=request.form[f'bsl-book_id-{cnt}'],
|
||||
# series_id=request.form[f'bsl-series_id-{cnt}'] )
|
||||
# else:
|
||||
# newbsl=Book_Series_Link( book_id=request.form[f'bsl-book_id-{cnt}'],
|
||||
# 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)
|
||||
message=RemoveDuplicateSeriesInForm( book, request )
|
||||
db.session.commit()
|
||||
|
||||
@@ -985,10 +969,10 @@ def OrderBooks(books):
|
||||
if tmp_b.IsChild():
|
||||
# this child book wont be in books, but its parent will -> use it instead
|
||||
# mark parent from books so we dont process it twice
|
||||
if tmp_b.parent[0].id not in processed:
|
||||
if tmp_b.parent.id not in processed:
|
||||
processed.append(tmp_b.id)
|
||||
processed.append(tmp_b.parent[0].id)
|
||||
ordered_books.append(tmp_b.parent[0])
|
||||
processed.append(tmp_b.parent.id)
|
||||
ordered_books.append(tmp_b.parent)
|
||||
else:
|
||||
if tmp_b.id not in processed:
|
||||
ordered_books.append(tmp_b)
|
||||
|
||||
Reference in New Issue
Block a user