Beispiel #1
0
def log_meal(request, meal_pk):
    """
    Copy the requested meal item and logs its nutritional values
    """

    # Check read permission
    meal = get_object_or_404(Meal, pk=meal_pk)
    user = meal.plan.user
    is_owner = request.user == user
    date = datetime.date.today()

    if not is_owner and not user.userprofile.ro_access:
        return HttpResponseForbidden()

    for item in meal.mealitem_set.select_related():
        log_item = LogItem(plan=item.meal.plan,
                           ingredient=item.ingredient,
                           weight_unit=item.weight_unit,
                           amount=item.amount)
        log_item.save()

    return HttpResponseRedirect(reverse('nutrition:log:detail',
                                        kwargs={'pk': meal.plan.pk,
                                                'year': date.year,
                                                'month': date.month,
                                                'day': date.day
                                                }))
Beispiel #2
0
def _logMealPlan(meals):
    """
    Helper method to log a collection of meals
    """

    for meal in meals:
        for item in meal.mealitem_set.select_related():
            log_item = LogItem(plan=item.meal.plan,
                               ingredient=item.ingredient,
                               weight_unit=item.weight_unit,
                               amount=item.amount)
            log_item.save()