fix empty book route

This commit is contained in:
Kostiantyn Stoliarskyi 2023-04-21 17:02:43 +03:00
parent 5d58a16d2e
commit 585adc1192
1 changed files with 11 additions and 8 deletions

View File

@ -18,18 +18,21 @@ bp = Blueprint("books", __name__, url_prefix="/books")
@bp.route("/", methods=["GET"])
def get_all():
q = request.args.get("q", type=str, default=None)
books = m.Book.query.order_by(m.Book.id)
if q:
books = books.filter(m.Book.label.like(f"{q}"))
# q = request.args.get("q", type=str, default=None)
# books = m.Book.query.order_by(m.Book.id)
# if q:
# books = books.filter(m.Book.label.like(f"{q}"))
pagination = create_pagination(total=books.count())
# pagination = create_pagination(total=books.count())
# return render_template(
# "books/index.html",
# books=books.paginate(page=pagination.page, per_page=pagination.per_page),
# page=pagination,
# search_query=q,
# )
return render_template(
"books/index.html",
books=books.paginate(page=pagination.page, per_page=pagination.per_page),
page=pagination,
search_query=q,
)