def recipe_list(): """ It searches all the Recipes: Returns: list of recipes (list of objects) list of cuisine (list of strings) list of sources (list of strings) list of categories (list of strings) list of levels (list of strings) """ # If user is logged in, search user's recipes. if 'User' in session: recipes = Recipe.getRecipesByUser(session['User']) cuisine = Recipe.getCuisineForRecipesByUser(session['User']) sources = Recipe.getSourceForRecipesByUser(session['User']) categories = Recipe.getCatForRecipesByUser(session['User']) levels = Recipe.getLevelsForRecipesByUser(session['User']) # If user is not logged in, return all recipes else: recipes = Recipe.getAllRecipes() cuisine = Recipe.getCuisineForRecipesByUser() sources = Recipe.getSourceForRecipesByUser() categories = Recipe.getCatForRecipesByUser() levels = Recipe.getLevelsForRecipesByUser() return render_template("recipe_list.html", recipes=recipes, levels=levels, cuisine=cuisine, sources=sources, categories=categories)
def getPlanner(date=None, num=None): """ Gets the list of meals planned """ start_date = '' # It sets the START DATE. if date and num =='-': start_date = datetime.strptime(date,'%Y-%m-%d %H:%M:%S.%f') - timedelta(days=7) elif date and num == '+': start_date = datetime.strptime(date,'%Y-%m-%d %H:%M:%S.%f') + timedelta(days=7) if not start_date: start_date = datetime.today() # It sets the END DATE end_date = start_date + timedelta(days=6) currentWeek = start_date.strftime("%W") week_days = [] meal_list = [] meal_days = [] if 'User' in session: recipes = Recipe.getRecipesByUser(session['User']) cuisine = Recipe.getCuisineForRecipesByUser(session['User']) categories = Recipe.getCatForRecipesByUser(session['User']) for i in range(7): week_days.append(int(start_date.strftime("%w")) + i) for i in range(7): mealsPlanned='' date = start_date + timedelta(days=i) # mealsPlanned = Meals.getMealsByDate(date, session['User']) b_meals = Meals.getMealsByDateByType(date, session['User'], 'breakfast') l_meals = Meals.getMealsByDateByType(date, session['User'], 'lunch') d_meals = Meals.getMealsByDateByType(date, session['User'], 'dinner') s_meals = Meals.getMealsByDateByType(date, session['User'], 'snack') # print "BREAKFAST",b_meals meal_list.append({"date": date, "b_meals":b_meals, "l_meals":l_meals, "d_meals":d_meals, "s_meals":s_meals}) print 'DATA', date return render_template("planner.html", meals_list=meal_list, week_days=week_days, start_date=start_date, end_date=end_date, recipes=recipes, cuisine=cuisine, categories=categories) else: flash("You need to sign in") return render_template("error.html",url="/planner")