コード例 #1
0
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')
コード例 #2
0
ファイル: app.py プロジェクト: ashans24/LibraryApp-First-
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)
コード例 #3
0
ファイル: app.py プロジェクト: ashans24/LibraryApp-First-
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)
コード例 #4
0
def user_book():
    form = SearchBookForm()
    return render_template('user-book.html', form=form)
コード例 #5
0
def search_book():  # 这个函数里不再处理提交按钮,使用Ajax局部刷新
    form = SearchBookForm()
    return render_template('search-book.html',
                           name=session.get('name'),
                           form=form)
コード例 #6
0
ファイル: ebook.py プロジェクト: JHolderguru/Web-front
def search():
    form = SearchBookForm()
    return render_template('search.html', title='Search for eBook', form=form)