def getBook(book_id): book = Book.findById(book_id) # DELETE Method Override if request.query.get('_method') == "DELETE": delete_book(book_id) if book: return template('show_book', book=book) abort(404)
def check_out(book_id): username = request.forms.get("username") book = Book.findById(book_id) if (username and book): book.check_out(username) redirect('/books/%i'%book_id) if (book): abort(403) abort(404)
def edit_book(book_id): book = Book.findById(book_id) if book: title = request.forms.get("title") author = request.forms.get("author") year = request.forms.get("year") desc = request.forms.get("desc") new_book_dict = {} if (title): new_book_dict["title"] = title if (author): new_book_dict["author"] = author if (year): new_book_dict["year"] = int(year) if (desc): new_book_dict["desc"] = desc for field, value in new_book_dict.items(): book.__dict__[field] = value book.save() redirect('/books/%i' % book_id) abort(404)
def delete_book(book_id): book = Book.findById(book_id) if book: book.delete() redirect('/') abort(404)