diff --git a/BUGs b/BUGs index 21ad650..4b27d0c 100644 --- a/BUGs +++ b/BUGs @@ -7,3 +7,4 @@ BUG-45: create a new book, fail (say for now year), and it loses the series BUG-46: search (and really all books.html usage), don't deal with sub books and/or series ordering. Probably should at least do subs ordering (so the code I wrote for author//books) and use that for search for example - test with search for 'dune' + - also test with authors book list for frank herbert diff --git a/TODO b/TODO index 3234f77..8c343f0 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,4 @@ TODO: - * book.parent is an array, not a dict - should change it over - * search on more than title, e.g. author, series, etc. * if we add a new parent book with sub-books into a series, with parent * book as 'null' sub_book_num, all the sub_books should be added somehow into series - but cant input numbering on parent book, so diff --git a/author.py b/author.py index 10fcdb8..9609f4c 100644 --- a/author.py +++ b/author.py @@ -122,13 +122,13 @@ def authors_books(author_id): ordered_books.append( tmp ) processed.append( bb.sub_book_id ) elif b.IsChild(): - ordered_books.append(b.parent[0]) - processed.append( b.parent[0].id ) + ordered_books.append(b.parent) + processed.append( b.parent.id ) cnt=1 - for bb in b.parent[0].child_ref: + for bb in b.parent.child_ref: tmp=Book.query.get(bb.sub_book_id) # need to set parent_id and sub_book_num for indenting to work in html - tmp.parent_id=b.parent[0].id + tmp.parent_id=b.parent.id tmp.sub_book_num=cnt ordered_books.append( tmp ) processed.append( bb.sub_book_id ) diff --git a/main.py b/main.py index 5c3ede9..fc209b8 100644 --- a/main.py +++ b/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) diff --git a/templates/book.html b/templates/book.html index 520aebc..3aca831 100644 --- a/templates/book.html +++ b/templates/book.html @@ -221,17 +221,17 @@ function AddAuthorToBook(num) {
{{ book_form.id }} {{ book_form.csrf_token }} - {% if b.parent|length %} + {% if b.parent %}
- - + +
{% endif %} @@ -303,7 +303,7 @@ function AddAuthorToBook(num) { {% if key == "notes" %} {% set rows=2 %} {% endif %} - {% if b.parent|length and + {% if b.parent and (key == 'publisher' or key == 'owned' or key == 'covertype' or key == 'condition' or key == 'blurb' ) %} {{book_form[key](class="form-control", rows=rows, disabled="disabled" )}} @@ -426,7 +426,7 @@ function AddAuthorToBook(num) { {% else %}
{% endif %} - {% if b.parent|length == 0 %} + {% if b.parent %} {{ book_form.add_sub( class="btn btn-outline-success offset-2 col-2" )}} @@ -434,7 +434,7 @@ function AddAuthorToBook(num) { {% else %} - + {{ book_form.rem_sub( class="btn btn-outline-danger offset-2 col-3" )}} {% endif %} diff --git a/templates/books_for_series.html b/templates/books_for_series.html index ce1ba42..3603d57 100644 --- a/templates/books_for_series.html +++ b/templates/books_for_series.html @@ -6,7 +6,7 @@ {% for book in books %} - {% if book.parent|length %} + {% if book.parent %} {% set style="style=visibility:hidden" %} {% endif %}