def get(self, item_id: int): item = self.catalog_service.get_category_item(item_id) if item is None: abort(404) categories = self.catalog_service.get_categories() form = EditItemForm() form.set_item(item, categories) return render_template('update_item.html', form=form)
def edit_item(list_id, item_id): list = List.objects.get(id=list_id) item = Item.objects.get(id=item_id) form = EditItemForm() if form.validate_on_submit(): name = form.name.data item.modify(name=name) return redirect(url_for('list', id=list_id)) elif request.method == 'GET': form.name.data = item.name return render_template('edit_item.html', form=form, item=item, list=list)
def post(self, item_id: int): categories = self.catalog_service.get_categories() form = EditItemForm(request.form) form.set_categories(categories) if form.validate_on_submit(): try: self.catalog_service.update_category_item(form, item_id) return redirect(url_for('catalog_item_view', item_id=item_id)) except Exception as e: return render_template('500.html', error=str(e)) return redirect(url_for('edit_catalog_item_view', item_id=item_id))
def edit(item_id): form = EditItemForm() item = Item.query.get(item_id) if item.user_id != current_user.id: flash('You are not allowed to edit this item') return redirect(url_for('index')) elif form.validate_on_submit(): item.title = form.title.data item.description = form.description.data item.category = form.opts.data db.session.commit() flash('Your changes: (Title: {}, Description: {}, Category: {}) \ have been saved!'.format(item.title, item.description, item.category.title)) return redirect(url_for('index')) elif request.method == 'GET': form.title.data = item.title form.description.data = item.description form.opts.data = item.category return render_template('edit.html', title='Edit Item', form=form)
def item_edit(id): item = Item.query.filter_by(id=id).first() form = EditItemForm(obj=item) if form.validate_on_submit(): item.description = form.description.data item.sku = form.sku.data item.item_number = form.item_number.data item.quantity = form.quantity.data item.cost = form.cost.data item.price = form.price.data db.session.commit() flash('Item updated') return redirect(url_for('item_edit', id=id)) elif request.method == 'GET': return render_template('item_add.html', title='Edit Item', form=form)
def edit_item(item_id): item = Item.query.get(item_id) if not (item in current_user.items): flash('You cannot edit that item.') return redirect(url_for('index')) form = EditItemForm() if form.validate_on_submit(): item.item_name = form.item_name.data item.item_description = form.item_description.data item.price = form.price.data item.initial_supply += form.num_available.data item.num_available += form.num_available.data db.session.commit() flash('Your changes have been saved.') return redirect(url_for('index')) elif request.method == 'GET': form.item_name.data = item.item_name form.item_description.data = item.item_description form.price.data = item.price form.num_available.data = 0 return render_template('edit_item.html', title='Edit Item', form=form)
def edit_item(id): item = get_item(id) form = EditItemForm(obj=item) if form.validate_on_submit(): if form.price.data < 0: flash("Cannot choose a negative price. Please try again") return redirect(url_for('edit_item', id=id)) if form.quantity.data < 0: flash("Cannot choose a negative quantity. Please try again") return redirect(url_for('edit_item', id=id)) item.name = form.name.data item.price = form.price.data item.quantity = form.quantity.data item.seller = current_user item.category = form.category.data item.description = form.description.data item.is_for_sale = form.is_for_sale.data db.session.commit() flash('Your changes have been saved.') return redirect(url_for('seller_summary')) return render_template('edit_item.html', title='Edit Item', form=form)
def edititem(iD): if (session.get('logged_in')): form = EditItemForm() search = SearchForm() if request.method == 'POST' and search.validate_on_submit(): return redirect((url_for('search_page', searchQuery=search.searchParam.data))) current_user = seller.query.filter_by( seller_id=session.get('user_id')).first() current_item = Inventory.query.filter_by(item_id=iD).first() item = { 'name': current_item.item_name, 'quantity': current_item.item_quantity, 'price': current_item.item_price, 'description': current_item.item_description } if form.validate_on_submit(): current_item.item_name = form.itemname.data current_item.item_quantity = form.itemquantity.data current_item.item_price = form.itemprice.data current_item.item_description = form.itemdescription.data db.session.commit() return redirect(url_for('account')) else: return redirect(url_for('index')) return render_template('edit.html', title="Add", form=form, search=search, user=current_user, item=item)
def update_category_item(self, form: EditItemForm, item_id: int) -> CategoryItem: new_item = form.build_item() new_item.id = item_id # Get the old item from the database and update its values before # committing changes. session = self.dbsetup.create_session() old_item = session.query(CategoryItem) \ .filter(CategoryItem.id == item_id) \ .one() old_item.name = new_item.name old_item.description = new_item.description old_item.category_id = new_item.category_id session.commit() session.close() return new_item