swap order of books in series works - still has debugs, and only works on current series, e.g. if you are in a series in a series, it will need you to manually do the same move in both series - I think I wont fix this bit, but we will see
This commit is contained in:
22
main.py
22
main.py
@@ -162,8 +162,28 @@ def books_for_loan(id):
|
|||||||
books = Book.query.join(Book_Loan_Link).filter(Book_Loan_Link.loan_id==id).order_by(Book.id).all()
|
books = Book.query.join(Book_Loan_Link).filter(Book_Loan_Link.loan_id==id).order_by(Book.id).all()
|
||||||
return render_template("books_for_loan.html", books=books)
|
return render_template("books_for_loan.html", books=books)
|
||||||
|
|
||||||
@app.route("/books_for_series/<id>", methods=["GET"])
|
@app.route("/books_for_series/<id>", methods=["GET", "POST"])
|
||||||
def books_for_series(id):
|
def books_for_series(id):
|
||||||
|
if request.method == 'POST':
|
||||||
|
if 'move_button' in request.form:
|
||||||
|
print( 'we are moving a book up or down in series, we pressed: ' + request.form['move_button'] )
|
||||||
|
dir, bid = request.form['move_button'].split('-')
|
||||||
|
print( "dir="+dir)
|
||||||
|
print( "bid="+bid)
|
||||||
|
print( "id="+id)
|
||||||
|
bsl1=Book_Series_Link.query.filter(Book_Series_Link.series_id==id, Book_Series_Link.book_id==bid).all()
|
||||||
|
print( bsl1[0].book_num )
|
||||||
|
if dir == "up":
|
||||||
|
other_bn=bsl1[0].book_num-1
|
||||||
|
else:
|
||||||
|
other_bn=bsl1[0].book_num+1
|
||||||
|
bsl2=Book_Series_Link.query.filter(Book_Series_Link.series_id==id, Book_Series_Link.book_num==other_bn).all()
|
||||||
|
print( bsl1[0].book_id )
|
||||||
|
print( "swap with book: " )
|
||||||
|
print( bsl2[0].book_id )
|
||||||
|
bsl2[0].book_num=bsl1[0].book_num
|
||||||
|
bsl1[0].book_num=other_bn
|
||||||
|
db.session.commit()
|
||||||
books = Book.query.join(Book_Series_Link).filter(Book_Series_Link.series_id==id).order_by(Book.id).all()
|
books = Book.query.join(Book_Series_Link).filter(Book_Series_Link.series_id==id).order_by(Book.id).all()
|
||||||
series = Series.query.get(id)
|
series = Series.query.get(id)
|
||||||
return render_template("books_for_series.html", books=books, series=series)
|
return render_template("books_for_series.html", books=books, series=series)
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ def series(id):
|
|||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if 'move_button' in request.form:
|
if 'move_button' in request.form:
|
||||||
print( 'maybe we are moving a book up or down in series, we pressed: ' + request.form['move_button'] )
|
print( 'maybe we are moving a book up or down in series, we pressed: ' + request.form['move_button'] )
|
||||||
|
dir, id = request.form['move_button'].split('-')
|
||||||
|
print( "dir="+dir)
|
||||||
|
print( "id="+id)
|
||||||
if request.method == 'POST' and series_form.validate_on_submit():
|
if request.method == 'POST' and series_form.validate_on_submit():
|
||||||
id = request.form['id']
|
id = request.form['id']
|
||||||
series = Series.query.get(id)
|
series = Series.query.get(id)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
<form action="" method="POST">
|
|
||||||
<table id="book_table" class="table table-striped table-sm small" data-toolbar="#toolbar" data-search="true">
|
<table id="book_table" class="table table-striped table-sm small" data-toolbar="#toolbar" data-search="true">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="thead-light"><th>Title</th><th>Book Number</th></tr>
|
<tr class="thead-light"><th>Title</th><th>Book Number</th></tr>
|
||||||
@@ -11,9 +10,21 @@
|
|||||||
{% if book.parent_ref|length %}
|
{% if book.parent_ref|length %}
|
||||||
{% set style="style=visibility:hidden" %}
|
{% set style="style=visibility:hidden" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<button type="submit" name="move_button" value="up-{{book.id}}" id="up-{{book.id}}" class="btn btn-outline-primary btn-small" {{style}}>
|
<button name="move_button" value="up-{{book.id}}" id="up-{{book.id}}" class="btn btn-outline-primary btn-small" {{style}}
|
||||||
<i class="fas fa-angle-double-up"></i></button>
|
onClick="$.ajax({
|
||||||
<button type="submit" name="move_button" value="down-{{book.id}}" id="down-{{book.id}}" class="btn btn-outline-primary btn-small" {{style}}>
|
type: 'POST', url: '/books_for_series/{{series.id}}',
|
||||||
|
data: '&id={{series.id}}&move_button=up-{{book.id}}',
|
||||||
|
success: function(data){
|
||||||
|
$('#books_for_series_bit').html(data); }
|
||||||
|
} );">
|
||||||
|
<i class="fas fa-angle-double-up" ></i></button>
|
||||||
|
<button name="move_button" value="down-{{book.id}}" id="down-{{book.id}}" class="btn btn-outline-primary btn-small" {{style}}
|
||||||
|
onClick="$.ajax({
|
||||||
|
type: 'POST', url: '/books_for_series/{{series.id}}',
|
||||||
|
data: '&id={{series.id}}&move_button=down-{{book.id}}',
|
||||||
|
success: function(data){
|
||||||
|
$('#books_for_series_bit').html(data); }
|
||||||
|
} );">
|
||||||
<i class="fas fa-angle-double-down"></i></button>
|
<i class="fas fa-angle-double-down"></i></button>
|
||||||
<a href="/book/{{book.id}}">{{book.title}}</a>
|
<a href="/book/{{book.id}}">{{book.title}}</a>
|
||||||
</td>
|
</td>
|
||||||
@@ -53,7 +64,6 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
|
||||||
|
|
||||||
<script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
|
<script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
|
||||||
<script src="https://cdn.datatables.net/1.10.22/js/dataTables.bootstrap4.min.js"></script>
|
<script src="https://cdn.datatables.net/1.10.22/js/dataTables.bootstrap4.min.js"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user