Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Show muscles for front and back, as some exercises work both sides

Roland Geider63d58f083b9f
diff --git a/exercises/templates/view.html b/exercises/templates/view.html
index e3ac23778..99bba84c5 100644
--- a/exercises/templates/view.html
+++ b/exercises/templates/view.html
@@ -108,10 +108,11 @@ $(document).ready(function() {
{% trans "The diagram shows the most used muscles on this exercise" %}
</p>
+{% if muscle_backgrounds_front %}
<div class="ym-grid linearize-level-1">
<div class="ym-g50 ym-gl">
<div class="ym-gbox-left">
- <div id="muscle-front" class="muscle-background" style="background-image: {% for background in muscle_backgrounds %}url({% static background %}){% if not forloop.last %},{% endif %}{% endfor %};">
+ <div id="muscle-front" class="muscle-background" style="background-image: {% for background in muscle_backgrounds_front %}url({% static background %}){% if not forloop.last %},{% endif %}{% endfor %};">
</div>
</div>
</div>
@@ -119,7 +120,9 @@ $(document).ready(function() {
<div class="ym-gbox-right">
<ul>
{% for muscle in exercise.muscles.all %}
+ {% if muscle.is_front %}
<li>{{muscle.name}}</li>
+ {% endif %}
{% endfor %}
</ul>
</div>
@@ -127,6 +130,32 @@ $(document).ready(function() {
</div>
{% endif %}
+
+{% if muscle_backgrounds_back %}
+<div class="ym-grid linearize-level-1">
+ <div class="ym-g50 ym-gl">
+ <div class="ym-gbox-left">
+ <div id="muscle-front" class="muscle-background" style="background-image: {% for background in muscle_backgrounds_back %}url({% static background %}){% if not forloop.last %},{% endif %}{% endfor %};">
+ </div>
+ </div>
+ </div>
+ <div class="ym-g40 ym-gr">
+ <div class="ym-gbox-right">
+ <ul>
+ {% for muscle in exercise.muscles.all %}
+ {% if not muscle.is_front %}
+ <li>{{muscle.name}}</li>
+ {% endif %}
+ {% endfor %}
+ </ul>
+ </div>
+ </div>
+</div>
+{% endif %}
+
+
+{% endif %}
+
{% if perms.exercises %}
<h3>{% trans "Options" %}</h3>
<p>
diff --git a/exercises/views.py b/exercises/views.py
index 6b8d9e150..00408cbc7 100644
--- a/exercises/views.py
+++ b/exercises/views.py
@@ -104,23 +104,25 @@ def exercise_view(request, id, comment_id=None):
template_data.update(csrf(request))
# Create the backgrounds that show what muscles the exercise works on
- backgrounds = []
- is_front = True
+ backgrounds_back = []
+ backgrounds_front = []
+
for muscle in exercise.muscles.all():
- # In theory some muscles associated with the exercercise could be for the front, others for
- # the back. But this shoult not happen in practice, so it's OK
- is_front = muscle.is_front
+ if muscle.is_front:
+ backgrounds_front.append('images/muscles/main/muscle-%s.svg' % muscle.id)
+ else:
+ backgrounds_back.append('images/muscles/main/muscle-%s.svg' % muscle.id)
- backgrounds.append('images/muscles/main/muscle-%s.svg' % muscle.id)
-
- # Append the correct "main" background, with the silhouette of the human body
- if is_front:
- backgrounds.append('images/muscles/muscular_system_front.svg')
- else:
- backgrounds.append('images/muscles/muscular_system_back.svg')
-
- template_data['muscle_backgrounds'] = backgrounds
-
+ # Append the "main" background, with the silhouette of the human body
+ # This has to happen as the last step, so it is rendered behind the muscles.
+ if backgrounds_front:
+ backgrounds_front.append('images/muscles/muscular_system_front.svg')
+
+ if backgrounds_back:
+ backgrounds_back.append('images/muscles/muscular_system_back.svg')
+
+ template_data['muscle_backgrounds_front'] = backgrounds_front
+ template_data['muscle_backgrounds_back'] = backgrounds_back
# Only users with the appropriate permissions can work with comments
if request.user.has_perm('exercises.add_exercisecomment'):