def displayItem(item_id): item = Item.getItemById(item_id) if not item: flash('Item {} not found'.format(item_id)) return redirect('main.homepage') return render_template("item_details.html", item=item, user=current_user)
def editItem(item_id): item = Item.getItemById(item_id) if not item: flash("Item () note found").form(item_id) return redirect(url_for(main.homepage)) next = get_redirect_target() form = ItemForm(next=next) form.category.choices = [(category.id, category.name) for category in Category.getAll()] if request.method == 'GET': form.name.data = item.name form.description.data = item.description form.category.data = item.category_id form.category.choices = [(category.id, category.name) for category in Category.getAll()] return render_template('item_form.html', form=form, name=item.name, description=item.description, category=item.category) if form.validate_on_submit(): item.name = form.data['name'] item.description = form.data['description'] cat_id = form.data['category'] item.category_id = form.data['category'] db.session.commit() return redirect_back('main.homepage')
def deleteItem(item_id): # Validate item_id item = Item.getItemById(item_id) if not item: flash('Item {} not found'.format(item_id)) return redirect_back('main.homepage') next = get_redirect_target() if request.method == 'POST': Item.delete(item_id) flash("{} deleted".format(item.name)) return redirect(url_for('main.homepage')) else: return render_template('item_delete.html', item=item, next=next)
def getItem(item_id): item = Item.getItemById(item_id) if not item: return jsonify("Item Not Found") else: return jsonify(item.serialize)