Self hosted FLOSS fitness/workout, nutrition and weight tracker
Don't break the index if the user has no weight entries
Roland Geider06c86cf9683c
diff --git a/manager/templates/index.html b/manager/templates/index.htmlindex d9de1f3e3..7285ddd03 100644--- a/manager/templates/index.html+++ b/manager/templates/index.html@@ -59,11 +59,11 @@{% trans "No nutrition plans." %} {% trans "Use link to add one." %}</div>{% endif %}-+ {% if weight %}<p>{% trans "Your current weight is: "%} <strong>{{weight.weight}} kg.</strong></p>-+ {% endif %}</div></div></div>diff --git a/manager/views.py b/manager/views.pyindex c740db19c..e8fbcb3e7 100644--- a/manager/views.py+++ b/manager/views.py@@ -23,6 +23,7 @@ from django.http import HttpResponseForbiddenfrom django.forms import ModelFormfrom django.forms.models import modelformset_factoryfrom django.core.context_processors import csrf+from django.core.exceptions import ObjectDoesNotExistfrom django.contrib.auth.decorators import login_requiredfrom django.utils.translation import ugettext as _@@ -66,7 +67,10 @@ def index(request):plans = NutritionPlan.objects.filter(user = request.user)template_data['plans'] = plans- weight = WeightEntry.objects.filter(user = request.user).latest('creation_date')+ try:+ weight = WeightEntry.objects.filter(user = request.user).latest('creation_date')+ except ObjectDoesNotExist:+ weight = Falsetemplate_data['weight'] = weight@@ -741,3 +745,4 @@ def delete_setting(request, id, set_id, exercise_id):settings.delete()return HttpResponseRedirect('/workout/%s/view/' % id)+