def add_category(): form_login = LoginForm() form_register = RegisterForm() form_cat = Add_Category() if form_cat.validate_on_submit(): category = Category(Name=form_cat.Name.data) db.session.add(category) db.session.commit() flash('New Category has been added!', 'success') else: flash('Error: The category alredy exists!', 'danger ') return jsonify(data=form_cat.errors)
def add_category(): form_cat = Add_Category() if request.method == 'POST': catName = request.form['catName'] category = Category(Name=catName) db.session.add(category) db.session.commit() flash('New category name has been added!', 'success') elif form_cat.validate_on_submit(): flash('Error: The category alredy exists!', 'danger ') form = Add_Book() return render_template('category/cat_options.html', form=form)
def add_book(): form = Add_Book() form_login = LoginForm() form_register = RegisterForm() form_cat = Add_Category() form_publisher = Add_Publisher() form_author = Add_Author() author = form.author.data publisher = form.publisher.data category = form.category.data if form.validate_on_submit(): book = Book(title=form.title.data, year=form.year.data, book_cover=form.book_cover.data, description=form.description.data, publisher_id=publisher.PublisherId, category_id=category.CategoryId, author_id=author.AuthorId) db.session.add(book) db.session.commit() flash('New Book has been added!', 'success') return redirect(url_for('main.index')) return render_template('book/add_book.html', title='New Book', form=form, legend='Add Book', form_login=form_login, form_register=form_register, form_cat=form_cat, form_publisher=form_publisher, form_author=form_author)
def edit_category(category_id): category = Category.query.get_or_404(category_id) form_cat = Add_Category() form_login = LoginForm() form_register = RegisterForm() if form_cat.validate_on_submit(): category.Name = form_cat.Name.data db.session.commit() flash('The category name has been updated!', 'success') elif request.method == 'GET': form_cat.Name.data = category.Name else: flash('Error: The category alredy exists!', 'danger ') categories = Category.query.all() return render_template('category/categories.html', categories=categories, title='Categories', form_cat=form_cat, form_login=form_login, form_register=form_register)
def all_categories(): form_cat = Add_Category() form_login = LoginForm() form_register = RegisterForm() categories = Category.query.all() return render_template('category/categories.html', categories=categories, title='Categories', form_cat=form_cat, form_login=form_login, form_register=form_register)
def edit_book(book_isbn): book = Book.query.get_or_404(book_isbn) form = Add_Book() form_login = LoginForm() form_register = RegisterForm() form_cat = Add_Category() form_publisher = Add_Publisher() form_author = Add_Author() if form.validate_on_submit(): book.title = form.title.data book.year = form.year.data book.book_cover = form.book_cover.data book.description = form.description.data publisher = form.publisher.data book.publisher_id = publisher.PublisherId category = form.category.data book.category_id = category.CategoryId author = form.author.data book.author_id = author.AuthorId db.session.commit() flash('The book detailes has been edited!', 'success') return redirect(url_for('books.book', book_isbn=book.isbn)) elif request.method == 'GET': form.title.data = book.title form.year.data = book.year form.book_cover.data = book.book_cover form.description.data = book.description form.publisher.data = book.publisher form.category.data = book.category form.author.data = book.author return render_template('book/add_book.html', title='Edit Book', form=form, legend='Edit Book', form_login=form_login, form_register=form_register, form_cat=form_cat, form_publisher=form_publisher, form_author=form_author)