Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Show ingredient images in the overview, if available

Roland Geidera15dcafe58aa
diff --git a/wger/nutrition/templates/ingredient/overview.html b/wger/nutrition/templates/ingredient/overview.html
index 483ac4415..33427c3ec 100644
--- a/wger/nutrition/templates/ingredient/overview.html
+++ b/wger/nutrition/templates/ingredient/overview.html
@@ -39,7 +39,19 @@
{% if ingredients_list %}
<div class="list-group">
{% for ingredient in ingredients_list %}
- <a class="list-group-item" href="{{ ingredient.get_absolute_url }}">
+ <a class="list-group-item list-group-item-action d-inline-flex align-items-center justify-content-start"
+ href="{{ ingredient.get_absolute_url }}">
+ <span class="text-white rounded-circle m-1 me-2"
+ style="background-color: lightgray; width: 40px; height: 40px;">
+ {% if ingredient.image %}
+ <img src="{{ ingredient.image.image.url }}"
+ class="img-fluid"
+ alt="{{ ingredient.name }}"
+ style="height: 40px; width: 40px; border-radius: 50%;">
+ {% else %}
+ <i class="fas fa-camera fa-sx" style="text-align:center; width: 40px;"></i>
+ {% endif %}
+ </span>
{{ ingredient.name }}
</a>
{% endfor %}
diff --git a/wger/nutrition/tests/test_ingredient_overview.py b/wger/nutrition/tests/test_ingredient_overview.py
index ea56a9fc5..538f8abc6 100644
--- a/wger/nutrition/tests/test_ingredient_overview.py
+++ b/wger/nutrition/tests/test_ingredient_overview.py
@@ -21,13 +21,12 @@ from wger.core.tests.base_testcase import WgerTestCase
from wger.utils.constants import PAGINATION_OBJECTS_PER_PAGE
-class OverviewPlanTestCase(WgerTestCase):
+class IngredientOverviewTestCase(WgerTestCase):
"""
Tests the ingredient overview
"""
def test_overview(self):
-
# Add more ingredients so we can test the pagination
self.user_login('admin')
data = {
@@ -74,7 +73,7 @@ class OverviewPlanTestCase(WgerTestCase):
response = self.client.get(reverse('nutrition:ingredient:list'), {'page': 'foobar'})
self.assertEqual(response.status_code, 404)
- def ingredient_overview(self, logged_in=True, demo=False, admin=False):
+ def ingredient_overview(self):
"""
Helper function to test the ingredient overview page
"""
@@ -83,30 +82,17 @@ class OverviewPlanTestCase(WgerTestCase):
response = self.client.get(reverse('nutrition:ingredient:list'))
self.assertEqual(response.status_code, 200)
- # No ingredients pending review
- if admin:
- self.assertContains(response, 'Ingredients pending review')
- else:
- self.assertNotContains(response, 'Ingredients pending review')
-
- # Only authorized users see the edit links
- if logged_in and not demo:
- self.assertNotContains(response, 'Only registered users can do this')
-
- if logged_in and demo:
- self.assertContains(response, 'Only registered users can do this')
-
def test_ingredient_index_editor(self):
"""
- Tests the ingredient overview page as a logged in user with editor rights
+ Tests the ingredient overview page as a logged-in user with editor rights
"""
self.user_login('admin')
- self.ingredient_overview(admin=True)
+ self.ingredient_overview()
def test_ingredient_index_non_editor(self):
"""
- Tests the overview overview page as a logged in user without editor rights
+ Tests the overview page as a logged-in user without editor rights
"""
self.user_login('test')
@@ -114,15 +100,15 @@ class OverviewPlanTestCase(WgerTestCase):
def test_ingredient_index_demo_user(self):
"""
- Tests the overview overview page as a logged in demo user
+ Tests the overview page as a logged in demo user
"""
self.user_login('demo')
- self.ingredient_overview(demo=True)
+ self.ingredient_overview()
def test_ingredient_index_logged_out(self):
"""
- Tests the overview overview page as an anonymous (logged out) user
+ Tests the overview page as an anonymous (logged out) user
"""
- self.ingredient_overview(logged_in=False)
+ self.ingredient_overview()