Exemplo n.º 1
0
def plan():

    """ Add a recipe to Meals """

    date = request.args.get("date")
    meal_type = request.args.get("type")
    servings = request.args.get("servings")
    recipe_id = request.args.get("recipeid")

    # import pdb;
    if 'User' in session:

        if not Meals.getMealByDateByRecipe(date, session['User'], recipe_id):
            
            Meals.plan_meal(recipe_id, meal_type, servings, session["User"], date)
            db.session.commit()
        
        if request.args.get('flag') == 'planner':           
            return redirect("/planner")         
        else:                 
            return redirect("/recipes")
    else:
        
        flash = []
        flash = "You need to login"
        return redirect("/error.html",url="/planner")
Exemplo n.º 2
0
def deleteMeal():
    
    recipe_fk = request.args.get("recipeid")
    meal_type = request.args.get("mealtype")
    date_planned = request.args.get("dateplanned")

    Meals.deleteMeal(date=date_planned, user=session['User'], meal_type=meal_type,
             recipe=recipe_fk)

    db.session.commit()


    return redirect("/planner")
Exemplo n.º 3
0
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")