|
|
@ -109,9 +109,9 @@ def search_to_shelf(shelf_id):
|
|
|
|
book_ids = list()
|
|
|
|
book_ids = list()
|
|
|
|
for book_id in books_in_shelf:
|
|
|
|
for book_id in books_in_shelf:
|
|
|
|
book_ids.append(book_id.book_id)
|
|
|
|
book_ids.append(book_id.book_id)
|
|
|
|
for id in searched_ids[current_user.id]:
|
|
|
|
for searchid in searched_ids[current_user.id]:
|
|
|
|
if id not in book_ids:
|
|
|
|
if searchid not in book_ids:
|
|
|
|
books_for_shelf.append(id)
|
|
|
|
books_for_shelf.append(searchid)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
books_for_shelf = searched_ids[current_user.id]
|
|
|
|
books_for_shelf = searched_ids[current_user.id]
|
|
|
|
|
|
|
|
|
|
|
@ -259,10 +259,11 @@ def delete_shelf(shelf_id):
|
|
|
|
app.logger.info(_(u"successfully deleted shelf %(name)s", name=cur_shelf.name, category="success"))
|
|
|
|
app.logger.info(_(u"successfully deleted shelf %(name)s", name=cur_shelf.name, category="success"))
|
|
|
|
return redirect(url_for('web.index'))
|
|
|
|
return redirect(url_for('web.index'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @shelf.route("/shelfdown/<int:shelf_id>")
|
|
|
|
@shelf.route("/shelf/<int:shelf_id>")
|
|
|
|
@shelf.route("/shelf/<int:shelf_id>", defaults={'type': 1})
|
|
|
|
|
|
|
|
@shelf.route("/shelf/<int:shelf_id>/<int:type>")
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
def show_shelf(shelf_id):
|
|
|
|
def show_shelf(type, shelf_id):
|
|
|
|
if current_user.is_anonymous:
|
|
|
|
if current_user.is_anonymous:
|
|
|
|
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
|
|
|
|
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -273,6 +274,8 @@ def show_shelf(shelf_id):
|
|
|
|
result = list()
|
|
|
|
result = list()
|
|
|
|
# user is allowed to access shelf
|
|
|
|
# user is allowed to access shelf
|
|
|
|
if shelf:
|
|
|
|
if shelf:
|
|
|
|
|
|
|
|
page = "shelf.html" if type == 1 else 'shelfdown.html'
|
|
|
|
|
|
|
|
|
|
|
|
books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).order_by(
|
|
|
|
books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).order_by(
|
|
|
|
ub.BookShelf.order.asc()).all()
|
|
|
|
ub.BookShelf.order.asc()).all()
|
|
|
|
for book in books_in_shelf:
|
|
|
|
for book in books_in_shelf:
|
|
|
@ -283,41 +286,13 @@ def show_shelf(shelf_id):
|
|
|
|
app.logger.info('Not existing book %s in shelf %s deleted' % (book.book_id, shelf.id))
|
|
|
|
app.logger.info('Not existing book %s in shelf %s deleted' % (book.book_id, shelf.id))
|
|
|
|
ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == book.book_id).delete()
|
|
|
|
ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == book.book_id).delete()
|
|
|
|
ub.session.commit()
|
|
|
|
ub.session.commit()
|
|
|
|
return render_title_template('shelf.html', entries=result, title=_(u"Shelf: '%(name)s'", name=shelf.name),
|
|
|
|
return render_title_template(page, entries=result, title=_(u"Shelf: '%(name)s'", name=shelf.name),
|
|
|
|
shelf=shelf, page="shelf")
|
|
|
|
shelf=shelf, page="shelf")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
flash(_(u"Error opening shelf. Shelf does not exist or is not accessible"), category="error")
|
|
|
|
flash(_(u"Error opening shelf. Shelf does not exist or is not accessible"), category="error")
|
|
|
|
return redirect(url_for("web.index"))
|
|
|
|
return redirect(url_for("web.index"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@shelf.route("/shelfdown/<int:shelf_id>")
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
def show_shelf_down(shelf_id):
|
|
|
|
|
|
|
|
if current_user.is_anonymous:
|
|
|
|
|
|
|
|
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id),
|
|
|
|
|
|
|
|
ub.Shelf.id == shelf_id),
|
|
|
|
|
|
|
|
ub.and_(ub.Shelf.is_public == 1,
|
|
|
|
|
|
|
|
ub.Shelf.id == shelf_id))).first()
|
|
|
|
|
|
|
|
result = list()
|
|
|
|
|
|
|
|
# user is allowed to access shelf
|
|
|
|
|
|
|
|
if shelf:
|
|
|
|
|
|
|
|
books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).order_by(
|
|
|
|
|
|
|
|
ub.BookShelf.order.asc()).all()
|
|
|
|
|
|
|
|
for book in books_in_shelf:
|
|
|
|
|
|
|
|
cur_book = db.session.query(db.Books).filter(db.Books.id == book.book_id).first()
|
|
|
|
|
|
|
|
if cur_book:
|
|
|
|
|
|
|
|
result.append(cur_book)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
app.logger.info('Not existing book %s in shelf %s deleted' % (book.book_id, shelf.id))
|
|
|
|
|
|
|
|
ub.session.query(ub.BookShelf).filter(ub.BookShelf.book_id == book.book_id).delete()
|
|
|
|
|
|
|
|
ub.session.commit()
|
|
|
|
|
|
|
|
return render_title_template('shelfdown.html', entries=result, title=_(u"Shelf: '%(name)s'", name=shelf.name),
|
|
|
|
|
|
|
|
shelf=shelf, page="shelf")
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
flash(_(u"Error opening shelf. Shelf does not exist or is not accessible"), category="error")
|
|
|
|
|
|
|
|
return redirect(url_for("web.index"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@shelf.route("/shelf/order/<int:shelf_id>", methods=["GET", "POST"])
|
|
|
|
@shelf.route("/shelf/order/<int:shelf_id>", methods=["GET", "POST"])
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|