Self hosted FLOSS fitness/workout, nutrition and weight tracker
Correctly retrieve the latest weight entry, fix JSON bug
Roland Geider3956f010d677
diff --git a/wger/nutrition/views/bmi.py b/wger/nutrition/views/bmi.pyindex 2e0ef7932..2a4c77036 100644--- a/wger/nutrition/views/bmi.py+++ b/wger/nutrition/views/bmi.py@@ -27,7 +27,7 @@ from django.utils.translation import ugettext as _from wger.nutrition.forms import BmiFormfrom wger.weight.models import WeightEntry-+from wger.utils import helperslogger = logging.getLogger('wger.custom')@@ -63,7 +63,7 @@ def calculate(request):# Create a new weight entry as neededif (not WeightEntry.objects.all().exists()- or (datetime.date.today() - WeightEntry.objects.all().latest().creation_date+ or (datetime.date.today() - WeightEntry.objects.filter(user=request.user).latest().creation_date> datetime.timedelta(1))):entry = WeightEntry()entry.weight = form.cleaned_data['weight']@@ -73,7 +73,7 @@ def calculate(request):# Update the last entryelse:- entry = WeightEntry.objects.all().latest()+ entry = WeightEntry.objects.filter(user=request.user).latest()entry.weight = form.cleaned_data['weight']entry.save()@@ -81,7 +81,7 @@ def calculate(request):result = {'bmi': '{0:.2f}'.format(bmi),'weight': form.cleaned_data['weight'],'height': request.user.userprofile.height}- data = json.dumps(result)+ data = json.dumps(result, cls=helpers.DecimalJsonEncoder)# Return the results to the clientreturn HttpResponse(data, 'application/json')