def delete_like(): if 'logged_in' in session.keys() and session['logged_in'] == True: recipe_id = request.args.get('id') user_id = functions.get_id_of_username(session['username']) if functions.recipe_exists(recipe_id): functions.delete_like(user_id, recipe_id) flash("Opinion obliterated!") else: flash("Recipe not found or user did not like this recipe") else: flash("Not logged in!") return redirect(url_for('recipes') + "?id=%s" % (recipe_id))
def process_dislike(): if 'logged_in' in session.keys() and session['logged_in'] == True: recipe_id = request.args.get('id') user_id = functions.get_id_of_username(session['username']) if (functions.recipe_exists(recipe_id)) and ( not functions.dislike_exists(user_id, recipe_id)): functions.insert_dislike(user_id, recipe_id) flash("Disliked!") else: flash("Recipe not found or user already disliked this recipe") else: flash("Not logged in!") return redirect(url_for('recipes') + "?id=%s" % (recipe_id))
def delete_recipe(): if 'logged_in' in session.keys() and session['logged_in'] == True: recipe_id = request.args.get('id') if (functions.get_username(recipe_id) == session['username']): if functions.recipe_exists(recipe_id): functions.delete_recipe(recipe_id) flash("Recipe deleted!") else: flash("Recipe not found!") else: flash("Username does not match!") else: flash("Not logged in!") return redirect(url_for('recipe_list'))
def recipes(): id = request.args.get('id') if functions.recipe_exists(id): score = functions.get_score(id) recipe = functions.get_recipe_by_id(id) creator = functions.get_username(id) category = functions.get_category(id) ingredients = functions.get_ingredients(id) instructions = functions.get_instructions(id) comments = functions.get_comments(id) user_logged_in = False current_user_is_creator = False likeexists = False dislikeexists = False if 'logged_in' in session.keys() and session['logged_in'] == True: user_logged_in = True current_user_is_creator = (session['username'] == creator) likeexists = functions.like_exists( functions.get_id_of_username(session['username']), id) dislikeexists = functions.dislike_exists( functions.get_id_of_username(session['username']), id) return render_template('recipes.html', score=score, likeexists=likeexists, dislikeexists=dislikeexists, current_user_is_creator=current_user_is_creator, recipe=recipe, creator=creator, category=category, ingredients=ingredients, instructions=instructions, comments=comments, user_logged_in=user_logged_in) else: flash("Recipe not found.") return url_for('recipe_list')