diff --git a/cps/templates/detail.html b/cps/templates/detail.html
index 227a57ec..6cb241f5 100644
--- a/cps/templates/detail.html
+++ b/cps/templates/detail.html
@@ -47,26 +47,9 @@
- {% if g.user.shelf.all() or g.public_shelfes %}
- -
-
-
-
-
-
- {% endif %}
{% if g.user.kindle_mail %}
- Send ebook to kindle
+ Send to Kindle
{% endif %}
@@ -80,8 +63,8 @@
-->
-
-
- read this book online
+ Read online
+
+ {% if g.user.shelf.all() or g.public_shelfes %}
+ -
+
+
+ Add to shelf
+
+
+
+
+ {% endif %}
+
+
+ {% if books_shelfs %}
+ -
+
+
+ Remove from shelf
+
+
+
+
+ {% endif %}
{% if g.user.roleĀ %}
- Edit book
- Delete book
+ Edit book
+ Delete book
{% endif %}
{% endif %}
diff --git a/cps/web.py b/cps/web.py
index c17e5535..bf38d976 100755
--- a/cps/web.py
+++ b/cps/web.py
@@ -206,7 +206,11 @@ def discover(page):
@app.route("/book/")
def show_book(id):
entries = db.session.query(db.Books).filter(db.Books.id == id).first()
- return render_template('detail.html', entry=entries, title=entries.title)
+ book_in_shelfs = []
+ shelfs = ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == id).all()
+ for entry in shelfs:
+ book_in_shelfs.append(entry.shelf)
+ return render_template('detail.html', entry=entries, title=entries.title, books_shelfs=book_in_shelfs)
@app.route("/category")
def category_list():
@@ -348,6 +352,27 @@ def add_to_shelf(shelf_id, book_id):
ub.session.add(ins)
ub.session.commit()
+ flash("Book has been added to shelf: %s" % shelf.name, category="success")
+
+ #return redirect(url_for('show_book', id=book_id))
+ return redirect(request.environ["HTTP_REFERER"])
+
+@app.route("/shelf/remove//")
+@login_required
+def remove_from_shelf(shelf_id, book_id):
+ shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.id == shelf_id).first()
+ if not shelf.is_public and not shelf.user_id == int(current_user.id):
+ flash("Sorry you are not allowed to remove a book from this shelf: %s" % shelf.name)
+ return redirect(url_for('index'))
+
+ book_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id, ub.BookShelf.book_id == book_id).first()
+
+ #rem = ub.BookShelf(shelf=shelf.id, book_id=book_id)
+ ub.session.delete(book_shelf)
+ ub.session.commit()
+
+ flash("Book has been removed from shelf: %s" % shelf.name, category="success")
+
return redirect(request.environ["HTTP_REFERER"])
@app.route("/shelf/create", methods=["GET", "POST"])