コード例 #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
ファイル: routes.py プロジェクト: fibeep/WTForms-Flask-BEW1.2
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
ファイル: routes.py プロジェクト: fibeep/WTForms-Flask-BEW1.2
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)