Exemple #1
0
def create_book(pub_id):
    form = CreateBookForm()
    form.pub_id.data = pub_id

    if form.validate_on_submit():
        book = Novel(title=form.title.data, author=form.author.data, avg_rating=form.avg_rating.data, image=form.image_url.data, book_format=form.book_format.data, num_pages=form.num_pages.data, pub_id=form.pub_id.data)
        db.session.add(book)
        db.session.commit()
        flash('Book Added Successfully')
        return redirect(url_for('main.display_publisher', publisher_id=pub_id))
    return render_template('create_book.html', form=form, pub_id=pub_id)
Exemple #2
0
def create_book(pub_id):
    form = CreateBookForm()
    form.pub_id.data = pub_id  # pre-populates this ID
    if form.validate_on_submit():
        book = Book(title=form.title.data,
                    author=form.author.data,
                    avg_rating=form.avg_rating.data,
                    book_format=form.format.data,
                    image=form.image_url.data,
                    num_pages=form.num_pages.data,
                    pub_id=form.pub_id.data)
        db.session.add(book)
        db.session.commit()
        flash("Book Added Successfully")
        return redirect(url_for("main.display_publisher", publisher_id=pub_id))
    return render_template("create_book.html", form=form, pub_id=pub_id)
Exemple #3
0
def create_book(pub_id):
    form = CreateBookForm()  # this imports the form to create the book
    form.pub_id.data = pub_id  # pre-populates pub_id
    if form.validate_on_submit():  # if post request
        book = Book(title=form.title.data,
                    author=form.author.data,
                    avg_rating=form.avg_rating.data,
                    book_format=form.format.data,
                    image=form.img_url.data,
                    num_pages=form.num_pages.data,
                    pub_id=form.pub_id.data)
        db.session.add(book)
        db.session.commit()
        flash('Book added successfully')
        return redirect(url_for('main.display_publisher', publisher_id=pub_id))
    return render_template('create_book.html', form=form,
                           pub_id=pub_id)  # get displays the form