def editCategory(category_name): """Edit a category Need to be logged in to be able to see the edit page. Args: category_name(str): the name of the category the object belongs to Returns: render the editCategory template if a GET request is sent redirect to the home page if the POST request succeeds""" if 'provider' in login_session: editedCategory = session.query(Category).filter_by( name=category_name).one() form = FormCategory() if form.validate_on_submit(): if len(form.name.data) > 0: editedCategory.name = form.name.data if len(form.name.data) > 0: editedCategory.image_loc = form.image_loc.data return redirect(url_for('showCategories')) return render_template('editCategory.html', category=editedCategory, form=form) else: flash("Please login to be able to edit a category") return redirect(url_for('showCategories'))
def newCategory(): """Create a category Need to be logged in to be able to see the edit page. Args: category_name(str): the name of the category the object belongs to Returns: render the newCategory template if a GET request is sent redirect to the home page if the POST request succeeds""" if 'provider' in login_session: form = FormCategory() if form.validate_on_submit(): newCategory = Category(name=form.name.data, image_loc=form.image_loc.data) session.add(newCategory) session.commit() return redirect(url_for('showCategories')) return render_template('newCategory.html', form=form) else: flash("Please login to be able to add a category") return redirect(url_for('showCategories'))