def books_index(): recent = Book.most_recent() popular = Book.most_popular_books() notes = Book.most_notes() return render_template("books/list.html", recent=recent, popular=popular, notes=notes)
def books_index(): user = current_user if user.is_authenticated: usersbooks = User.get_users_books(user.id) return render_template("books/list.html", books=Book.all_books(), user=user, usersbooks=usersbooks) else: return render_template("books/list.html", books=Book.all_books(), user=user)
def books_show(book_id): score = Book.average_score(book_id) if score != None: score = "%.2f" % score return render_template("books/book.html", book=Book.query.get(book_id), score=score)
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"))
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"))
def admin_delete_author(firstname, lastname): author = Author.query.filter_by(firstname=firstname, lastname=lastname).first() if request.method == "GET": return render_template("authors/deleteauthor.html", author=author) else: # change book names Author.change_booknames_todelete(author.id) # delete authorsbooks connection Author.delete_authorsbooks_connection(author.id) # delete usersbooks connection for books with changed name Book.delete_usersbooks_connection_todelete() # delete author Author.delete_author(author.firstname, author.lastname) # delete books with changed name Book.delete_books_todelete() flash("Kirjailija poistettiin onnistuneesti.", 'success') return redirect(url_for('authors_index'))
def books_new(): if request.method == "GET": return render_template("books/new.html", authors=Author.all_authors()) else: bookname = request.form["inputName"] year = request.form["inputYear"] pages = request.form["inputPages"] isbn = request.form["inputIsbn"] authorname = request.form["dropdown"] # check if any input is invalid (spaces) if bookname.isspace() or year.isspace() or pages.isspace( ) or isbn.isspace(): flash( "Virheellinen syöte (kentät eivät saa sisältää pelkästään välilyöntejä). Ole hyvä ja yritä uudestaan.", 'warning') return render_template("books/new.html", authors=Author.all_authors()) splitname = authorname.split(" ") author = Author.query.filter_by(firstname=splitname[0], lastname=splitname[1]).first() # check if the book already in database booknamequery = Book.check_if_book_with_name_and_authorid_exists( bookname, author.id) if booknamequery > 0: flash("Kyseinen kirja on jo lisätty tietokantaan.", 'warning') return render_template("books/new.html", authors=Author.all_authors()) book = Book(name=bookname, year=year, pages=pages, isbn=isbn) db.session().add(book) author.books.append(book) author.books_count = author.books_count + 1 db.session().commit() flash("Kirja lisätty onnistuneesti!", 'success') return redirect(url_for("books_index"))
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"))
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"))
def books_set_read_or_delete(book_id): if request.form["btn"] == "Merkitse luetuksi": Book.book_set_read(current_user.id, book_id) elif request.form["btn"] == "Merkitse lukemattomaksi": Book.book_set_unread(current_user.id, book_id) else: Book.book_delete_from_user(current_user.id, book_id) return redirect(url_for("auth_mybooks"))
def admin_delete_book(bookname, id): book = Book.book_info(id) if request.method == "GET": return render_template("books/deletebook.html", book=book) else: author = Author.query.filter_by(firstname=book.firstname, lastname=book.lastname).first() Book.delete_from_authorsbooks(id) Book.delete_from_usersbooks(id) Book.delete_book(bookname, id) author.books_count = author.books_count - 1 flash("Kirja poistettiin onnistuneesti.", 'success') return redirect(url_for('books_index'))
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"))
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"))
def books_info(book_id): return render_template("books/info.html", list_authors=Book.list_authors(book_id), loans_count=Book.loans_count(book_id), not_deleted_count=Book.not_deleted_count(book_id), book=Book.query.get(book_id))
def books_index(): return render_template("books/list.html", books=Book.average_rating_of_book())
def books_results(): search_term = "%" + request.form.get("seachTerm") + "%" res = Book.basic_search(search_term) return render_template("books/results.html", books=res)
def book_info(bookname): book = Book.query.filter_by(name=bookname).first() book = Book.book_info(book.id) return render_template("books/bookinfo.html", book=book)
def book_show(book_id): book = Book.query.get(book_id) book_notes = Book.book_notes_data(book_id) return render_template("books/book.html", book=book, book_notes=book_notes)
def book_edit_info(bookname, id): book = Book.book_info(id) currentauthor = Author.query.filter_by(firstname=book.firstname, lastname=book.lastname).first() if request.method == "GET": return render_template("books/editinfo.html", book=book, authors=Author.all_authors()) else: bookname = request.form["name"] year = request.form["year"] pages = request.form["pages"] isbn = request.form["isbn"] authorname = request.form["dropdown"] # check for empty inputs if bookname.isspace() or year.isspace() or pages.isspace( ) or isbn.isspace(): flash( "Virheellinen syöte (kentät eivät saa sisältää pelkästään välilyöntejä). Ole hyvä ja yritä uudestaan.", 'warning') return render_template("books/editinfo.html", book=book, authors=Author.all_authors()) splitname = authorname.split(" ") author = Author.query.filter_by(firstname=splitname[0], lastname=splitname[1]).first() authorchanged = False namechanged = False # check if author has changed if book.firstname != author.firstname and book.lastname != author.lastname: authorchanged = True # check if book name changed if bookname != book.name: namechanged = True # check if book info has changed if not namechanged and book.year == year and pages == book.pages and isbn == book.isbn and not authorchanged: flash("Et muuttanut tietoja.", 'info') return render_template("books/editinfo.html", book=book, authors=Author.all_authors()) # check if book with same name and author in database IF NAME OR AUTHOR HAS CHANGED if namechanged and authorchanged: booknamequery = Book.check_if_book_with_name_and_authorid_exists( bookname, author.id) if booknamequery > 0: flash("Kyseinen kirja on jo lisätty tietokantaan.", 'warning') return render_template("books/editinfo.html", book=book, authors=Author.all_authors()) else: Book.book_update_info(bookname, year, pages, isbn, book.id) if authorchanged: currentauthor.books_count = currentauthor.books_count - 1 # reduce previous author's book count author.books_count = author.books_count + 1 # add to new author's book count Book.update_authorsbooks(author.id, currentauthor.id, book.id) flash("Kirjan tiedot päivitetiin onnistuneesti!", 'success') return redirect(url_for("book_info", bookname=bookname))
def index(): return render_template("index.html", by_rating=Book.best_books(), by_loans=Book.top_loaned_books())