Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Make order of exercises everywhere the same (view, weight log, etc.)

Roland Geider3574acbf3cd0
diff --git a/wger/manager/templates/day/log.html b/wger/manager/templates/day/log.html
index 498b8e4b7..257c42dfb 100644
--- a/wger/manager/templates/day/log.html
+++ b/wger/manager/templates/day/log.html
@@ -25,7 +25,7 @@ $(document).ready(function () {
<td>
{% trans dateform.date.label %}
</td>
- <td >
+ <td>
<div class= "ym-fbox-text {% if dateform.date.errors %}ym-error{% endif %}">
{{dateform.date}}
</div>
@@ -39,44 +39,45 @@ $(document).ready(function () {
<h3>{% trans "Exercises" %}</h3>
<table class="workout-log-table">
-{% for key, value in exercises.items %}
-<tr>
- <td style="max-width: 5em; padding-right:0.4em;">
- {{value.obj.name}}
- </td>
-
- {% for form in value.forms %}
- <td class="narrow-input">
- <div class= "ym-fbox-text narrow-input {% if form.reps.errors %}ym-error{% endif %}">
- {{form.reps}}
- </div>
- <div class="ym-fbox-text narrow-input {% if form.reps.errors %}ym-error{% endif %}">
- <span class="ym-message">{% trans "Reps" %}</span>
- </div>
- </td>
- <td>
- <div class= "ym-fbox-text narrow-input {% if form.weight.errors %}ym-error{% endif %}">
- {{form.weight}}
- </div>
-
- <div class="ym-fbox-text narrow-input {% if form.weight.errors %}ym-error{% endif %}" >
- <span class="ym-message">kg.</span>
- </div>
- </td>
- {% endfor %}
-</tr>
+{% for set in day.set_set.select_related %}
+{% for exercise in set.exercises.select_related %}
+ {% with value=exercises|get_item:exercise.id %}
+ <tr>
+ <td style="max-width: 5em; padding-right:0.4em;">
+ {{value.obj.name}}
+ </td>
+
+ {% for form in value.forms %}
+ <td class="narrow-input">
+ <div class= "ym-fbox-text narrow-input {% if form.reps.errors %}ym-error{% endif %}">
+ {{form.reps}}
+ </div>
+
+ <div class="ym-fbox-text narrow-input {% if form.reps.errors %}ym-error{% endif %}">
+ <span class="ym-message">{% trans "Reps" %}</span>
+ </div>
+ </td>
+ <td>
+ <div class= "ym-fbox-text narrow-input {% if form.weight.errors %}ym-error{% endif %}">
+ {{form.weight}}
+ </div>
+
+ <div class="ym-fbox-text narrow-input {% if form.weight.errors %}ym-error{% endif %}" >
+ <span class="ym-message">kg.</span>
+ </div>
+ </td>
+ {% endfor %}
+ </tr>
+ {% endwith %}
+{% endfor %}
{% empty %}
<tr>
<td>
- <p>
- {% trans "Add exercises to this training day before adding a log." %}
-
- <a href="{% url 'workout-view' day.training.id %}">
- {% trans "Back to workout" %}
- </a>
+ {% trans "Add exercises to this training day before adding a log." %}
- </p>
+ <br>
+ <a href="{% url 'workout-view' day.training.id %}">{% trans "Back to workout" %}</a>
</td>
</tr>
{% endfor %}
diff --git a/wger/manager/templates/mobile/workout/log.html b/wger/manager/templates/mobile/workout/log.html
index a8d86867f..1634d48df 100644
--- a/wger/manager/templates/mobile/workout/log.html
+++ b/wger/manager/templates/mobile/workout/log.html
@@ -7,12 +7,12 @@
{% block title %}{% trans "Weight log for workout" %}{% endblock %}
-{% block header %}
-<script src="{% static 'js/exercises.js' %}"></script>
-{% endblock %}
+{% block header %}{% endblock %}
{% block scripts %}
+<script src="{% static 'js/exercises.js' %}"></script>
+
<script type="text/javascript">
$(document).on('pageinit', function(){
// Init the data toggle for the weight log tables
@@ -25,11 +25,12 @@ $(document).on('pageinit', function(){
{% block content %}
{% if workout.comment %}
<p>
- <span class="dimmed">{{workout.comment}}</span>
+ <strong>{% trans "Goal" %}:</strong> {{workout.comment}}
</p>
{% endif %}
-{% for day, exercise_log in workout_log.items %}
+
+{% for day in workout.day_set.select_related|dictsort:"get_first_day_id" %}
<ul data-role="listview"
@@ -43,37 +44,27 @@ $(document).on('pageinit', function(){
</li>
</ul>
-<!--
-<p>
-<a href="{% url 'day-log' day.id %}"
- title="{% trans 'Add weight log to this day' %}"
- data-role="button">
- <img src="{% static 'images/icons/statistics.svg' %}"
- width="32"
- height="32"
- alt="{% trans 'Add weight log to this day' %}">
- {% trans 'Add weight log to this day' %}
-</a>
-</p>
--->
+ {% for set in day.set_set.select_related %}
+ {% for exercise in set.exercises.select_related %}
+ {% with day_list=workout_log|get_item:day.id %}
+ {% with exercise_list=day_list|get_item:exercise.id %}
- {% for exercise, date_list in exercise_log.items %}
- <ul data-role="listview"
- style="margin-top: 3em;">
- <li>
- <a href="{{ exercise.get_absolute_url }}">{{ exercise.name }}</a>
- </li>
- </ul>
+ <ul data-role="listview"
+ style="margin-top: 3em;">
+ <li>
+ <a href="{{ exercise.get_absolute_url }}">{{ exercise.name }}</a>
+ </li>
+ </ul>
- {% if date_list.log_by_date %}
- {% with list=date_list.log_by_date %}
- {% render_weight_log list date_list.div_uuid %}
+ {% if exercise_list.log_by_date %}
+ {% with list=exercise_list.log_by_date %}
+ {% render_weight_log list exercise_list.div_uuid %}
<script>
$(document).ready(function() {
- weight_log_chart({{date_list.chart_data|safe}},
- "{{date_list.div_uuid}}",
+ weight_log_chart({{exercise_list.chart_data|safe}},
+ "{{exercise_list.div_uuid}}",
"{{reps}}",
$('#content').width() * 0.95)
});
@@ -83,11 +74,15 @@ $(document).on('pageinit', function(){
<p><em>{% trans "No weight entries here." %}</em></p>
{% endif %}
+ {% endwith %}
+ {% endwith %}
+
{% empty%}
<p>
<em>{% trans "No exercises for this day." %}</em>
</p>
{% endfor %}
+ {% endfor %}
{% endfor %}
diff --git a/wger/manager/templates/mobile/workout/view.html b/wger/manager/templates/mobile/workout/view.html
index 87fce63d1..f890fbbf3 100644
--- a/wger/manager/templates/mobile/workout/view.html
+++ b/wger/manager/templates/mobile/workout/view.html
@@ -10,9 +10,9 @@
{% block scripts %}
+<script src="{% static 'js/exercises.js' %}"></script>
<script>
$( document ).off("pageinit").on("pageinit", function() {
- console.log('Pageinit workout view');
/*
* Show/Hide the comments to the exercises
*/
diff --git a/wger/manager/templates/workout/log.html b/wger/manager/templates/workout/log.html
index c1fb366ca..1a7884d1c 100644
--- a/wger/manager/templates/workout/log.html
+++ b/wger/manager/templates/workout/log.html
@@ -26,47 +26,55 @@ function custom_modal_init()
</p>
{% endif %}
-{% for day, exercise_log in workout_log.items %}
-<h3>{{ day.description }}</h3>
-<p>
-<a href="{% url 'day-log' day.id %}"
- title="{% trans 'Add weight log to this day' %}">
- <img src="{% static 'images/icons/statistics.svg' %}"
- width="32"
- height="32"
- alt="{% trans 'Add weight log to this day' %}">
- {% trans 'Add weight log to this day' %}
-</a>
-</p>
+{% for day in workout.day_set.select_related|dictsort:"get_first_day_id" %}
+ <h3>{{ day.description }}</h3>
+
+ <p>
+ <a href="{% url 'day-log' day.id %}"
+ title="{% trans 'Add weight log to this day' %}">
+ <img src="{% static 'images/icons/statistics.svg' %}"
+ width="32"
+ height="32"
+ alt="{% trans 'Add weight log to this day' %}">
+ {% trans 'Add weight log to this day' %}
+ </a>
+ </p>
+
+ {% for set in day.set_set.select_related %}
+ {% for exercise in set.exercises.select_related %}
- {% for exercise, date_list in exercise_log.items %}
- <div class="alert alert-info" style="text-align: center;margin-top:1em;">
- <a href="{{ exercise.get_absolute_url }}">{{ exercise.name }}</a>
- </div>
-
- {% if date_list.log_by_date %}
- {% with list=date_list.log_by_date %}
- {% render_weight_log list date_list.div_uuid %}
-
- <script>
- $(document).ready(function() {
- weight_log_chart({{date_list.chart_data|safe}}, "{{date_list.div_uuid}}", "{{reps}}")
- });
- </script>
- {% endwith %}
- {% else %}
- <p><em>{% trans "No weight entries here." %}</em></p>
- {% endif %}
+ {% with day_list=workout_log|get_item:day.id %}
+ {% with exercise_list=day_list|get_item:exercise.id %}
+
+ <div class="alert alert-info" style="text-align: center;margin-top:1em;">
+ <a href="{{ exercise.get_absolute_url }}">{{ exercise.name }}</a>
+ </div>
+
+ {% if exercise_list.log_by_date %}
+ {% with list=exercise_list.log_by_date %}
+ {% render_weight_log list exercise_list.div_uuid %}
+
+ <script>
+ $(document).ready(function() {
+ weight_log_chart({{exercise_list.chart_data|safe}}, "{{exercise_list.div_uuid}}", "{{reps}}")
+ });
+ </script>
+ {% endwith %}
+ {% else %}
+ <p><em>{% trans "No weight entries here." %}</em></p>
+ {% endif %}
+
+ {% endwith %}
+ {% endwith %}
{% empty%}
<p>
<em>{% trans "No exercises for this day." %}</em>
</p>
{% endfor %}
+ {% endfor %}
{% endfor %}
-
-
{% endblock %}
diff --git a/wger/manager/templatetags/wger_extras.py b/wger/manager/templatetags/wger_extras.py
index 786a38065..2c382ad0c 100644
--- a/wger/manager/templatetags/wger_extras.py
+++ b/wger/manager/templatetags/wger_extras.py
@@ -123,3 +123,11 @@ def language_select(context, language):
return {'language_name': language[1],
'path': 'images/icons/flag-{0}.svg'.format(language[0]),
'i18n_path': context['i18n_path'][language[0]]}
+
+
+def get_item(dictionary, key):
+ '''
+ Allows to access a specific key in a dictionary in a template
+ '''
+ return dictionary.get(key)
diff --git a/wger/manager/views/log.py b/wger/manager/views/log.py
index 7660bc69e..f0e92542b 100644
--- a/wger/manager/views/log.py
+++ b/wger/manager/views/log.py
@@ -164,6 +164,7 @@ def add(request, pk):
template_data['day'] = day
template_data['exercises'] = exercise_list
+ template_data['exercise_list'] = exercise_list
template_data['formset'] = formset
template_data['dateform'] = dateform
template_data['form_action'] = reverse('day-log', kwargs={'pk': pk})
@@ -193,24 +194,24 @@ class WorkoutLogDetailView(DetailView, WgerPermissionMixin):
entry = WorkoutLog()
for day in self.object.day_set.select_related():
- workout_log[day] = {}
+ workout_log[day.id] = {}
for set in day.set_set.select_related():
exercise_log = {}
for exercise in set.exercises.select_related():
- exercise_log[exercise] = []
+ exercise_log[exercise.id] = []
logs = exercise.workoutlog_set.filter(user=self.request.user,
workout=self.object)
entry_log, chart_data = entry.process_log_entries(logs)
if entry_log:
- exercise_log[exercise].append(entry_log)
+ exercise_log[exercise.id].append(entry_log)
if exercise_log:
- workout_log[day][exercise] = {}
- workout_log[day][exercise]['log_by_date'] = entry_log
- workout_log[day][exercise]['div_uuid'] = str(uuid.uuid4())
- workout_log[day][exercise]['chart_data'] = chart_data
+ workout_log[day.id][exercise.id] = {}
+ workout_log[day.id][exercise.id]['log_by_date'] = entry_log
+ workout_log[day.id][exercise.id]['div_uuid'] = 'div-' + str(uuid.uuid4())
+ workout_log[day.id][exercise.id]['chart_data'] = chart_data
context['workout_log'] = workout_log
context['reps'] = _("Reps")