def add_wolfram_food_to_day(request):
    if request.is_ajax and request.method == "POST":
        data = request.POST.dict()

        lang = data['lang']
        date = string_to_date(data['date'])
        food_name = data['food_name']
        food_unit = data['food_unit']
        if food_unit == '/ 100g' or food_unit == 'x 100g':
            food_unit = "g"

        if lang == "pl":
            food_name_pl = upper_first_letter(food_name)
            food_name = upper_first_letter(
                translate_polish_to_english(food_name))
        else:
            food_name_pl = upper_first_letter(
                translate_english_to_polish(food_name))
            food_name = upper_first_letter(food_name)

        new_food = get_food_data_from_wolfram(food_name, food_unit)
        new_food.name_pl = food_name_pl
        manager.save_food(new_food)

        manager.add_food_to_day(manager.get_day(date), new_food,
                                float(data['food_count']))
        return JsonResponse({}, status=200)
def add_manual_food_to_day(request):
    if request.is_ajax and request.method == "POST":
        data = request.POST.dict()

        lang = data['lang']
        date = string_to_date(data['date'])
        food_name = data['food_name']

        if lang == "pl":
            food_name_pl = upper_first_letter(food_name)
            food_name = upper_first_letter(
                translate_polish_to_english(food_name))
        else:
            food_name_pl = upper_first_letter(
                translate_english_to_polish(food_name))
            food_name = upper_first_letter(food_name)

        new_food = manager.add_or_change_food(
            food_name, food_name_pl, data['food_unit'],
            float(data['food_calories']), float(data['food_fat']),
            float(data['food_carbohydrates']), float(data['food_protein']))

        manager.add_food_to_day(manager.get_day(date), new_food,
                                float(data['food_count']))

        return JsonResponse({}, status=200)
def get_food(request):
    if request.is_ajax and request.method == "POST":
        data = request.POST.dict()
        lang = data['lang']
        food_name = data['food_name']

        if lang == "pl":
            food_name = translate_polish_to_english(food_name)

        json_string = json.dumps(
            ResponseFood(manager.get_food(food_name), 0).__dict__)
        return JsonResponse({"food": json_string}, status=200)
def add_food_to_day(request):
    if request.is_ajax and request.method == "POST":
        data = request.POST.dict()
        lang = data['lang']
        food_name = data['food_name']
        count = float(data['count'])
        date = string_to_date(data['date'])

        if lang == "pl":
            food_name = translate_polish_to_english(food_name)

        food_name = upper_first_letter(food_name)
        manager.add_food_to_day(manager.get_day(date),
                                manager.get_food(food_name), count)

        return JsonResponse({}, status=200)
 def test_translate_polish_to_english(self):
     self.assertEqual('egg', translate_polish_to_english('jajko'))
     self.assertEqual('wood', translate_polish_to_english('drewno'))