add/remove series from a book now works, havent thought about removing a parent book fro a series, but otherwise you can add more than one series, remove as well, and it works in the DB
This commit is contained in:
19
main.py
19
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():
|
||||
|
||||
Reference in New Issue
Block a user