Skip to content

armgit / wger

Public Imported from GitHub
0

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.html
index 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.py
index c740db19c..e8fbcb3e7 100644
--- a/manager/views.py
+++ b/manager/views.py
@@ -23,6 +23,7 @@ from django.http import HttpResponseForbidden
from django.forms import ModelForm
from django.forms.models import modelformset_factory
from django.core.context_processors import csrf
+from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth.decorators import login_required
from 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 = False
template_data['weight'] = weight
@@ -741,3 +745,4 @@ def delete_setting(request, id, set_id, exercise_id):
settings.delete()
return HttpResponseRedirect('/workout/%s/view/' % id)
+