TODO 3 and 4 finished. removing parent or sub books from series handled
This commit is contained in:
5
README
5
README
@@ -31,11 +31,6 @@ python3 main.py
|
||||
MAYBE-1: 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)
|
||||
|
||||
#### TODOS (next 22):
|
||||
TODO-3: when remove a Parent book from a series (condition in code marked with BUG):
|
||||
- popup with: remove all sub books from series too?
|
||||
TODO-4: removing a subbook from a series (condition in code marked with BUG)
|
||||
- dont allow it & say remove sub book form parent book before we can act on this. OR:
|
||||
- popup with: this is a subbook, you want to remove the parent & all its sub books from the series?
|
||||
TODO-5: should deleting really just ask if want to mark it as SOLD?
|
||||
TODO-8: show books on shelf list
|
||||
TODO-9: show books to buy view / printable
|
||||
|
||||
25
main.py
25
main.py
@@ -444,6 +444,7 @@ def new_book():
|
||||
def book(id):
|
||||
book_form = BookForm(request.form)
|
||||
page_title='Edit Book'
|
||||
CheckSeriesChange=None
|
||||
if request.method == 'POST':
|
||||
if 'delete' in request.form:
|
||||
book = Book.query.get(id)
|
||||
@@ -502,16 +503,20 @@ def book(id):
|
||||
book.author.append( Author.query.get( request.form[el] ) )
|
||||
|
||||
still_in_series=0
|
||||
still_in_series_sid=99999
|
||||
if book.IsParent():
|
||||
for field in request.form:
|
||||
if 'bsl-book_num-' in field and field != 'bsl-book_num-NUM' and request.form[field] == 'PARENT':
|
||||
cnt=int(re.findall( '\d+', field )[0])
|
||||
print("cnt={}".format(cnt))
|
||||
still_in_series_sid=request.form['bsl-series_id-{}'.format(cnt)]
|
||||
still_in_series=1
|
||||
|
||||
if book.IsChild() or (book.IsParent() and not still_in_series):
|
||||
if book.IsParent():
|
||||
print ( "BUG: Houston we have a problem, need to deal with parent book being moved out of series, without its subbooks... (IGNORING series change)" )
|
||||
CheckSeriesChange={'type':'parent', 'pid': book.id, 'bid': book.id}
|
||||
else:
|
||||
print ( "BUG: Houston we have a problem, need to deal with child book being moved out of series, without its parent... (IGNORING series change)" )
|
||||
CheckSeriesChange={'type':'child', 'pid': book.parent[0].id, 'bid': book.id }
|
||||
else:
|
||||
# delete all bsls
|
||||
db.engine.execute("delete from book_series_link where book_id = {}".format( book.id ) )
|
||||
@@ -544,8 +549,7 @@ def book(id):
|
||||
genre_list = GetGenres()
|
||||
|
||||
book_s = book_schema.dump(book)
|
||||
print( "parent={}".format(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() )
|
||||
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(), CheckSeriesChange=CheckSeriesChange)
|
||||
|
||||
def GetCount( what, where ):
|
||||
st="select count(id) as count from book where "
|
||||
@@ -603,6 +607,19 @@ def add_books_to_loan(id):
|
||||
print ("NOT SURE WHAT TO DO if we dont want output" )
|
||||
return redirect("/loan/{}".format(id))
|
||||
|
||||
@app.route("/rem_parent_books_from_series/<pid>", methods=["POST"])
|
||||
def rem_parent_books_from_series(pid):
|
||||
print ("pid={}".format(pid) )
|
||||
try:
|
||||
db.engine.execute("delete from book_series_link where book_id in ( select sub_book_id from book_sub_book_link where book_id = {} ) ".format( pid ))
|
||||
db.engine.execute("delete from book_series_link where book_id = {}".format( pid ))
|
||||
db.session.commit()
|
||||
except SQLAlchemyError as e:
|
||||
st.SetAlert("danger")
|
||||
st.SetMessage("Failed to delete parent & sub books from ALL series! -- {}".format( e.orig ))
|
||||
print ("NOT SURE WHAT TO DO if we dont want output - can we just return a 200?" )
|
||||
return redirect("/")
|
||||
|
||||
@app.route("/", methods=["GET"])
|
||||
def main_page():
|
||||
return render_template("base.html", alert=st.GetAlert(), message=st.GetMessage())
|
||||
|
||||
@@ -22,6 +22,46 @@
|
||||
|
||||
<script>
|
||||
|
||||
function ConfirmRemoveParentAndSubsFromSeries(pid,bid)
|
||||
{
|
||||
$('#dbox-title').html('Confirm: Removing Parent Book from Series')
|
||||
div=`
|
||||
<div class="row col-lg-12">
|
||||
<p class="lead">You have chosen to remove this (parent) book from a series.
|
||||
What should we do with the sub-books for <span style="background:red" class="text-white"><em>ALL</em></span> series?</p>
|
||||
</div class="row">
|
||||
<div class="row col-lg-12">
|
||||
<button id="RPS" class="btn btn-primary col-lg-2">Remove all children</button>
|
||||
<button onClick="$('#dbox').modal('hide')"
|
||||
class="btn btn-outline-danger offset-lg-8 col-lg-2"> Cancel Series change</button>
|
||||
</div class="row">
|
||||
`
|
||||
$('#dbox-content').html(div)
|
||||
$('#dbox').modal('show')
|
||||
// have to do this AFTER modal show otherwise it doesnt exist... (grrr)
|
||||
$('#RPS').attr( 'onClick', "$('#dbox').modal('hide') ; $.post( '/rem_parent_books_from_series/" +pid + "' ) ; window.location='/book/"+ bid + "'" )
|
||||
}
|
||||
|
||||
function ConfirmRemoveThisSubs_ParentAndSubsFromSeries(pid,bid)
|
||||
{
|
||||
$('#dbox-title').html('Confirm: Removing Sub Book from Series')
|
||||
div=`
|
||||
<div class="row col-lg-12">
|
||||
<p>You have chosen to remove this (sub) book from a series.
|
||||
What should we do with the parent and all its sub-books for <span style="background:red" class="text-white"><em>ALL</em></span>series?</p>
|
||||
</div class="row">
|
||||
<div class="row col-lg-12">
|
||||
<button id="RPS" class="btn btn-primary col-lg-2">Remove parent and all children too</button>
|
||||
<button onClick="$('#dbox').modal('hide')" class="btn btn-outline-danger offset-lg-8 col-lg-2">
|
||||
Cancel Series change</button>
|
||||
</div class="row">
|
||||
`
|
||||
$('#dbox-content').html(div)
|
||||
$('#dbox').modal('show')
|
||||
// have to do this AFTER modal show otherwise it doesnt exist... (grrr)
|
||||
$('#RPS').attr( 'onClick', "$('#dbox').modal('hide') ; $.post( '/rem_parent_books_from_series/" +pid + "' ) ; window.location='/book/"+ bid + "'" )
|
||||
}
|
||||
|
||||
function SeriesButPlus(num) {
|
||||
return '<div id="series-plus-div'+num+'" class="input-group-append"><button id="series-plus-but-'+num+'" class="btn btn-outline-success" type="button" onClick="AddBookToSeries()"><i class="fas fa-plus"></i></button></div>'
|
||||
}
|
||||
@@ -337,7 +377,15 @@ function AddAuthorToBook(num) {
|
||||
<script>
|
||||
$(document).ready( function() {
|
||||
$("#sub_book_content").load("/subbooks_for_book/{{books.id}}")
|
||||
{% if CheckSeriesChange is defined and CheckSeriesChange != None %}
|
||||
{% if CheckSeriesChange.type == 'parent' %}
|
||||
ConfirmRemoveParentAndSubsFromSeries( {{CheckSeriesChange.pid}}, {{CheckSeriesChange.bid}} )
|
||||
{% else %}
|
||||
ConfirmRemoveThisSubs_ParentAndSubsFromSeries( {{CheckSeriesChange.pid}}, {{CheckSeriesChange.bid}} )
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
} )
|
||||
|
||||
</script>
|
||||
{% endblock script_content %}
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user