fixed TODO-23 (moving book in 2 series). also put db change in a try/except and cleaned up comments
This commit is contained in:
1
README
1
README
@@ -28,7 +28,6 @@ python3 main.py
|
||||
|
||||
|
||||
#### TODOS (next 26):
|
||||
TODO-23: when moving a book in a series (which is part of 2 series), do we pop-up offer to move parent/child series orders as well to match (think Thomas Covenant)
|
||||
TODO-24: get this into docker (as per TODO above)
|
||||
gunicorn and it seems easy enough: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-18-04
|
||||
|
||||
|
||||
26
main.py
26
main.py
@@ -137,6 +137,8 @@ class Book(db.Model):
|
||||
return 1
|
||||
|
||||
def MoveBookInSeries( self, series_id, amt ):
|
||||
# if parent book, move all sub books instead
|
||||
try:
|
||||
if self.IsParent():
|
||||
tmp_book=book_schema.dump(self)
|
||||
for book in tmp_book['child_ref']:
|
||||
@@ -148,6 +150,10 @@ class Book(db.Model):
|
||||
bsl[0].book_num=bsl[0].book_num+amt
|
||||
db.session.commit()
|
||||
return
|
||||
except SQLAlchemyError as e:
|
||||
st.SetAlert( "danger" )
|
||||
st.SetMessage( e.orig )
|
||||
return redirect( '/series/{}'.format(series_id) )
|
||||
|
||||
def __repr__(self):
|
||||
return "<id: {}, author: {}, title: {}, year_published: {}, rating: {}, condition: {}, owned: {}, covertype: {}, notes: {}, blurb: {}, created: {}, modified: {}, publisher: {}, genre: {}, parent: {}>".format(self.id, self.author, self.title, self.year_published, self.rating, self.condition, self.owned, self.covertype, self.notes, self.blurb, self.created, self.modified, self.publisher, self.genre, self.parent )
|
||||
@@ -255,14 +261,9 @@ def books_for_loan(id):
|
||||
InDBox=0
|
||||
return render_template("books_for_loan.html", books=books, loan_id=id, InDBox=InDBox)
|
||||
|
||||
@app.route("/books_for_series/<id>", methods=["GET", "POST"])
|
||||
def books_for_series(id):
|
||||
if request.method == 'POST':
|
||||
if 'move_button' in request.form:
|
||||
# split form's pressed move_button to yield: dir ("up" or "down") and bid = book_id of book
|
||||
dir, bid = request.form['move_button'].split('-')
|
||||
|
||||
def CalcMoveForBookInSeries( id, bid, dir ):
|
||||
book1 = Book.query.get(bid)
|
||||
|
||||
# if parent book, then up needs first sub book, if down then need last sub book (as parent book does not have a book_num in a series, its sub books do)
|
||||
if book1.IsParent():
|
||||
if dir == "up":
|
||||
@@ -313,6 +314,16 @@ def books_for_series(id):
|
||||
book1.MoveBookInSeries( id, b1_move_by )
|
||||
book2.MoveBookInSeries( id, b2_move_by )
|
||||
|
||||
@app.route("/books_for_series/<id>", methods=["GET", "POST"])
|
||||
def books_for_series(id):
|
||||
if request.method == 'POST':
|
||||
if 'move_button' in request.form:
|
||||
# split form's pressed move_button to yield: dir ("up" or "down") and bid = book_id of book
|
||||
dir, bid = request.form['move_button'].split('-')
|
||||
book1 = Book.query.get(bid)
|
||||
for bsl in book1.bsl:
|
||||
CalcMoveForBookInSeries( bsl.series_id, bid, dir )
|
||||
|
||||
books = Book.query.join(Book_Series_Link).filter(Book_Series_Link.series_id==id).all()
|
||||
series = Series.query.get(id)
|
||||
return render_template("books_for_series.html", books=books, series=series)
|
||||
@@ -362,7 +373,6 @@ def subbooks_for_book(id):
|
||||
################################################################################
|
||||
@app.route("/remove_subbook", methods=["POST"])
|
||||
def remove_sub_book():
|
||||
print("DDP: ADD SQL HERE TO DO THE DELETE - try/except")
|
||||
try:
|
||||
db.engine.execute("delete from book_sub_book_link where book_id = {} and sub_book_id = {}".format( request.form['rem_sub_parent_id'], request.form['rem_sub_sub_book_id']) )
|
||||
db.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user