Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Show additional user data on overview page

Roland Geider342bbfc9ae56
diff --git a/wger/core/templates/user/overview.html b/wger/core/templates/user/overview.html
index 4b49ce15a..0c788e022 100644
--- a/wger/core/templates/user/overview.html
+++ b/wger/core/templates/user/overview.html
@@ -10,22 +10,30 @@
{% url 'core:trainer-login' current_user.pk as trainer_login %}
-<h3>{% trans "Workouts" %} ({% trans "last 10" %})</h3>
+<h3>{% trans "Workouts" %} <small>({% trans "last 10" %})</small></h3>
<table class="table">
<thead>
<tr>
- <th>{% trans "Name" %}</th>
- <th>{% trans "Date" %}</th>
+ <th style="width: 20%;">{% trans "Date" %}</th>
+ <th>{% trans "Description" %}</th>
+ <th>{% trans "Number of logs (days)" %}</th>
+ <th>{% trans "Last log" %}</th>
</tr>
</thead>
<tbody>
-{% for workout in current_user.workout_set.all|slice:":10" %}
+{% for workout in workouts %}
<tr>
<td>
- <a href="{{trainer_login}}?next={% url 'workout-view' workout.pk %}">{{workout}}</a>
+ {{workout.workout.creation_date}}
</td>
<td>
- {{workout.creation_date}}
+ <a href="{{trainer_login}}?next={% url 'workout-view' workout.workout.pk %}">{{workout.workout}}</a>
+ </td>
+ <td>
+ {{workout.logs|default:'-/-'}}
+ </td>
+ <td>
+ {{workout.last_log.date|default:'-/-'}}
</td>
</tr>
{% empty %}
@@ -36,25 +44,26 @@
</tbody>
</table>
{% if perms.core.gym_trainer %}
-
<a href="{{trainer_login}}" class="btn btn-success btn-sm">{% trans "Log in as this user" %}</a>
+<a href="{{trainer_login}}?next={% url 'workout-calendar' %}" class="btn btn-default btn-sm">{% trans "Calendar" %}</a>
<a href="{{trainer_login}}?next={% url 'workout-add' %}" class="btn btn-default btn-sm">{% trans "Add workout" %}</a>
{% endif %}
-<h3>{% trans "Log" %}</h3>
+<h4>{% trans "Log" %} <small>({% trans "last 10" %})</small></h4>
<table class="table">
<thead>
<tr>
- <th>{% trans "Date" %}</th>
+ <th style="width: 20%;">{% trans "Date" %}</th>
<th>{% trans "General impression" %}</th>
+ <th>{% trans "Notes" %}</th>
<th>{% trans "Time" %}</th>
</tr>
</thead>
<tbody>
-{% for log in current_user.workoutsession_set.all|slice:":10" %}
+{% for log in session %}
<tr>
<td>
{{log.date}}
@@ -62,6 +71,9 @@
<td>
{{log.get_impression_display}}
</td>
+ <td>
+ {{log.notes|truncatewords:6|default:'-/-'}}
+ </td>
<td>
{% if log.time_start and log.time_end %}
{{log.time_start|time:"H:i"}} - {{log.time_end|time:"H:i"}}
@@ -77,6 +89,75 @@
{% endfor %}
</tbody>
</table>
+
+
+<h3>{% trans "Weight" %} <small>({% trans "last 5" %})</small></h3>
+<table class="table">
+<thead>
+<tr>
+ <th style="width: 20%;">{% trans "Date" %}</th>
+ <th>{% trans "Weight" %}</th>
+</tr>
+</thead>
+<tbody>
+{% for weight in weight_entries %}
+<tr>
+ <td>
+ {{weight.creation_date}}
+ </td>
+ <td>
+ {{weight.weight}}
+ </td>
+</tr>
+{% empty %}
+<tr>
+ <td colspan="3">{% trans "No logs found." %}</td>
+</tr>
+{% endfor %}
+</tbody>
+</table>
+{% if perms.core.gym_trainer %}
+<a href="{{trainer_login}}?next={% url 'weight-overview' %}" class="btn btn-default btn-sm">{% trans "Weight overview" %}</a>
+{% endif %}
+
+
+<h3>{% trans "Nutrition plans" %} <small>({% trans "last 5" %})</small></h3>
+<table class="table">
+<thead>
+<tr>
+ <th style="width: 20%;">{% trans "Date" %}</th>
+ <th>{% trans "Description" %}</th>
+ <th>{% trans "Energy" %}</th>
+ <th>{% trans "Protein" %}</th>
+ <th>{% trans "Carbohydrates" %}</th>
+ <th>{% trans "Fat" %}</th>
+</tr>
+</thead>
+<tbody>
+{% for nutrition_plan in nutrition_plans %}
+<tr>
+ <td>
+ {{nutrition_plan.creation_date}}
+ </td>
+ <td>
+ <a href="{{trainer_login}}?next={% url 'nutrition-view' nutrition_plan.id %}">{{nutrition_plan.description}}</a>
+ </td>
+ <td>
+ {{nutrition_plan.get_nutritional_values.total.energy|floatformat}}kcal
+ </td>
+ <td>
+ {{nutrition_plan.get_nutritional_values.total.protein|floatformat}}g
+ </td>
+ <td>
+ {{nutrition_plan.get_nutritional_values.total.carbohydrates|floatformat}}g
+ </td>
+ <td>
+ {{nutrition_plan.get_nutritional_values.total.fat|floatformat}}g
+ </td>
+</tr>
+{% endfor %}
+</tbody>
+</table>
{% endblock %}
diff --git a/wger/core/views/user.py b/wger/core/views/user.py
index 441faa50c..18937492c 100644
--- a/wger/core/views/user.py
+++ b/wger/core/views/user.py
@@ -17,7 +17,8 @@
import logging
from django.shortcuts import render, get_object_or_404
-from django.http import HttpResponseRedirect, HttpResponseForbidden
+from django.http import HttpResponseRedirect
+from django.http import HttpResponseForbidden
from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _, ugettext_lazy
@@ -32,7 +33,6 @@ from django.contrib import messages
from django.views.generic import RedirectView, UpdateView, DetailView
from rest_framework.authtoken.models import Token
-from wger.core.models import Language
from wger.utils.constants import USER_TAB
from wger.utils.generic_views import WgerPermissionMixin
from wger.utils.generic_views import WgerFormMixin
@@ -42,7 +42,13 @@ from wger.core.forms import UserPreferencesForm, UserPersonalInformationForm
from wger.core.forms import PasswordConfirmationForm
from wger.core.forms import RegistrationForm
from wger.core.forms import RegistrationFormNoCaptcha
+from wger.core.models import Language
+from wger.manager.models import WorkoutLog
+from wger.manager.models import WorkoutSession
+from wger.manager.models import Workout
+from wger.nutrition.models import NutritionPlan
from wger.config.models import GymConfig
+from wger.weight.models import WeightEntry
logger = logging.getLogger('wger.custom')
@@ -400,3 +406,23 @@ class UserDetailView(WgerPermissionMixin, DetailView):
return super(UserDetailView, self).dispatch(request, *args, **kwargs)
else:
return HttpResponseForbidden()
+
+ def get_context_data(self, **kwargs):
+ '''
+ Send some additional data to the template
+ '''
+ context = super(UserDetailView, self).get_context_data(**kwargs)
+ out = []
+ workouts = Workout.objects.filter(user=self.object).all()
+ for workout in workouts:
+ logs = WorkoutLog.objects.filter(workout=workout)
+ out.append({'workout': workout,
+ 'logs': logs.dates('date', 'day').count(),
+ 'last_log': logs.last()})
+ context['workouts'] = out
+ context['weight_entries'] = WeightEntry.objects.filter(user=self.object)\
+ .order_by('-creation_date')[:5]
+ context['nutrition_plans'] = NutritionPlan.objects.filter(user=self.object)\
+ .order_by('-creation_date')[:5]
+ context['session'] = WorkoutSession.objects.filter(user=self.object).order_by('-date')[:10]
+ return context