def new_store(): form = GroceryStoreForm() if form.validate_on_submit(): add_store = GroceryStore(title=form.title.data, address=form.address.data, created_by_id=current_user.username) db.session.add(add_store) db.session.commit() flash('New store added') return redirect(url_for('main.store_detail', store_id=add_store.id)) return render_template('new_store.html', form=form)
def new_store(): form = GroceryStoreForm() if form.validate_on_submit(): print("***** trying to print success *****") new_store = GroceryStore(title=form.title.data, address=form.address.data) db.session.add(new_store) db.session.commit() flash('You have Succesfully created a new store') return redirect(url_for('main.store_detail', store_id=new_store.id)) return render_template('new_store.html', form=form)
def new_store(): '''Route for adding a new_store to the database. ''' form = GroceryStoreForm() if form.validate_on_submit(): new_store = GroceryStore(title=form.title.data, address=form.address.data, created_by=current_user, created_by_id=current_user.id) db.session.add(new_store) db.session.commit() flash("New Store Was Created!") return redirect(url_for('main.store_detail', store_id=new_store.id)) return render_template('new_store.html', form=form)
def new_store(): form = GroceryStoreForm() if form.validate_on_submit(): new_store = GroceryStore(title=form.title.data, address=form.address.data) db.session.add(new_store) db.session.commit() flash('New grocery store has been added.') return redirect(url_for('main.store_detail', store_id=new_store)) # TODO: Send the form to the template and use it to render the form fields return render_template('new_store.html', form=form)
def new_store(): form = GroceryStoreForm() if form.validate_on_submit(): new_GS = GroceryStore(title=form.title.data, address=form.address.data) db.session.add(new_GS) db.session.commit() flash('New Grocery Store was created successfully.') # - redirect the user to the store detail page. return redirect(url_for('main.store_detail', GroceryStore_id=new_GS.id)) #Send the form to the template and use it to render the form fields return render_template('new_store.html', form=form)
def new_store(): form = GroceryStoreForm() if form.validate_on_submit(): new_store = GroceryStore(title=form.title.data, address=form.address.data) db.session.add(new_store) db.session.commit() flash("New store was successfully added.") return redirect(url_for('main.store_detail', store_id=new_store.id)) return render_template('new_store.html', form=form)
def new_store(): # Creates a GroceryStoreForm form = GroceryStoreForm() # If form was submitted and was valid: if form.validate_on_submit(): new_store = GroceryStore(title=form.title.data, address=form.address.data) db.session.add(new_store) db.session.commit() flash('New store was added successfully.') return redirect(url_for('main.store_detail', store_id=new_store.id)) return render_template('new_store.html', form=form)
def store_detail(store_id): store = GroceryStore.query.get(store_id) form = GroceryStoreForm(obj=store) if form.validate_on_submit(): new_store = GroceryStore(address=form.address.data, title=form.title.data) db.session.add(new_store) db.session.commit() flash('Store details were updated successfully.') return redirect(url_for('main.store_detail', store_id=new_store.id)) #Send the form to the template and use it to render the form fields store = GroceryStore.query.get(store_id) return render_template('store_detail.html', store=store, form=form)
def new_store(): form = GroceryStoreForm() if form.validate_on_submit(): new_GroceryStore = GroceryStore(title=form.title.data, address=form.address.data, created_by=current_user) db.session.add(new_GroceryStore) db.session.commit() flash('A new Grocery Store was successfully created') return redirect( url_for('main.store_detail', store_id=new_GroceryStore.id)) return render_template('new_store.html', form=form)
def new_store(): #Creates a GroceryStoreForm form = GroceryStoreForm() if form.validate_on_submit(): new_GroceryStore = GroceryStore( title=form.title.data, address=form.address.data, ) db.session.add(new_GroceryStore) db.session.commit() flash('New GroceryStore was created successfully!') return redirect(url_for('main.store_detail')) return render_template('new_store.html', form=form)
def new_store(): # TODO: Create a GroceryStoreForm form = GroceryStoreForm() if form.validate_on_submit(): store = GroceryStore( title=form.title.data, address=form.address.data, created_by=current_user, ) db.session.add(store) db.session.commit() flash('New store was created') return redirect(url_for('main.store_detail', store_id=store.id)) return render_template('new_store.html', form=form)
def store_detail(store_id): store = GroceryStore.query.get(store_id) # Create a GroceryStoreForm and pass in `obj=store` form = GroceryStoreForm(obj=store) # If form was submitted and was valid: if form.validate_on_submit(): new_GroceryStore = GroceryStore(title=form.title.data, address=form.address.data) db.session.add(new_GroceryStore) db.session.commit() flash('New store was created successfully.') return redirect( url_for('main.store_detail', GroceryStore_id=new_GroceryStore.id)) store = GroceryStore.query.get(store_id) return render_template('store_detail.html', store=store, form=form)
def new_store(): groceryStoreForm = GroceryStoreForm() if groceryStoreForm.validate_on_submit(): # Create new ORM GroceryStore newGroceryStore = GroceryStore(title=groceryStoreForm.title.data, address=groceryStoreForm.address.data, created_by=current_user) db.session.add(newGroceryStore) db.session.commit() flash('Success') # Send to created GroceryStore page return redirect( url_for('main.store_detail', store_id=newGroceryStore.id)) # Returned on 'GET' return render_template('new_store.html', groceryStoreForm=groceryStoreForm, current_user=current_user)
def new_store(): # TODO: Create a GroceryStoreForm form = GroceryStoreForm() # TODO: If form was submitted and was valid: # - create a new GroceryStore object and save it to the database, # - flash a success message, and # - redirect the user to the store detail page. if form.validate_on_submit(): new_store = GroceryStore(title=form.title.data, address=form.address.data, created_by=current_user) db.session.add(new_store) db.session.commit() flash('Store was created successfully.') return redirect(url_for('auth.store_detail', store_id=new_store.id)) # TODO: Send the form to the template and use it to render the form fields return render_template('new_store.html', form=form)
def store_detail(store_id): store = GroceryStore.query.get(store_id) #Creates a GroceryStoreForm store = GroceryStore.query.get(store_id) form = GroceryStoreForm(obj=store) if form.validate_on_submit(): new_GroceryStore = GroceryStore( title=form.title.data, address=form.address.data, ) db.session.add(new_GroceryStore) db.sesssion.commit() flash('New GroceryStore was created') return redirect( url_for('main.store_detail', store_id=new_GroceryStore.id)) store = GroceryStore.query.get(store_id) return render_template('store_detail.html', store=store, form=form)
def new_store(): form = GroceryStoreForm() # If form was submitted and was valid: if form.validate_on_submit(): # - creates a new GroceryStore object and save it to the database, new_GroceryStore = GroceryStore( title=form.title.data, address=form.address.data, created_by=current_user ) db.session.add(new_GroceryStore) db.session.commit() # - flashes a success message flash('You have created a Grocery Store successfully') # - redirects the user to the store detail page. return redirect(url_for('main.store_detail', store_id=new_GroceryStore.id)) # Sends the form to the template and use it to render the form fields return render_template('new_store.html', form=form)
def store_detail(store_id): store = GroceryStore.query.get(store_id) # Creates a GroceryStoreForm and pass in `obj=store` form = GroceryStoreForm(obj=store) # If form was submitted and was valid: # - update the GroceryStore object and save it to the database, # - flash a success message, and # - redirect the user to the store detail page. if form.validate_on_submit(): new_store = GroceryStore(title=form.data.title, address=form.address.data) db.session.add(new_store) db.committ() flash("New store was added") return redirect( url_for('main.store_detail', store_id=store.id, store=store)) return render_template('store_detail.html', store=store)
def store_detail(store_id): store = GroceryStore.query.get(store_id) # TODO: Create a GroceryStoreForm and pass in `obj=store` form = GroceryStoreForm(obj=store) # TODO: If form was submitted and was valid: # - update the GroceryStore object and save it to the database, # - flash a success message, and # - redirect the user to the store detail page. if form.validate_on_submit(): update_store = GroceryStore(title=form.title.data, address=form.address.data) db.session.add(update_store) db.session.commit() flash('Store was updated successfully.') return redirect(url_for('auth.store_detail', store_id=update_store.id)) # TODO: Send the form to the template and use it to render the form fields store = GroceryStore.query.get(store_id) return render_template('store_detail.html', store_id=store_id, form=form, store=store)