Exemplo n.º 1
0
Arquivo: views.py Projeto: sc17zm/cw2
def addbook(username):
    form = AddBookForm()

    if request.method == 'POST':
        x = Books()
        x.bookname = form.bookname.data
        x.bookgenre = form.bookgenre.data
        x.author = form.author.data
        x.user_name = username
        db.session.add(x)
        db.session.commit()
        flash("Book Added Succesfully")

    return render_template("addbook.html",
                           title='Read a Book',
                           form=form,
                           username=username)
Exemplo n.º 2
0
def async_new_book_add(title,isbn,description,pages,author,category,language,num_copies):
    new_book = Books()
    new_book.title = title.strip()
    new_book.isbn = isbn.strip()
    new_book.description = description.strip()
    new_book.pages = pages
    authors = [author.strip() for author in author.split(",")]
    categories = [category.strip() for category in category.split(",")]
    new_book.author = authors
    new_book.category = categories
    new_book.language = language.strip()
    new_book.num_copies = num_copies

    db.session.add(new_book)
    db.session.commit()

    for _ in range(int(new_book.num_copies)):
        new_copy = BookCopies()
        new_copy.title = new_book.title
        new_copy.book_id = new_book.id
        new_book.copies.append(new_copy)
        db.session.add(new_copy)
        db.session.commit()