diff --git a/BUGs b/BUGs index 53ce13f..6d1e905 100644 --- a/BUGs +++ b/BUGs @@ -4,3 +4,5 @@ * book form is not validating (year published) * 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) * show books, only shows first author +* starting on series remove button. If we click a subbook, then remove series button needs to be clever (might need client-side validation / confirmation, eg. this is a subbook, you want to remove all of the sub books from the series?) +* series: 112, book/sub-book ordering is broken diff --git a/README b/README index 04a9231..6510d7d 100644 --- a/README +++ b/README @@ -29,7 +29,7 @@ python3 main.py offer to move parent/child series orders as well to match (think Thomas Covenant) ### TODO: - - need to create series, loan, book classes (and make green + button work) + - when remove a Parent book from a series, what do we do? - need to delete all classes (and watch for referential integrity) - need to add 1 author to book, book to sub_book, series - need to delete 1 author from book diff --git a/main.py b/main.py index e7a0c6e..d8ead91 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ from flask_bootstrap import Bootstrap from wtforms import SubmitField, StringField, HiddenField, SelectField, IntegerField, TextAreaField, validators from flask_wtf import FlaskForm from status import st, Status +import re ####################################### Flask App globals ####################################### app = Flask(__name__) @@ -26,7 +27,7 @@ from covertype import Covertype, CovertypeForm, CovertypeSchema, GetCovertypeByI from owned import Owned, OwnedForm, OwnedSchema, GetOwnedById from rating import Rating, RatingForm, RatingSchema from loan import Loan, LoanForm, LoanSchema -from series import Series, SeriesForm, SeriesSchema +from series import Series, SeriesForm, SeriesSchema, ListOfSeriesWithMissingBooks ####################################### CLASSES / DB model ####################################### book_author_link = db.Table('book_author_link', db.Model.metadata, @@ -77,6 +78,7 @@ class Book(db.Model): genre = db.relationship('Genre', secondary=book_genre_link ) loan = db.relationship('Loan', secondary=Book_Loan_Link.__table__); series = db.relationship('Series', secondary=Book_Series_Link.__table__); + bsl = db.relationship('Book_Series_Link' ) year_published = db.Column(db.Integer) condition = db.Column(db.Integer, db.ForeignKey('condition.id')) covertype = db.Column(db.Integer, db.ForeignKey('covertype.id')) @@ -212,6 +214,7 @@ app.jinja_env.globals['GetConditionById'] = GetConditionById app.jinja_env.globals['GetPublisherById'] = GetPublisherById app.jinja_env.globals['SeriesBookNum'] = SeriesBookNum app.jinja_env.globals['ClearStatus'] = st.ClearMessage +app.jinja_env.globals['ListOfSeriesWithMissingBooks'] = ListOfSeriesWithMissingBooks book_schema = BookSchema() @@ -367,6 +370,18 @@ def book(id): if 'author-' in el: book.author.append( Author.query.get( request.form[el] ) ) + print( "bsl={}".format( book.bsl )) + # delete all bsls + db.engine.execute("delete from book_series_link where book_id = {}".format( book.id ) ) + 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]) + print( "found: bsl-{} book_id == {}, series_id={}, book_num={}".format(cnt, request.form['bsl-book_id-{}'.format(cnt)], request.form['bsl-series_id-{}'.format(cnt)], request.form['bsl-book_num-{}'.format(cnt)]) ) + sql="insert into book_series_link (book_id, series_id, book_num) values ( {}, {}, {} )".format( request.form['bsl-book_id-{}'.format(cnt)], request.form['bsl-series_id-{}'.format(cnt)], request.form['bsl-book_num-{}'.format(cnt)]) + db.engine.execute( sql ) + cnt=cnt+1 + ## TODO: # what about series?, subbooks?, loan?, etc. db.session.commit() @@ -382,7 +397,7 @@ def book(id): genre_list = GetGenres() book_s = book_schema.dump(book) - return render_template("book.html", b=book, books=book_s, book_form=book_form, author_list=author_list, genre_list=genre_list, alert=alert, message=message, n=book_form.notes ) + return render_template("book.html", b=book, books=book_s, book_form=book_form, author_list=author_list, genre_list=genre_list, alert=alert, message=message, n=book_form.notes, poss_series_list=ListOfSeriesWithMissingBooks() ) @app.route("/", methods=["GET"]) def main_page(): diff --git a/series.py b/series.py index 6fcc3c0..3b6cfcd 100644 --- a/series.py +++ b/series.py @@ -44,6 +44,13 @@ def CalcAvgRating(sid): print( row ) return row.rating +def ListOfSeriesWithMissingBooks(): + res=db.engine.execute("select id, title, num_books, count from ( select s.id, s.title, s.num_books, count(bsl.book_id) from series s, book_series_link bsl where s.id = bsl.series_id group by s.id ) as foo where num_books > count") + tmp=[] + for row in res: + tmp.append({'id': row[0], 'title': row[1]}) + return tmp + ################################################################################ # Routes for series data # diff --git a/templates/book.html b/templates/book.html index 36dbbbf..327aec0 100644 --- a/templates/book.html +++ b/templates/book.html @@ -2,6 +2,69 @@ {% block main_content %} +
+ {% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}| - {% if SeriesBookNum( s.id, books.id ) %} - - {% else %} - - {% endif %} - |