Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Filter the settings by set with a custom filter

Roland Geiderd92c390fcd30
diff --git a/manager/templates/workout/view.html b/manager/templates/workout/view.html
index 12987337f..b1137c8d2 100644
--- a/manager/templates/workout/view.html
+++ b/manager/templates/workout/view.html
@@ -1,5 +1,6 @@
{% extends "base.html" %}
{% load i18n %}
+{% load manager_extras %}
{% block title %}{% trans "Workout for" %} {{ workout.creation_date }}{% endblock %}
@@ -11,7 +12,7 @@
<table>
<thead>
<tr>
- <th>{{ day.description }} <!--(Day-ID: {{ day.id }})--></th>
+ <th>{{ day.description }}<!--(Day-ID: {{ day.id }})--></th>
<th style="text-align:right">
<a href="/workout/{{ workout.id}}/delete/day/{{ day.id }}"
title="{% trans "Delete" %}">[x]</a>
@@ -44,18 +45,16 @@
-->
{{ set.sets }} x <!--(Set-ID: {{ set.id }})-->
- {% for setting in exercise.setting_set.all %}
- {% comment %}
- TODO: solution with 'if' is ugly and bad!
- {% endcomment %}
-
- {% if setting.sets_id == set.id %}
- {% for individual_setting in setting.individual_exercises.select_related %}
- {{individual_setting.reps}}
- <!--(IndividualSetting-ID: {{ individual_setting.id }})-->
- <!--@ {{individual_setting.weight}}-->
- {% endfor %}
- {% endif %}
+
+ {% comment %}
+ get_current_settings only does a exercise.setting_set.filter(sets_id=set_id) ugly and bad!
+ {% endcomment %}
+ {% for setting in exercise|get_current_settings:set.id %}
+ {% for individual_setting in setting.individual_exercises.select_related %}
+ {{individual_setting.reps}}
+ <!--(IndividualSetting-ID: {{ individual_setting.id }})-->
+ <!--@ {{individual_setting.weight}}-->
+ {% endfor %}
{% empty %}
<div class="box warning">
{% trans "No settings for this exercise." %} {% trans "Use link to add one." %}
diff --git a/manager/templatetags/__init__.py b/manager/templatetags/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/manager/templatetags/manager_extras.py b/manager/templatetags/manager_extras.py
new file mode 100644
index 000000000..177f79d45
--- /dev/null
+++ b/manager/templatetags/manager_extras.py
@@ -0,0 +1,12 @@
+from django import template
+
+register = template.Library()
+
[email protected](name='get_current_settings')
+def get_current_settings(exercise, set_id):
+ """Does a filter on the sets
+
+ We need to do this here because it's not possible to pass arguments to function in the template,
+ and we are only interested on the settings that belong to the current set
+ """
+ return exercise.setting_set.filter(sets_id=set_id)
\ No newline at end of file
diff --git a/manager/views.py b/manager/views.py
index 0f892677f..d0d7051a9 100644
--- a/manager/views.py
+++ b/manager/views.py
@@ -63,8 +63,13 @@ class WorkoutForm(ModelForm):
def view_workout(request, id):
"""Show the workout with the given ID
"""
- p = get_object_or_404(TrainingSchedule, pk=id)
- return render_to_response('workout/view.html', {'workout': p})
+ template_data = {}
+
+ workout = get_object_or_404(TrainingSchedule, pk=id)
+ template_data['workout'] = workout
+
+ #days = workout.day_set.all()
+ return render_to_response('workout/view.html', template_data)
def add(request):
"""Add a new workout and redirect to its page