def edit_item(category_name, item_name): """Depending on the request method, it shows a form prepopulated with the data of the item the user wants to edit, or executes code to update the item in the database. If there isn't a valid session present, the user is redirected to the index page. """ if check_acl() is None: return redirect(url_for('index')) if request.method == 'GET': form = CreateItemForm() cats = dao.get_categories() form.category.choices = [(g['_id'], g['name']) for g in cats] item = dao.get_item_by_name(item_name) form._objectId = item['_id'] form.category.process_data(item.get('cat_id')) form.title.process_data(item.get('title')) form.description.process_data(item.get('description')) return render_template('edit.html', form=form, session=session) else: form = request.form item = form_to_record(form) dao.update_item(form['_objectId'], item) flash('Item ' + item['title'] + " updated.") return redirect(url_for('index'))
def tworzenie_przedmiotu(): form = CreateItemForm() if form.validate_on_submit(): url_form = form.item_url.data check_prize_form = form.check_value.data try: data = scraper(url_form) except: flash("Niepoprawne URL, spróbuj ponownie.") return redirect(url_for("tworzenie_przedmiotu")) else: new_item = Item( name = data["name"], last_value = data["lowest_value"], item_url = url_form, check_value = check_prize_form, user_id = current_user.id ) db.session.add(new_item) db.session.commit() value_checker(new_item) return redirect(url_for("sledzenie_cen")) return render_template("tworzenie.html", form = form, current_user = current_user)
def add_item(request): createitemForm = CreateItemForm(request.POST or None) if createitemForm.is_valid(): createitemForm.save() return HttpResponseRedirect(reverse('list_items')) to_return = { 'form':createitemForm, } return render(request, 'finance/createitem.html', to_return)
def create_item(): form = CreateItemForm(request.form) if request.method == 'POST' and form.validate(): items = g.db['items'] items.insert_one({ 'name': form.item_name.data, 'price': float(form.price.data), 'description': form.description.data, 'created': datetime.utcnow() }) flash('The item was successfully created!', 'success') return redirect(url_for('index')) return render_template('create_item.html', form=form)