def new_store(): """ Add a new store """ form = StoreForm(request.form) if request.method == 'POST' and form.validate(): # save the store store = Store() save_changes(store, form, new=True) flash('Store created successfully!') return redirect('/') return render_template('new_store.html', form=form)
def edit(id): qry = db_session.query(Store).filter( Store.id==id) store = qry.first() if store: form = StoreForm(formdata=request.form, obj=store) if request.method == 'POST' and form.validate(): # save edits save_changes(store, form) flash('Store updated successfully!') return redirect('/') return render_template('edit_store.html', form=form) else: return 'Error loading #{id}'.format(id=id)
def delete(id): """ Delete the item in the database that matches the specified id in the URL """ qry = db_session.query(Store).filter( Store.id==id) store = qry.first() if store: form = StoreForm(formdata=request.form, obj=store) if request.method == 'POST' and form.validate(): # delete the item from the database db_session.delete(store) db_session.commit() flash('Store deleted successfully!') return redirect('/') return render_template('delete_store.html', form=form) else: return 'Error deleting #{id}'.format(id=id)