Exemplo n.º 1
0
def books_edit():
    id = request.args.get("book_id")
    book = Book.query.get(id)
    form = BookForm(obj=book)
    if request.method == 'POST' and form.validate():
        form.populate_obj(book)
        db.session().commit()
        flash('Kirjan tiedot päivitetty!')
        return redirect(url_for("books_index"))
    return render_template('books/edit.html', form=form)
Exemplo n.º 2
0
def books_create():
    form = BookForm(request.form)

    if not form.validate():
        return render_template("books/new.html", form=form)

    b = Book(form.title.data, form.author.data, form.description.data,
             form.isbn.data)

    db.session().add(b)
    db.session().commit()

    return redirect(url_for("books_index"))
Exemplo n.º 3
0
def books_create():
    form = BookForm(request.form)

    if not form.validate():
        return render_template("books/new.html", form = form)
        
    b = Book(form.title.data, form.author.data, form.year.data, form.language.data, form.price.data, form.amount.data,
    form.available.data)

    db.session().add(b)
    db.session().commit()
  
    return redirect(url_for("books_index"))
Exemplo n.º 4
0
def books_update(book_id):
    form = BookForm(request.form)

    if not form.validate():
        return render_template("books/edit.html",
                               book=Book.query.get(book_id),
                               form=form)

    b = Book.query.get(book_id)
    b.title = form.title.data
    b.author = form.author.data
    b.description = form.description.data
    db.session().commit()

    return redirect(url_for('book_show', book_id=book_id))
Exemplo n.º 5
0
def books_create():
    form = BookForm(request.form)

    if not form.validate():
        return render_template("books/new.html", form=form)

    book = Book(form.name.data)
    book.read = form.read.data
    book.account_id = current_user.id
    series = form.series.data
    if not series:
        book.series_id = 0
    else:
        s = Series.query.filter_by(name=series).first()
        if s is None:
            s = Series(series)
            db.session.add(s)
            db.session.commit()
        book.series_id = s.id

    genres = form.genres.data.split(";")

    for genre in genres:
        g = Genre.query.filter_by(name=genre).first()
        if g is not None:
            book.genres.append(g)
        else:
            g = Genre(genre)
            db.session.add(g)
            book.genres.append(g)
        db.session.commit()

    authors = form.authors.data.split(";")

    for author in authors:
        a = Author.query.filter_by(name=author).first()
        if a is not None:
            book.authors.append(a)
        else:
            a = Author(author)
            db.session.add(a)
            book.authors.append(a)
        db.session.commit()

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

    return redirect(url_for("books_index"))
Exemplo n.º 6
0
def books_create():
    form = BookForm(request.form)
    user = current_user

    if not form.validate():
        return render_template("books/new.html", form=form)

    book = Book(form.name.data)
    book.read = form.read.data
    book.account_id = current_user.id

    if book.read:
        user.read_books.append(book)

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

    return redirect(url_for("books_index"))
Exemplo n.º 7
0
def books_new():
    form = BookForm(request.form)
    form.update_choices(Author.query.all(), Genre.query.all())
    if not form.validate():
        print(form)
        return render_template("books/new.html", form=form)
    title = form.title.data
    new_book = Book(title)
    new_book.author_id = form.author.data

    for id in form.genre.data:
        genre = Genre.query.get(id)
        new_book.genres.append(genre)

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

    return redirect(url_for("books_index"))
Exemplo n.º 8
0
def books_save(book_id):

    form = BookForm(request.form)

    if not form.validate():
        return render_template("books/new.html", form=form, num=book_id)

    book = Book.query.get(book_id)
    author = Author.query.get(book_id)

    author.name = form.author.data
    book.name = form.name.data
    book.published = form.published.data
    book.count = form.count.data
    book.desc = form.desc.data
    book.account_id = current_user.id

    db.session().commit()

    return redirect(url_for("books_index"))
Exemplo n.º 9
0
def books_modify(book_id):

    book = Book.query.get(book_id)
    author = Author.query.get(book_id)
    form = BookForm()
    form.name.data = book.name
    form.author.data = author.name
    form.published.data = book.published
    form.count.data = book.count
    form.desc.data = book.desc

    return render_template("books/new.html", form=form, num=book_id)
Exemplo n.º 10
0
def books_create():
    form = BookForm(request.form)

    if not form.validate():
        return render_template("books/new.html", form=form, num=0)

    book = Book(form.name.data)
    author = Author(form.author.data)

    db.session().add(author)

    book.author.append(author)
    book.published = form.published.data
    book.count = form.count.data
    book.desc = form.desc.data
    book.account_id = current_user.id

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

    return redirect(url_for("books_index"))
Exemplo n.º 11
0
def books_form():
    return render_template("books/new.html", form=BookForm(), num=0)
Exemplo n.º 12
0
def books_edit(book_id):
    form = BookForm(request.form)
    form.description.data = Book.query.get(book_id).description
    return render_template("books/edit.html",
                           book=Book.query.get(book_id),
                           form=form)
Exemplo n.º 13
0
def books_index():
    return render_template(
        "books/list.html",
        books=Book.query.order_by("id").filter_by(account_id=current_user.id),
        form=BookForm())
Exemplo n.º 14
0
def books_form():
    form = BookForm()
    form.update_choices(Author.query.all(), Genre.query.all())
    return render_template("books/new.html", form=form)
Exemplo n.º 15
0
def book_view():
    book_id = request.args.get("book_id")
    return render_template('books/book.html', book = Book.query.get(book_id), form=BookForm())