Self hosted FLOSS fitness/workout, nutrition and weight tracker
Do the data processing for the weekdays on the python side, not on the template
Roland Geider8490d51a2b20
diff --git a/manager/templates/index.html b/manager/templates/index.htmlindex 61c56be7a..529b8b141 100644--- a/manager/templates/index.html+++ b/manager/templates/index.html@@ -25,15 +25,13 @@<ul>- {% for i, j in weekdays %}+ {% for day, exercise, is_workout in weekdays %}<li>- {{ j }}:+ {{ day }}:+ {% if not is_workout %}<span class="dimmed">{% endif%}+ {{ exercise }}+ {% if not is_workout %}</span>{% endif%}- {% for day in current_workout.day_set.select_related %}- {% if day.day == i %}- {{ day.description }}- {% endif %}- {% endfor %}</li>{% endfor %}</ul>diff --git a/manager/views.py b/manager/views.pyindex 39f2a72d1..802eea3a3 100644--- a/manager/views.py+++ b/manager/views.py@@ -13,6 +13,7 @@# You should have received a copy of the GNU Affero General Public Licenseimport loggingimport uuid+import datetimefrom django.template import RequestContextfrom django.shortcuts import render_to_response@@ -66,8 +67,6 @@ def index(request):template_data = {}template_data['active_tab'] = 'user'-- template_data['weekdays'] = DAYS_OF_WEEK_CHOICEScurrent_workout = TrainingSchedule.objects.filter(user=request.user).latest('creation_date')template_data['current_workout'] = current_workout@@ -75,6 +74,23 @@ def index(request):plan = NutritionPlan.objects.filter(user = request.user).latest('creation_date')template_data['plan'] = plan+ # Format a bit the days so it doesn't have to be done in the template+ week_day_result = []+ for i, j in DAYS_OF_WEEK_CHOICES:+ day_has_workout = False+ for day in current_workout.day_set.select_related():+ if day.day == i:+ day_has_workout = True+ week_day_result.append((_(j), day.description, True))+ break++ if not day_has_workout:+ week_day_result.append((_(j), _('Rest day'), False))++ template_data['weekdays'] = week_day_result+++ # Load the nutritional infotemplate_data['nutritional_info'] = plan.get_nutritional_values()