def book_search(): form = SearchBookForm() choice = form.search_type.data query_string = form.query_input.data query_display_choices = [] if form.validate_on_submit(): if choice == "isbn": query_display_choices = [( book.isbn, book.title, book.author, book.books_id, book.year ) for book in db.execute( "SELECT isbn, title, author, books_id, year FROM books WHERE isbn LIKE :query_string ", { "query_string": "%" + query_string + "%" }).fetchall()] if query_display_choices == []: flash( 'Your query produced no results. Please, change your input and try again. ', category='danger') elif choice == "title": query_display_choices = [( book.isbn, book.title, book.author, book.books_id, book.year ) for book in db.execute( "SELECT isbn, title, author, books_id, year FROM books WHERE title LIKE :query_string", { "query_string": "%" + query_string + "%" }).fetchall()] if query_display_choices == []: flash( 'Your query produced no results. Please, change your input and try again. ', category='danger') elif choice == "author": query_display_choices = [( book.isbn, book.title, book.author, book.books_id, book.year ) for book in db.execute( "SELECT isbn, title, author, books_id, year FROM books WHERE author LIKE :query_string ", { "query_string": "%" + query_string + "%" }).fetchall()] if query_display_choices == []: flash( 'Your query produced no results. Please, change your input and try again. ', category='danger') return render_template('book_search.html', query_display_choices=query_display_choices, choice=choice, form=form, legend='Book Search')
def showBooks(search_param, page_num=1): if 'email' not in session: return redirect(url_for('login')) searchbookForm = SearchBookForm() bookList = queryBooks(search_param) print(bookList) return render_template('searchbooks.html', signin=True, form=searchbookForm, search=True, bookList=bookList)
def searchBooks(): if 'email' not in session: return redirect(url_for('login')) searchbookForm = SearchBookForm() if request.method == "POST": searchParam = request.form["searchBook"].replace(' ', '+') return redirect(url_for('showBooks', search_param=searchParam)) #return render_template('searchbooks.html', signin=True, form=SearchBookForm, search=False) else: return render_template('searchbooks.html', signin=True, form=searchbookForm, search=False)
def user_book(): form = SearchBookForm() return render_template('user-book.html', form=form)
def search_book(): # 这个函数里不再处理提交按钮,使用Ajax局部刷新 form = SearchBookForm() return render_template('search-book.html', name=session.get('name'), form=form)
def search(): form = SearchBookForm() return render_template('search.html', title='Search for eBook', form=form)