def add_recipe(): '''If request method is GET, load the 'add recipe' page. If request method is POST: 1. Get all posted form data 2. Get ID of currently logged-in user 3. Call the relevant function of the Recipes class to add/create a new record in the recipes table. Pass in the relevant information as arguments to the function. 4. Redirect to the Recipes (listing) page.''' if request.method == 'GET': return render_template('add_recipe.html') elif request.method == 'POST': title = request.form.get('recipe-title') image = request.form.get('recipe-image') category = request.form.get('recipe-category') description = request.form.get('recipe-description') ingredients = request.form.get('recipe-ingredients') auth = Auth() user = auth.get_current_user() user_id = user[0] new_recipe = { 'title': title, 'image_URL': image, 'category': category, 'description': description, 'ingredients': ingredients, } recipe = Recipes() recipe.add_recipe(new_recipe, user_id) return redirect(url_for('show_recipes'))
def add_recipe(): if request.method == 'GET': return render_template('add_recipe.html') title = request.form.get('title', None) description = request.form.get('description') image = request.form.get('image', None) ingredients = request.form.get('ingredients', None) user_id = Auth().get_current_user()['user_id'] recipe_manager = Recipes() recipe_manager.add_recipe( { 'title': title, 'description': description, 'image': image, 'ingredients': ingredients }, user_id) return redirect(url_for('show_recipes'))
def add_recipe(): '''If request method is GET, load the 'add recipe' page. If request method is POST: 1. Get all posted form data 2. Get ID of currently logged-in user 3. Call the relevant function of the Recipes class to add/create a new record in the recipes table. Pass in the relevant information as arguments to the function. 4. Redirect to the Recipes (listing) page.''' if request.method == "GET": return render_template('add_recipe.html') if request.method == "POST": recipe = Recipes() auth = Auth() description = request.form.get('description', None) ingredients = request.form.get('ingredients', None) user_id = auth.get_current_user()[0] recipe.add_recipe(description, ingredients, user_id) return redirect(url_for('show_recipes'))