remove book from stacks

This commit is contained in:
Alice 2018-06-07 23:05:55 +02:00
parent 869ed3f3bb
commit 2d8110585d
3 changed files with 19 additions and 5 deletions

View File

@ -4,7 +4,8 @@
<div class="container"> <div class="container">
<h1 class="header">{{ book.title }}</h1> <h1 class="header">{{ book.title }}</h1>
<img class="no_cover" id="{{ book.title }}" src="../uploads/cover/{{ book.cover }}" width="150" onerror="if (this.src != '../static/img/{{ book.cover }}') this.src = '../static/img/default_cover.gif';"> <img class="no_cover" id="{{ book.title }}" src="../uploads/cover/{{ book.cover }}" width="150" onerror="if (this.src != '../uploads/cover/{{ book.cover }}') this.src = '../static/img/default_cover.gif';">
<p>Author(s): <ul>{% for author in book.authors %} <p>Author(s): <ul>{% for author in book.authors %}
<li><a href="{{url_for('show_author_by_id', id=author.id)}}">{{ author.author_name }}</a> </li> <li><a href="{{url_for('show_author_by_id', id=author.id)}}">{{ author.author_name }}</a> </li>
@ -16,6 +17,8 @@
<p>Stack(s): <ul>{% for stack in book.stacks %} <p>Stack(s): <ul>{% for stack in book.stacks %}
<li><a href="{{url_for('show_stack_by_id', id=stack.id)}}">{{ stack.stack_name }}</a> <li><a href="{{url_for('show_stack_by_id', id=stack.id)}}">{{ stack.stack_name }}</a>
<p style="font-size: 10px;"><a href='{{url_for('remove_from_stack', stackid=stack.id, bookid=book.id)}}'> Remove from stack</a></p>
{% endfor %}</ul></p> {% endfor %}</ul></p>

View File

@ -9,7 +9,7 @@
<p>Books in this stack: {% for book in stack.books %} <p>Books in this stack: {% for book in stack.books %}
<li> <a href="{{url_for('show_book_by_id', id=book.id)}}">{{book.title}}</a> </li> <li> <a href="{{url_for('show_book_by_id', id=book.id)}}">{{book.title}}</a> </li>
<img class="no_cover" id="{{ book.title }}" src="../uploads/cover/{{ book.cover }}" width="150" onerror="if (this.src != '../static/img/{{ book.cover }}') this.src = '../static/img/default_cover.gif';"> <img class="no_cover" id="{{ book.title }}" src="../uploads/cover/{{ book.cover }}" width="150" onerror="if (this.src != '../uploads/cover/{{ book.cover }}') this.src = '../static/img/default_cover.gif';">
<div class='widget'> <div class='widget'>
<iframe src="../uploads/{{ book.file }}" width="50%" ></iframe> <iframe src="../uploads/{{ book.file }}" width="50%" ></iframe>
</div> </div>

View File

@ -136,7 +136,7 @@ def edit_book_by_id(id):
if user_form.validate_on_submit(): if user_form.validate_on_submit():
# on submit, check fields # on submit, check fields
title = user_form.title.data title = user_form.title.data
input_authors = user_form.author.data input_authors = user_form.author.data
category = user_form.category.data category = user_form.category.data
year_published = user_form.year_published.data year_published = user_form.year_published.data
if year_published=="": if year_published=="":
@ -336,6 +336,17 @@ def edit_stack_by_id(id):
return redirect(url_for('show_stack_by_id', id=id)) return redirect(url_for('show_stack_by_id', id=id))
return render_template('edit_stack_detail.html', stack=stack, form=form) return render_template('edit_stack_detail.html', stack=stack, form=form)
@app.route('/stacks/<int:stackid>/remove/<int:bookid>', methods=['POST', 'GET'])
def remove_from_stack(bookid, stackid):
book = Book.query.get(bookid)
stack = Stack.query.get(stackid)
if book not in stack.books:
return render_template('show_book_detail.html', book=book)
stack.books.remove(book)
db.session.commit()
return render_template('show_book_detail.html', book=book)
## search ## search
@app.route('/books', methods= ['POST','GET']) @app.route('/books', methods= ['POST','GET'])
@ -383,7 +394,7 @@ def search_results(searchtype, query):
count = results.count() count = results.count()
whole = Book.query.count() whole = Book.query.count()
percentage = float(count / whole * 100) percentage = float(count / whole * 100)
if search.listview.data: if search.listview.data:
return render_template('results.html', books=results, form=search, query=query, books_all=random_order, searchtype=search.select.data, count = count, whole = whole, percentage = percentage) return render_template('results.html', books=results, form=search, query=query, books_all=random_order, searchtype=search.select.data, count = count, whole = whole, percentage = percentage)
@ -395,7 +406,7 @@ def search_results(searchtype, query):
query = search.search.data query = search.search.data
results = [] results = []
return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data))) return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data)))
return render_template('results.html', form=search, books=results, books_all=random_order, searchtype=search.select.data, query=query, count = count, whole = whole, percentage = percentage) return render_template('results.html', form=search, books=results, books_all=random_order, searchtype=search.select.data, query=query, count = count, whole = whole, percentage = percentage)