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

    if form.submit.data and 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()

    return render_template('book_detail.html', book=book, form=form)
예제 #2
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
        db.session.commit()
        flash(f"{book.title} was updated successfully.")
        return redirect(url_for("main.book_detail"))

    return render_template("book_detail.html", book=book, form=form)
예제 #3
0
def create_book():
    form = BookForm()
    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)
예제 #4
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)
예제 #5
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

        db.session.add(book)
        db.session.commit()

        flash('Book was successfully edited.')
    return render_template('book_detail.html', book=book, form=form)
예제 #6
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)
예제 #7
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
    if form.validate_on_submit():
        book.title = (form.title.data,)
        book.publish_date = (form.publish_data.data,)
        book.author = (form.author.data,)
        book.audience = (form.audience.data,)
        book.genres = form.genres.data
    db.session.add(book)
    db.session.commit()

    flash("Book was successfully updated.")
    return render_template("book_detail.html", book=book, form=form)