Browse Source

remove book from stacks

ansible-setup-and-deploy
Alice 6 years ago
parent
commit
2d8110585d
  1. 5
      app/templates/show_book_detail.html
  2. 2
      app/templates/show_stack_detail.html
  3. 11
      app/views.py

5
app/templates/show_book_detail.html

@ -4,7 +4,8 @@
<div class="container">
<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 %}
<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 %}
<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>

2
app/templates/show_stack_detail.html

@ -9,7 +9,7 @@
<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>
<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'>
<iframe src="../uploads/{{ book.file }}" width="50%" ></iframe>
</div>

11
app/views.py

@ -336,6 +336,17 @@ def edit_stack_by_id(id):
return redirect(url_for('show_stack_by_id', id=id))
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
@app.route('/books', methods= ['POST','GET'])

Loading…
Cancel
Save