Skip to content

Commit

Permalink
Don't force users to add individual ingredients/products to a plan
Browse files Browse the repository at this point in the history
Closes #817
  • Loading branch information
rolandgeider committed Sep 29, 2023
1 parent cba2451 commit bf84232
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 27 deletions.
1 change: 0 additions & 1 deletion wger/core/templates/user/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ <h4>{% translate "Weight" %} <small>({% blocktranslate with number=5 %}last {{ n
<h4>{% translate "Nutrition plans" %} <small>({% blocktranslate with number=5 %}last {{ number }}{% endblocktranslate %})</small></h4>
{% if perms.gym.gym_trainer %}
<a href="{{trainer_login}}?next={% url 'nutrition:plan:overview' %}" class="btn btn-light btn-sm">{% translate "Overview" %}</a>
<a href="{{trainer_login}}?next={% url 'nutrition:plan:add' %}" class="btn btn-light btn-sm">{% translate "Add nutrition plan" %}</a>
{% endif %}

<table class="table">
Expand Down
11 changes: 3 additions & 8 deletions wger/core/tests/api_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,9 @@ def test_get_overview_is_cached(self):
if self.overview_cached:
cache_length = len(locmem._caches['wger-cache'])
self.assertNotEqual(cache_length, 0)

# TODO: Commented out because the nutritional plan caused this to fail.
# Since we do everything over the API now, we should decide one of
# these days if we want to move the calculations for the nutritional
# values out of the client and just read this
# else:
# cache_length = len(locmem._caches['wger-cache'])
# self.assertEqual(cache_length, 0)
else:
cache_length = len(locmem._caches['wger-cache'])
self.assertEqual(cache_length, 0)

def test_special_endpoints(self):
"""
Expand Down
15 changes: 1 addition & 14 deletions wger/core/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,7 @@ def dashboard(self):
self.assertTrue(response.context['weekdays'])

#
# 2. Add a nutrition plan
#
self.client.get(reverse('nutrition:plan:add'))
response = self.client.get(reverse('core:dashboard'))

self.assertEqual(response.status_code, 200)
self.assertFalse(response.context['weight'])
self.assertTrue(response.context['current_workout'])
self.assertTrue(response.context['plan'])
self.assertTrue(response.context['weekdays'])

#
# 3. Add a weight entry
# 2. Add a weight entry
#
self.client.post(reverse('weight:add'), {
'weight': 100,
Expand All @@ -86,7 +74,6 @@ def dashboard(self):
self.assertEqual(response.status_code, 200)
self.assertTrue(response.context['weight'])
self.assertTrue(response.context['current_workout'])
self.assertTrue(response.context['plan'])
self.assertTrue(response.context['weekdays'])

def test_dashboard_logged_in(self):
Expand Down
2 changes: 2 additions & 0 deletions wger/nutrition/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class Meta:
depth = 1
fields = [
'id',
'uuid',
'code',
'name',
'created',
Expand Down Expand Up @@ -323,6 +324,7 @@ class Meta:
'id',
'creation_date',
'description',
'only_logging',
'get_nutritional_values',
]

Expand Down
3 changes: 0 additions & 3 deletions wger/nutrition/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.

# Standard Library
import datetime
import logging

# Django
from django.conf import settings
from django.shortcuts import get_object_or_404
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page

Expand Down Expand Up @@ -77,7 +75,6 @@
from wger.utils.language import load_language
from wger.utils.viewsets import WgerOwnerObjectModelViewSet


logger = logging.getLogger(__name__)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ class Migration(migrations.Migration):
verbose_name='Meal'
),
),
migrations.AddField(
model_name='nutritionplan',
name='only_logging',
field=models.BooleanField(default=False, verbose_name='Only logging'),
),
]
7 changes: 7 additions & 0 deletions wger/nutrition/models/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class Meta:
'"Gain mass" or "Prepare for summer"'
),
)

only_logging = models.BooleanField(
verbose_name='Only logging',
default=False,
)
"""Flag to indicate that the nutritional plan will only used for logging"""

has_goal_calories = models.BooleanField(
verbose_name=_('Use daily calories'),
default=False,
Expand Down
5 changes: 4 additions & 1 deletion wger/nutrition/tests/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
class PlanApiTestCase(api_base_test.ApiBaseResourceTestCase):
"""
Tests the nutritional plan overview resource
TODO: setting overview_cached to true since get_nutritional_values is
cached, but we don't really use it. This should be removed
"""
pk = 4
resource = NutritionPlan
private_resource = True
overview_cached = False
overview_cached = True
special_endpoints = ('nutritional_values', )
data = {'description': 'The description'}

0 comments on commit bf84232

Please sign in to comment.