def editItem(category_id, item_id): if 'email' in login_session.keys(): edit_item = models.item_get(item_id) user_id = models.getUserID(login_session['email']) if edit_item.user_id == user_id: form = forms.itemForm(request.form) user = models.getUserInfo(user_id) category = models.category_get(category_id) if request.method == 'POST' and form.validate(): edit_item.name = form.name.data edit_item.image = form.image.data edit_item.description = form.description.data models.item_edit(edit_item) items = models.items_get_by_category(category_id) return render_template('categories/show.html', category=category, items=items, user=user) else: return render_template('items/edit.html', category=category, item=edit_item, form=form, user=user) else: flash("You aren't the owner for that.") return redirect(url_for('showCategory', category_id=category_id)) else: return redirect(url_for('showCategory', category_id=category_id))
def newItem(category_id): if 'email' in login_session.keys(): form = forms.itemForm(request.form) user_id = models.getUserID(login_session['email']) user = models.getUserInfo(user_id) category = models.category_get(category_id) if request.method == 'POST' and form.validate(): new_item = { "name": form.name.data, "image": form.image.data, "description": form.description.data, "user_id": models.getUserID(login_session['email']), "category_id": category_id } models.item_new(category_id, new_item) items = models.items_get_by_category(category_id) return render_template('categories/show.html', category=category, items=items, user=user) else: return render_template('items/new.html', category=category, form=form, user=user) else: return redirect(url_for('showCategory', category_id=category_id))