Ejemplo n.º 1
0
def edit_food(food_id=None):
    if request.method == "POST":
        food = Food.get_food(food_id)
        if not request.form['cal'] == "":
            food.cal = float(request.form['cal'])
        if not request.form['pro'] == "":
            food.pro = float(request.form['pro'])
        if not request.form['fat'] == "":
            food.fat = float(request.form['fat'])
        if not request.form['carbs'] == "":
            food.carbs = float(request.form['carbs'])
        food.update()
        return render_template("food/edit_food.html",
                               all_food=Food.get_foods())
    elif request.method == "GET":
        try:
            return render_template("food/edit_food.html",
                                   food=Food.get_food(food_id))
        except food_exceptions.IdNotFoundException:
            if session['email'] in ADMINS:
                all_food = Food.get_foods()
            else:
                user = User.get_by_email(session['email'])
                all_food = Food.get_by_user_id(user_id=user._id)
            return render_template("food/edit_food.html", all_food=all_food)
Ejemplo n.º 2
0
 def get_food_list(list_of_food):
     full_list = []
     for each_item in list_of_food:
         food = Food.get_food(each_item._id)
         food.gram = int(each_item.gram)
         full_list.append(food)
     return full_list
Ejemplo n.º 3
0
def remove_from_list():
    food = Food.get_food(request.form['id'])
    food.gram = int(request.form['gram'])
    DietList.remove_food_from_list(request.form['list_id'], food)
    user_list = DietList.get_list(request.form['list_id'])
    if user_list.list_of_food.__len__() == 0:
        DietList.remove_list(user_list._id)
        user = User.get_by_email(session['email'])
        return render_template("list/my_lists.html", user_lists=DietList.get_user_lists(user._id))
    return render_template("list/edit_list.html", user_list=user_list, list_of_food=user_list.list_of_food)
Ejemplo n.º 4
0
 def list_food():
     all_food = Food.get_foods()
     for each_food in all_food:
         print("Name: {}, Cal: {}, Pro: {}, Fat: {}, Carb: {}, Id: {}.".
               format(each_food.name, each_food.cal, each_food.pro, each_food.fat
                      , each_food.carbs, each_food._id))
     id = input("Input id of the item: ")
     gram = input("Input gram amount: ")
     food = Food.get_food(id)
     food.gram = gram
     return food
Ejemplo n.º 5
0
def add_to_my_list(list_id=None):
    if request.method == "POST":
        try:
            food = Food.get_food(request.form["id"])
            food.gram = int(request.form["gram"])
            DietList.add_to_list(list_id=list_id,
                                 food=food)
            user = User.get_by_email(session['email'])
        except food_exceptions.InvalidFoodAmount:
            return render_template("list/add_to_list.html", user_list=DietList.get_list(list_id),
                                   all_food=Food.get_foods(), ex="הכנס כמות אל התיבה.")
        return render_template("list/my_lists.html", user_lists=DietList.get_user_lists(user._id))
    return render_template("list/add_to_list.html", user_list=DietList.get_list(list_id),
                           all_food=Food.get_foods())
Ejemplo n.º 6
0
def select_food(food_id):
    try:
        current_food = Food.get_food(food_id)
    except food_exceptions.IdNotFoundException:
        return render_template("user/profile.html",
                               email=session['email'],
                               current_food=None,
                               all_food=Food.get_foods(),
                               ex="לא נמצא.",
                               result=list_blueprint.result)
    return render_template("user/profile.html",
                           email=session['email'],
                           current_food=current_food,
                           all_food=user_blueprint.user_food,
                           current_list=list_blueprint.current_list,
                           result=list_blueprint.result)
Ejemplo n.º 7
0
    def render_list(cls, data):
        list = cls(**data)
        list_of_food = []
        # fixing list from dict array to obj array
        for each_food in list.list_of_food:
            food = Food.get_food(each_food['_id'])
            food.gram = each_food['gram']
            list_of_food.append(food)
        list.list_of_food = list_of_food

        # fixing result from dict to obj
        result = Result(cal=list.result['cal'],
                        pro=list.result['pro'],
                        fat=list.result['fat'],
                        carbs=list.result['carbs'])
        list.result = result
        return list