def deleteRestaurant(restaurant_id): session = DBSession() form = RestaurantForm() restaurantToDelete = session.query(Restaurant).filter_by(id=restaurant_id).one() if form.validate_on_submit(): session.delete(restaurantToDelete) session.commit() session.close() flash("Restaurant Deleted Successfully!!! ") return redirect(url_for('showRestaurants', restaurant_id=restaurant_id)) return render_template('restaurant/deleterestaurant.html', item = restaurantToDelete, form=form)
def createRestaurant(): session = DBSession() form = RestaurantForm() if form.validate_on_submit(): name = form.name.data location = form.location.data description = form.description.data restaurant = models.Restaurant(name=name, location =location, description = description) session.add(restaurant) session.commit() session.close() flash("Added '{}'".format(name)) return redirect(url_for('showRestaurants')) return render_template('restaurant/createrestaurant.html', form=form)
def editRestaurant(restaurant_id): session = DBSession() form = RestaurantForm() editedrestaurant = session.query(Restaurant).filter_by(id=restaurant_id).one() if form.validate_on_submit(): if request.form['name']: editedrestaurant.name = form.name.data if request.form['location']: editedrestaurant.location = form.location.data if request.form['description']: editedrestaurant.description = form.description.data session.add(editedrestaurant) session.commit() session.close() flash("Restaurant Edited Successfully!!! ") return redirect(url_for('showRestaurants', restaurant_id=restaurant_id)) return render_template('restaurant/editrestaurant.html', restaurant_id=restaurant_id, item=editedrestaurant, form=form)