예제 #1
0
def book_detail(book_id):
    book = Book.query.get(book_id)
    form = BookForm(obj=book)

    if form.validate_on_submit():
        book.title = form.title.data
        book.publish_date = form.publish_date.data
        book.author = form.author.data
        book.audience = form.audience.data
        book.genres = form.genres.data
        flash('Success')
        db.session.commit()
        return redirect('main.book_detail', book_id=book_id)
    return render_template('book_detail.html', book=book, form=form)
예제 #2
0
def create_book():
    form = BookForm()

    # if form was submitted and contained no errors
    if form.validate_on_submit():
        new_book = Book(title=form.title.data,
                        publish_date=form.publish_date.data,
                        author=form.author.data,
                        audience=form.audience.data,
                        genres=form.genres.data)
        db.session.add(new_book)
        db.session.commit()

        flash('New book was created successfully.')
        return redirect(url_for('main.book_detail', book_id=new_book.id))
    return render_template('create_book.html', form=form)
예제 #3
0
def book_detail(book_id):
    book = Book.query.get(book_id)
    form = BookForm(obj=book)

    # TODO: If the form was submitted and is valid, update the fields in the
    # Book object and save to the database, then flash a success message to the
    # user and redirect to the book detail page

    return render_template('book_detail.html', book=book, form=form)
def book_detail(book_id):
    book = Book.query.get(book_id)
    form = BookForm(obj=book)

    # if form was submitted and contained no errors
    if form.validate_on_submit():
        book.title = form.title.data
        book.publish_date = form.publish_date.data
        book.author = form.author.data
        book.audience = form.audience.data
        book.genres = form.genres.data

        db.session.commit()

        flash('Book was updated successfully.')
        return redirect(url_for('main.book_detail', book_id=book_id))

    return render_template('book_detail.html', book=book, form=form)