fixed BUG-11, parent was both an array (in Book) and not an array in QuickBook, so made them arrays to keep with ORM-way

This commit is contained in:
2021-01-02 18:53:52 +11:00
parent 3c47063ee2
commit 4c442e1fea
3 changed files with 50 additions and 34 deletions

38
BUGs
View File

@@ -1,28 +1,28 @@
#### BUGS
BUG-1: loan card is not in right div anymore (since series stuff?)
http://mara.ddp.net:5000/book/1513
BUG-1: loan card is not in right div anymore (since series stuff?)
- http://mara.ddp.net:5000/book/1513
BUG-2 series does not deal with calcd_rating...
(on edit could, recalc as a catch-all, and obviously if we change a single book's rating, we should re-calc)
BUG-2: series does not deal with calcd_rating...
- (on edit could, recalc as a catch-all, and obviously if we change a single book's rating, we should re-calc)
BUG-3 alter a condition, covertype, etc. and its not in drop-down list (even though db look via index is correct, e.g books.html shows updated covertype)
BUG-3: alter a condition, covertype, etc. and its not in drop-down list (even though db look via index is correct, e.g books.html shows updated covertype)
BUG-4 show books, only shows first author
BUG-4: show books, only shows first author
BUG-6 author,series, etc. do not have explicit ordering like sub-books... sort of irritating / needs code and DB fix
* add/remove authors, and after save they are ordered by author.id, not order of addition (prob. needs book_author_link to have an auth_num)
BUG-6: author,series, etc. do not have explicit ordering like sub-books... sort of irritating / needs code and DB fix
- add/remove authors, and after save they are ordered by author.id, not order of addition (prob. needs book_author_link to have an auth_num)
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-8 if you add a sub-book, then fail to validate (say no genre), then it takes you back, you click a genre (BUT it has lost th eparent association), so it adds a book, not a sub-book
BUG-8: if you add a sub-book, then fail to validate (say no genre), then it takes you back, you click a genre (BUT it has lost th eparent association), so it adds a book, not a sub-book
### SHOWSTOPPERS: sub book issues, did the following steps:
http://mara.ddp.net:5000/series/112
http://mara.ddp.net:5000/book/1282 (Mavin Manyshaped)
Add Sub-book -> BUG-9
then to test above, I:
created a new book
created a new sub-book
Saved it, and it added to Mavin Manyshaped parent book, not the new book -> BUG 10
BUG-9 raw DB error as blurb field is undefined -- seems the hidden fields at bottom of form are missing
BUG-10 raw DB error as blurb field is undefined -- we are not trapping this sort of DB error?
BUG-9: raw DB error as blurb field is undefined -- seems the hidden fields at bottom of form are missing
BUG-10: raw DB error as blurb field is undefined -- we are not trapping this sort of DB error?
http://mara.ddp.net:5000/series/112
http://mara.ddp.net:5000/book/1282 (Mavin Manyshaped)
Add Sub-book -> BUG-9
then to test above, I:
created a new book
created a new sub-book
Saved it, and it added to Mavin Manyshaped parent book, not the new book -> BUG 10

25
main.py
View File

@@ -31,6 +31,13 @@ from loan import Loan, LoanForm, LoanSchema
from series import Series, SeriesForm, SeriesSchema, ListOfSeriesWithMissingBooks
####################################### CLASSES / DB model #######################################
class QuickParentBook:
parent=[]
def __repr__(self):
return "<parent: {}, publisher: {}, owned: {}, covertype: {}, condition: {}, blurb: {}>".format(self.parent, self.publisher, self.owned, self.covertype, self.condition, self.blurb )
book_author_link = db.Table('book_author_link', db.Model.metadata,
db.Column('book_id', db.Integer, db.ForeignKey('book.id')),
db.Column('author_id', db.Integer, db.ForeignKey('author.id'))
@@ -178,7 +185,7 @@ class BookForm(FlaskForm):
submit = SubmitField('Save' )
delete = SubmitField('Delete' )
add_sub = SubmitField('Add Sub-Book' )
rem_sub = SubmitField('Remove Sub-Book from Parent' )
################################# helper functions ###################################
def GetBookIdFromSeriesByBookNum( series_id, book_num ):
@@ -339,12 +346,13 @@ def subbooks_for_book(id):
return render_template("subbooks_for_book.html", sub_books=sub_book, s2=subs )
class QuickParentBook:
parent=[]
def __repr__(self):
return "<parent: {}, publisher: {}, owned: {}, covertype: {}, condition: {}, blurb: {}>".format(self.parent, self.publisher, self.owned, self.covertype, self.condition, self.blurb )
################################################################################
# /remove_sub_book -> POST -> removes this subbook from parent
# /books (or /book/<parent_id> -- if you added a sub-book of parent_id
################################################################################
@app.route("/remove_subbook", methods=["POST"])
def remove_sub_book():
return redirect( '/book/{}'.format(request.form['rem_sub_parent_id']) )
################################################################################
# /book -> GET/POST -> creates a new book and when created, takes you back to
@@ -369,7 +377,7 @@ def new_book():
parent=request.form['add_sub_parent_id']
book = Book.query.get(parent)
bb=QuickParentBook()
bb.parent= { 'id': parent, 'title': book.title }
bb.parent.append( { 'id': parent, 'title': book.title } )
form.publisher.default = book.publisher
form.owned.default = book.owned
form.condition.default = book.condition
@@ -499,6 +507,7 @@ def book(id):
genre_list = GetGenres()
book_s = book_schema.dump(book)
print( book.parent )
return render_template("book.html", b=book, books=book_s, book_form=book_form, author_list=author_list, genre_list=genre_list, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage(), poss_series_list=ListOfSeriesWithMissingBooks() )
def GetCount( what, where ):

View File

@@ -135,10 +135,10 @@ function AddAuthorToBook(num) {
<label class="col-lg-2 col-form-label bg-secondary text-white">Parent Book:</label>
<div class="col">
<button disabled class="col btn btn-outline-primary">
<i><a href="/book/{{b.parent.id}}">{{b.parent.title}}</a></i>
<i><a href="/book/{{b.parent[0].id}}">{{b.parent[0].title}}</a></i>
</button>
</div>
<input type="hidden" name="parent_id" value="{{b.parent.id}}">
<input type="hidden" name="parent_id" value="{{b.parent[0].id}}">
</div>
{% endif %}
{% for key in keys %}
@@ -295,11 +295,18 @@ function AddAuthorToBook(num) {
</div class="form-row">
{{ hiddens.txt|safe }}
</form>
{% if b.parent|length == 0 and 'Edit' in page_title %}
<form role="form" class="form col-lg-10" action="{{url_for('new_book')}}" method="POST">
<input type="hidden" name="add_sub_parent_id" value="{{books.id}}">
{{ book_form.add_sub( class="btn btn-outline-success offset-lg-2 col-lg-2" )}}
</form>
{% if 'Edit' in page_title %}
{% if b.parent|length == 0 %}
<form role="form" class="form col-lg-10" action="{{url_for('new_book')}}" method="POST">
<input type="hidden" name="add_sub_parent_id" value="{{books.id}}">
{{ book_form.add_sub( class="btn btn-outline-success offset-lg-2 col-lg-2" )}}
</form>
{% else %}
<form role="form" class="form col-lg-10" action="{{url_for('remove_sub_book')}}" method="POST">
<input type="hidden" name="rem_sub_parent_id" value="{{books.id}}">
{{ book_form.rem_sub( class="btn btn-outline-danger offset-lg-2 col-lg-3" )}}
</form>
{% endif %}
{% endif %}
{% if books.loan|length %}
<div class="col">