Self hosted FLOSS fitness/workout, nutrition and weight tracker
Render the edit/delete links for muscles outside of the cache block
Roland Geider5e62d92b00e9
diff --git a/wger/exercises/templates/muscles/overview.html b/wger/exercises/templates/muscles/overview.htmlindex 7d51d6bc8..50de207c5 100644--- a/wger/exercises/templates/muscles/overview.html+++ b/wger/exercises/templates/muscles/overview.html@@ -18,6 +18,7 @@ function highlight_muscle(element)var div_id = $(element).data('target');var is_front = ($(element).data('isFront') == 'True') ? 'front' : 'back';var muscle_id = div_id.match(/\d+/);+ var muscle_name = $(element).data('name');// Reset all other highlighted muscles$('.muscle').removeClass('muscle-active');@@ -27,6 +28,12 @@ function highlight_muscle(element)$(element).removeClass('muscle-inactive');$(element).addClass('muscle-active');+ {% if perms.exercises %}+ $('#muscle-edit-box').show();+ $('.muscle-edit-name').html(muscle_name);+ $('#muscle-edit-edit-link').attr("href", "/exercise/muscle/" + muscle_id + "/edit/");+ $('#muscle-delete-edit-link').attr("href", "/exercise/muscle/" + muscle_id + "/delete/");+ {% endif %}// Set the corresponding background$('#muscle-system').css('background-image',@@ -92,28 +99,9 @@ $(document).ready(function() {<li class="muscle"data-target="muscle-{{muscle.id}}"data-is-front="{{muscle.is_front}}"+ data-name="{{muscle.name}}"itemscope itemtype="http://schema.org/Muscle"><span itemprop="name">{{muscle.name}}</span>-- {% if perms.exercises %}- <span style="float:right;">- <a href="{% url 'muscle-edit' muscle.id %}"- class="modal-dialog no-hover">- <img src="{% static 'images/icons/edit.svg' %}"- width="16"- height="16"- alt="{% trans 'Edit muscle' %}"- title="{% trans 'Edit muscle' %}"></a>-- <a href="{% url 'muscle-delete' muscle.id %}"- class="modal-dialog no-hover">- <img src="{% static 'images/icons/trash.svg' %}"- width="16"- height="16"- alt="{% trans 'Delete muscle' %}"- title="{% trans 'Delete muscle' %}"></a>- </span>- {% endif %}</li>{% endfor %}</ul>@@ -127,7 +115,7 @@ $(document).ready(function() {<h3>{% trans "Exercises" %}</h3><ul class="exercise-overview">{% for exercise in muscle.exercise_set.select_related %}- {% if exercise.category.language == language %}+ {% if exercise.language == language %}<li class="exercise"><a href="{{exercise.get_absolute_url}}">{{exercise}}</a></li>@@ -143,6 +131,7 @@ $(document).ready(function() {</div></div></div>+{% endcache %}{% if perms.exercises %}<h3>{% trans "Options" %}</h3>@@ -163,9 +152,32 @@ $(document).ready(function() {<p>{% blocktrans %}<strong>Important:</strong> After adding a muscle, you needto create a new SVG image with the contours of the muscle and place it in thefolder <em>images/muscles</em>.{% endblocktrans %}</p>+++<div id="muscle-edit-box" style="display:none;">+<p>+ <a href="{% url 'muscle-edit' 1 %}"+ class="modal-dialog"+ id="muscle-edit-edit-link">+ <img src="{% static 'images/icons/edit.svg' %}"+ width="32"+ height="32"+ alt="{% trans 'Edit muscle' %}"+ title="{% trans 'Edit muscle' %}">{% trans 'Edit muscle' %}: <span class="muscle-edit-name"></span></a>+</p>+<p>+ <a href="{% url 'muscle-delete' 1 %}"+ class="modal-dialog"+ id="muscle-edit-delete-link">+ <img src="{% static 'images/icons/trash.svg' %}"+ width="32"+ height="32"+ alt="{% trans 'Delete muscle' %}"+ title="{% trans 'Delete muscle' %}">{% trans 'Delete muscle' %}: <span class="muscle-edit-name"></span></a>+</p>+</div>{% endif %}-{% endcache %}{% endblock %}diff --git a/wger/exercises/tests/muscles.py b/wger/exercises/tests/muscles.pyindex 2364940c2..0f32e0cdd 100644--- a/wger/exercises/tests/muscles.py+++ b/wger/exercises/tests/muscles.py@@ -73,3 +73,29 @@ class MuscleCacheTestCase(WorkoutManagerTestCase):self.assertFalse(cache.get(get_template_cache_name('muscle-overview', 2)))self.client.get(reverse('muscle-overview'))self.assertTrue(cache.get(get_template_cache_name('muscle-overview', 2)))+++class MuscleOverviewTestCase(WorkoutManagerTestCase):+ '''+ Test that only admins see the edit links+ '''++ def test_overview(self):+ '''+ Test that only admins see the edit links+ '''++ self.user_login('admin')+ response = self.client.get(reverse('muscle-overview'))+ self.assertContains(response, 'Edit muscle')+ self.assertContains(response, 'Delete muscle')+ self.assertContains(response, 'Add muscle')+ self.assertContains(response, 'After adding a muscle')++ self.user_logout()+ response = self.client.get(reverse('muscle-overview'))+ self.assertNotContains(response, 'Edit muscle')+ self.assertNotContains(response, 'Delete muscle')+ self.assertNotContains(response, 'Add muscle')+ self.assertNotContains(response, 'After adding a muscle')+