Self hosted FLOSS fitness/workout, nutrition and weight tracker
Start removing the old workout models
Roland Geider728364dd7321
diff --git a/wger/core/demo.py b/wger/core/demo.pyindex 888cd1866..caa3d6686 100644--- a/wger/core/demo.py+++ b/wger/core/demo.py@@ -15,52 +15,18 @@# You should have received a copy of the GNU Affero General Public License# Standard Library-import datetimeimport logging-import randomimport uuid# Djangofrom django.contrib.auth import authenticatefrom django.contrib.auth.models import User+from django.core.management import call_commandfrom django.http import HttpRequest-from django.utils.translation import gettext as _--# wger-from wger.core.models import DaysOfWeek-from wger.exercises.models import (- Exercise,- ExerciseBase,-)-from wger.manager.models import (- Day,- Routine,- Schedule,- ScheduleStep,- Set,- Setting,- Workout,- WorkoutLog,-)-from wger.nutrition.models import (- Ingredient,- IngredientWeightUnit,- Meal,- MealItem,- NutritionPlan,-)-from wger.utils.language import load_language-from wger.weight.models import WeightEntrylogger = logging.getLogger(__name__)-UUID_SQUATS = 'a2f5b6ef-b780-49c0-8d96-fdaff23e27ce'-UUID_CURLS = '1ae6a28d-10e7-4ecf-af4f-905f8193e2c6'-UUID_FRENCH_PRESS = '95a7e546-e8f8-4521-a76b-983d94161b25'-UUID_CRUNCHES = 'b186f1f8-4957-44dc-bf30-d0b00064ce6f'-UUID_LEG_RAISES = 'c2078aac-e4e2-4103-a845-6252a3eb795e'-def create_temporary_user(request: HttpRequest):"""@@ -85,340 +51,33 @@ def create_demo_entries(user):"""Creates some demo data for temporary users"""-- # (this is a bit ugly and long...)- language = load_language()-- #- # Workout and exercises- #- setting_list = []- weight_log = []- routine = Routine(- user=user,- name=_('Sample workout'),- start=datetime.date.today(),- end=datetime.date.today() + datetime.timedelta(days=60),+ call_command(+ 'dummy-generator-routines',+ '--routines=4',+ f'--user-id={user.id}',+ )+ call_command(+ 'dummy-generator-workout-diary',+ '--diary-entries=5',+ f'--user-id={user.id}',+ )+ call_command(+ 'dummy-generator-body-weight',+ '--nr-entries=40',+ f'--user-id={user.id}',+ )+ call_command(+ 'dummy-generator-nutrition',+ '--plans=5',+ f'--user-id={user.id}',+ )+ call_command(+ 'dummy-generator-measurement-categories',+ '--nr-categories=4',+ f'--user-id={user.id}',+ )+ call_command(+ 'dummy-generator-measurements',+ '--nr-measurements=10',+ f'--user-id={user.id}',)- routine.save()- monday = DaysOfWeek.objects.get(pk=1)- wednesday = DaysOfWeek.objects.get(pk=3)- day = Day(training=routine, description=_('Sample day'))- day.save()- day.day.add(monday)-- day2 = Day(training=routine, description=_('Another sample day'))- day2.save()- day2.day.add(wednesday)-- # Biceps curls with dumbbell- exercise = ExerciseBase.objects.get(uuid=UUID_CURLS)- day_set = Set(exerciseday=day, sets=4, order=2)- day_set.save()-- setting = Setting(set=day_set, exercise_base=exercise, reps=8, order=1)- setting.save()-- # Weight log entries- for reps in (8, 10, 12):- for i in range(1, 8):- log = WorkoutLog(- user=user,- exercise=exercise,- routine=routine,- reps=reps,- weight=18 - reps + random.randint(1, 4),- date=datetime.date.today() - datetime.timedelta(weeks=i),- )- weight_log.append(log)-- # French press- exercise = ExerciseBase.objects.get(uuid=UUID_FRENCH_PRESS)- day_set = Set(exerciseday=day, sets=4, order=2)- day_set.save()-- setting_list.append(Setting(set=day_set, exercise_base=exercise, reps=8, order=1))-- # Weight log entries- for reps in (7, 10):- for i in range(1, 8):- log = WorkoutLog(- user=user,- exercise=exercise,- routine=routine,- reps=reps,- weight=30 - reps + random.randint(1, 4),- date=datetime.date.today() - datetime.timedelta(weeks=i),- )- weight_log.append(log)-- # Squats- exercise = ExerciseBase.objects.get(uuid=UUID_SQUATS)- day_set = Set(exerciseday=day, sets=4, order=3)- day_set.save()-- setting_list.append(Setting(set=day_set, exercise_base=exercise, reps=10, order=1))-- # Weight log entries- for reps in (5, 10, 12):- for i in range(1, 8):- log = WorkoutLog(- user=user,- exercise=exercise,- routine=routine,- reps=reps,- weight=110 - reps + random.randint(1, 10),- date=datetime.date.today() - datetime.timedelta(weeks=i),- )- weight_log.append(log)-- # Crunches- exercise = ExerciseBase.objects.get(uuid=UUID_CRUNCHES)- day_set = Set(exerciseday=day, sets=4, order=4)- day_set.save()-- setting_list.append(Setting(set=day_set, exercise_base=exercise, reps=30, order=1))- setting_list.append(Setting(set=day_set, exercise_base=exercise, reps=99, order=2))- setting_list.append(Setting(set=day_set, exercise_base=exercise, reps=35, order=3))-- # Leg raises, supersets with crunches- exercise = ExerciseBase.objects.get(uuid=UUID_LEG_RAISES)-- setting_list.append(Setting(set=day_set, exercise_base=exercise, reps=30, order=1))- setting_list.append(Setting(set=day_set, exercise_base=exercise, reps=40, order=2))- setting_list.append(Setting(set=day_set, exercise_base=exercise, reps=99, order=3))-- Setting.objects.bulk_create(setting_list)-- # Save all the log entries- WorkoutLog.objects.bulk_create(weight_log)-- #- # (Body) weight entries- #- temp = []- existing_entries = [i.date for i in WeightEntry.objects.filter(user=user)]- for i in range(1, 20):- creation_date = datetime.date.today() - datetime.timedelta(days=i)- if creation_date not in existing_entries:- entry = WeightEntry(- user=user,- weight=80 + 0.5 * i + random.randint(1, 3),- date=creation_date,- )- temp.append(entry)- WeightEntry.objects.bulk_create(temp)-- #- # Nutritional plan- #- plan = NutritionPlan()- plan.user = user- plan.language = language- plan.description = _('Sample nutritional plan')- plan.save()-- # Breakfast- meal = Meal()- meal.plan = plan- meal.order = 1- meal.time = datetime.time(7, 30)- meal.save()-- # Oatmeal- if language.short_name == 'de':- ingredient = Ingredient.objects.get(pk=8197)- else:- ingredient = Ingredient.objects.get(pk=2126)-- mealitem = MealItem()- mealitem.meal = meal- mealitem.ingredient = ingredient- mealitem.order = 1- mealitem.amount = 100- mealitem.save()-- # Milk- if language.short_name == 'de':- ingredient = Ingredient.objects.get(pk=8198)- else:- ingredient = Ingredient.objects.get(pk=154)-- mealitem = MealItem()- mealitem.meal = meal- mealitem.ingredient = ingredient- mealitem.order = 2- mealitem.amount = 100- mealitem.save()-- # Protein powder- if language.short_name == 'de':- ingredient = Ingredient.objects.get(pk=8244)- else:- ingredient = Ingredient.objects.get(pk=196)-- mealitem = MealItem()- mealitem.meal = meal- mealitem.ingredient = ingredient- mealitem.order = 3- mealitem.amount = 30- mealitem.save()-- #- # 11 o'clock meal- meal = Meal()- meal.plan = plan- meal.order = 2- meal.time = datetime.time(11, 0)- meal.save()-- # Bread, in slices- if language.short_name == 'de':- ingredient = Ingredient.objects.get(pk=8225)- unit = None- amount = 80- else:- ingredient = Ingredient.objects.get(pk=5370)- unit = IngredientWeightUnit.objects.get(pk=9874)- amount = 2-- mealitem = MealItem()- mealitem.meal = meal- mealitem.ingredient = ingredient- mealitem.weight_unit = unit- mealitem.order = 1- mealitem.amount = amount- mealitem.save()-- # Turkey- if language.short_name == 'de':- ingredient = Ingredient.objects.get(pk=8201)- else:- ingredient = Ingredient.objects.get(pk=1643)-- mealitem = MealItem()- mealitem.meal = meal- mealitem.order = 2- mealitem.ingredient = ingredient- mealitem.amount = 100- mealitem.save()-- # Cottage cheese- if language.short_name == 'de':- ingredient = Ingredient.objects.get(pk=8222) # TODO: check this!- else:- ingredient = Ingredient.objects.get(pk=17)-- mealitem = MealItem()- mealitem.meal = meal- mealitem.ingredient = ingredient- mealitem.order = 3- mealitem.amount = 50- mealitem.save()-- # Tomato, one- if language.short_name == 'de':- ingredient = Ingredient.objects.get(pk=8217)- unit = None- amount = 120- else:- ingredient = Ingredient.objects.get(pk=3208)- unit = IngredientWeightUnit.objects.get(pk=5950)- amount = 1-- mealitem = MealItem()- mealitem.meal = meal- mealitem.weight_unit = unit- mealitem.ingredient = ingredient- mealitem.order = 4- mealitem.amount = amount- mealitem.save()-- #- # Lunch (leave empty so users can add their own ingredients)- meal = Meal()- meal.plan = plan- meal.order = 3- meal.time = datetime.time(13, 0)- meal.save()-- #- # Workout schedules- #-- # create some empty workouts to fill the list- workout2 = Workout(user=user, name=_('Placeholder workout nr {0} for schedule').format(1))- workout2.save()- workout3 = Workout(user=user, name=_('Placeholder workout nr {0} for schedule').format(2))- workout3.save()- workout4 = Workout(user=user, name=_('Placeholder workout nr {0} for schedule').format(3))- workout4.save()-- schedule = Schedule()- schedule.user = user- schedule.name = _('My cool workout schedule')- schedule.start_date = datetime.date.today() - datetime.timedelta(weeks=4)- schedule.is_active = True- schedule.is_loop = True- schedule.save()-- # Add the workouts- step = ScheduleStep()- step.schedule = schedule- step.workout = workout2- step.duration = 2- step.order = 1- step.save()-- step = ScheduleStep()- step.schedule = schedule- step.workout = routine- step.duration = 4- step.order = 2- step.save()-- step = ScheduleStep()- step.schedule = schedule- step.workout = workout3- step.duration = 1- step.order = 3- step.save()-- step = ScheduleStep()- step.schedule = schedule- step.workout = workout4- step.duration = 6- step.order = 4- step.save()-- #- # Add two more schedules, to make the overview more interesting- schedule = Schedule()- schedule.user = user- schedule.name = _('Empty placeholder schedule')- schedule.start_date = datetime.date.today() - datetime.timedelta(weeks=15)- schedule.is_active = False- schedule.is_loop = False- schedule.save()-- step = ScheduleStep()- step.schedule = schedule- step.workout = workout2- step.duration = 2- step.order = 1- step.save()-- schedule = Schedule()- schedule.user = user- schedule.name = _('Empty placeholder schedule')- schedule.start_date = datetime.date.today() - datetime.timedelta(weeks=30)- schedule.is_active = False- schedule.is_loop = False- schedule.save()-- step = ScheduleStep()- step.schedule = schedule- step.workout = workout4- step.duration = 2- step.order = 1- step.save()diff --git a/wger/core/templates/user/overview.html b/wger/core/templates/user/overview.htmlindex b21b7099c..7ecdb17aa 100644--- a/wger/core/templates/user/overview.html+++ b/wger/core/templates/user/overview.html@@ -22,7 +22,7 @@{% if perms.gym.gym_trainer %}-<h4>{% translate "Workouts" %} <small>({% blocktranslate with number=10 %}last {{ number }}{% endblocktranslate %})</small></h4>+<h4>{% translate "Routines" %} <small>({% blocktranslate with number=10 %}last {{ number }}{% endblocktranslate %})</small></h4>{% if perms.gym.gym_trainer %}<a href="{{trainer_login}}?next={% url 'manager:workout:overview' %}" class="btn btn-light btn-sm">{% translate "Overview" %}</a><a href="{{trainer_login}}?next={% url 'manager:workout:add' %}" class="btn btn-light btn-sm">{% translate "Add workout" %}</a>@@ -38,19 +38,19 @@</tr></thead><tbody>-{% for workout in workouts %}+{% for entry in routine_data %}<tr><td>- {{workout.workout.creation_date}}+ {{entry.routine.created}}</td><td>- <a href="{{trainer_login}}?next={{ workout.workout.get_absolute_url }}">{{workout.workout}}</a>+ <a href="{{trainer_login}}?next={{ entry.routine.get_absolute_url }}">{{entry.routine}}</a></td><td>- {{workout.logs|default:'-/-'}}+ {{entry.logs|default:'-/-'}}</td><td>- {{workout.last_log.date|default:'-/-'}}+ {{entry.last_log.date|default:'-/-'}}</td></tr>{% empty %}diff --git a/wger/core/tests/test_temporary_users.py b/wger/core/tests/test_temporary_users.pyindex 4f32b7651..815dafa03 100644--- a/wger/core/tests/test_temporary_users.py+++ b/wger/core/tests/test_temporary_users.py@@ -29,10 +29,8 @@ from wger.core.demo import ()from wger.core.tests.base_testcase import WgerTestCasefrom wger.manager.models import (- Day,- Schedule,- ScheduleStep,- Workout,+ DayNg,+ Routine,WorkoutLog,)from wger.nutrition.models import (@@ -84,24 +82,21 @@ class DemoUserTestCase(WgerTestCase):self.assertEqual(self.count_temp_users(), 2)user = User.objects.get(pk=User.objects.latest('id').id)self.assertEqual(user.userprofile.is_temporary, True)- self.assertEqual(Workout.objects.filter(user=user).count(), 0)+ self.assertEqual(Routine.objects.filter(user=user).count(), 0)self.client.get(reverse('core:user:demo-entries'))- # Workout- self.assertEqual(Workout.objects.filter(user=user).count(), 4)- self.assertEqual(Day.objects.filter(training__user=user).count(), 2)- self.assertEqual(WorkoutLog.objects.filter(user=user).count(), 56)- # Schedule- self.assertEqual(Schedule.objects.filter(user=user).count(), 3)- self.assertEqual(ScheduleStep.objects.filter(schedule__user=user).count(), 6)+ # Routine+ self.assertEqual(Routine.objects.filter(user=user).count(), 4)+ self.assertGreater(DayNg.objects.filter(routine__user=user).count(), 5)+ self.assertGreater(WorkoutLog.objects.filter(user=user).count(), 400)# Nutrition- self.assertEqual(NutritionPlan.objects.filter(user=user).count(), 1)- self.assertEqual(Meal.objects.filter(plan__user=user).count(), 3)+ self.assertEqual(NutritionPlan.objects.filter(user=user).count(), 5)+ self.assertEqual(Meal.objects.filter(plan__user=user).count(), 20)# Body weight- self.assertEqual(WeightEntry.objects.filter(user=user).count(), 19)+ self.assertEqual(WeightEntry.objects.filter(user=user).count(), 40)def test_demo_data_body_weight(self):"""@@ -125,7 +120,7 @@ class DemoUserTestCase(WgerTestCase):create_demo_entries(user)# Body weight- self.assertEqual(WeightEntry.objects.filter(user=user).count(), 19)+ self.assertEqual(WeightEntry.objects.filter(user=user).count(), 40)def test_demo_user(self):"""diff --git a/wger/core/views/user.py b/wger/core/views/user.pyindex dda9f59f9..119c2dfb6 100644--- a/wger/core/views/user.py+++ b/wger/core/views/user.py@@ -91,7 +91,7 @@ from wger.gym.models import (GymUserConfig,)from wger.manager.models import (- Workout,+ Routine,WorkoutLog,WorkoutSession,)@@ -537,17 +537,17 @@ class UserDetailView(LoginRequiredMixin, WgerMultiplePermissionRequiredMixin, De"""context = super(UserDetailView, self).get_context_data(**kwargs)out = []- workouts = Workout.objects.filter(user=self.object).all()- for workout in workouts:- logs = WorkoutLog.objects.filter(workout=workout)+ routines = Routine.objects.filter(user=self.object).all()+ for routine in routines:+ logs = WorkoutLog.objects.filter(routine=routine)out.append({- 'workout': workout,+ 'routine': routine,'logs': logs.dates('date', 'day').count(),'last_log': logs.last(),})- context['workouts'] = out+ context['routine_data'] = outcontext['weight_entries'] = WeightEntry.objects.filter(user=self.object).order_by('-date')[:5]diff --git a/wger/exercises/management/commands/delete-unused-exercises.py b/wger/exercises/management/commands/delete-unused-exercises.pydeleted file mode 100644index 8ba6c68a7..000000000--- a/wger/exercises/management/commands/delete-unused-exercises.py+++ /dev/null@@ -1,62 +0,0 @@-# This file is part of wger Workout Manager.-#-# wger Workout Manager is free software: you can redistribute it and/or modify-# it under the terms of the GNU Affero General Public License as published by-# the Free Software Foundation, either version 3 of the License, or-# (at your option) any later version.-#-# wger Workout Manager is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU Affero General Public License--# Standard Library-import collections--# Django-from django.core.management.base import BaseCommand--# wger-from wger.core.models import Language-from wger.exercises.models import ExerciseBase-from wger.manager.models import (- Setting,- WorkoutLog,-)-from wger.utils.constants import ENGLISH_SHORT_NAME---class Command(BaseCommand):- """- Deletes all unused exercises- """-- help = """Deletes all unused exercises from the database. After running this script, sync- the database with ´python manage.py sync-exercises`- """-- def handle(self, **options):- # Collect all exercise bases that are not used in any workout or log entry- out = f'{ExerciseBase.objects.all().count()} exercises currently in the database'- self.stdout.write(out)-- exercises = set(Setting.objects.all().values_list('exercise_base', flat=True))- logs = set(WorkoutLog.objects.all().values_list('exercise', flat=True))- exercises.update(logs)-- # Ask for confirmation- out = f'{len(exercises)} exercises are in use, delete the rest?'- self.stdout.write(out)- response = ''- while response not in ('y', 'n'):- response = input('Type y to delete or n to exit: ')-- if response == 'y':- ExerciseBase.objects.exclude(pk__in=exercises).delete()- out = self.style.SUCCESS('Done! You can now run python manage.py sync-exercises')- self.stdout.write(out)- else:- out = self.style.SUCCESS('Exiting without deleting anything')- self.stdout.write(out)diff --git a/wger/exercises/sync.py b/wger/exercises/sync.pyindex 7cbc1ffbe..63dd74f54 100644--- a/wger/exercises/sync.py+++ b/wger/exercises/sync.py@@ -54,7 +54,7 @@ from wger.exercises.models import (Muscle,)from wger.manager.models import (- Setting,+ SlotConfig,WorkoutLog,)from wger.utils.requests import (@@ -313,6 +313,7 @@ def handle_deleted_entries(if model_type == DeletionLog.MODEL_BASE:obj_replaced = Nonenr_settings = None+ nr_slot_configs = Nonenr_logs = Nonetry:obj_replaced = ExerciseBase.objects.get(uuid=replaced_by_uuid)@@ -324,19 +325,20 @@ def handle_deleted_entries(# Replace exercise in workouts and logsif obj_replaced:- nr_settings = Setting.objects.filter(exercise_base=obj).update(- exercise_base=obj_replaced- )- nr_logs = WorkoutLog.objects.filter(exercise_base=obj).update(- exercise_base=obj_replaced+ nr_slot_configs = SlotConfig.objects.filter(exercise=obj).update(+ exercise=obj_replaced)+ nr_logs = WorkoutLog.objects.filter(exercise=obj).update(exercise=obj_replaced)+obj.delete()- print_fn(f'Deleted exercise base {uuid}')+ print_fn(f'Deleted exercise {uuid}')if nr_settings:- print_fn(f'- replaced {nr_settings} time(s) in workouts by {replaced_by_uuid}')+ print_fn(f'- replaced in {nr_settings} in workouts with {replaced_by_uuid}')+ if nr_slot_configs:+ print_fn(f'- replaced in {nr_slot_configs} routines with {replaced_by_uuid}')if nr_logs:- print_fn(f'- replaced {nr_logs} time(s) in workout logs by {replaced_by_uuid}')+ print_fn(f'- replaced in {nr_logs} workout logs with {replaced_by_uuid}')except ExerciseBase.DoesNotExist:passdiff --git a/wger/exercises/tests/test_sync.py b/wger/exercises/tests/test_sync.pyindex 5b12fb70c..92fc5e263 100644--- a/wger/exercises/tests/test_sync.py+++ b/wger/exercises/tests/test_sync.py@@ -38,7 +38,7 @@ from wger.exercises.sync import (sync_muscles,)from wger.manager.models import (- Setting,+ SlotConfig,WorkoutLog,)from wger.utils.requests import wger_headers@@ -278,14 +278,14 @@ class MockDeletionLogResponse:"uuid": "acad3949-36fb-4481-9a72-be2ddae2bc05","replaced_by": "ae3328ba-9a35-4731-bc23-5da50720c5aa","timestamp": "2023-01-30T19:32:56.761426+01:00",- "comment": "Exercise base with ID 1"+ "comment": "Exercise with ID 1"},{"model_type": "base","uuid": "577ee012-70c6-4517-b0fe-dcf340926ae7","replaced_by": None,"timestamp": "2023-01-30T19:32:56.761426+01:00",- "comment": "Unknown Exercise base"+ "comment": "Unknown Exercise"},{"model_type": "translation",@@ -650,13 +650,13 @@ class TestSyncMethods(WgerTestCase):self.assertEqual(ExerciseBase.objects.count(), 8)self.assertEqual(Exercise.objects.count(), 11)- base = ExerciseBase.objects.get(pk=1)- base2 = ExerciseBase.objects.get(pk=3)- self.assertFalse(Setting.objects.filter(exercise_base=base2).count())- self.assertFalse(WorkoutLog.objects.filter(exercise_base=base2).count())+ exercise1 = ExerciseBase.objects.get(pk=1)+ exercise2 = ExerciseBase.objects.get(pk=4)+ self.assertFalse(SlotConfig.objects.filter(exercise=exercise2).count())+ self.assertFalse(WorkoutLog.objects.filter(exercise=exercise2).count())- settings = Setting.objects.filter(exercise_base=base)- logs = WorkoutLog.objects.filter(exercise_base=base)+ slot_configs = SlotConfig.objects.filter(exercise=exercise1)+ logs = WorkoutLog.objects.filter(exercise=exercise1)handle_deleted_entries(print)@@ -670,17 +670,17 @@ class TestSyncMethods(WgerTestCase):self.assertRaises(ExerciseBase.DoesNotExist, ExerciseBase.objects.get, pk=1)# Workouts and logs have been moved- for setting_pk in settings:- self.assertEqual(Setting.objects.get(pk=setting_pk).exercise_base_id, 2)- for setting_pk in logs:- self.assertEqual(WorkoutLog.objects.get(pk=setting_pk).exercise_base_id, 2)+ for pk in slot_configs:+ self.assertEqual(SlotConfig.objects.get(pk=pk).exercise_id, 2)+ for pk in logs:+ self.assertEqual(WorkoutLog.objects.get(pk=pk).exercise_id, 2)@patch('requests.get', return_value=MockExerciseResponse())def test_exercise_sync(self, mock_request):self.assertEqual(ExerciseBase.objects.count(), 8)self.assertEqual(Exercise.objects.count(), 11)- base = ExerciseBase.objects.get(uuid='ae3328ba-9a35-4731-bc23-5da50720c5aa')- self.assertEqual(base.category_id, 2)+ exercise = ExerciseBase.objects.get(uuid='ae3328ba-9a35-4731-bc23-5da50720c5aa')+ self.assertEqual(exercise.category_id, 2)sync_exercises(lambda x: x)@@ -691,14 +691,14 @@ class TestSyncMethods(WgerTestCase):self.assertEqual(ExerciseBase.objects.count(), 9)self.assertEqual(Exercise.objects.count(), 14)- # New base was created- new_base = ExerciseBase.objects.get(uuid='1b020b3a-3732-4c7e-92fd-a0cec90ed69b')- self.assertEqual(new_base.category_id, 2)- self.assertEqual([e.id for e in new_base.equipment.all()], [2])- self.assertEqual([m.id for m in new_base.muscles.all()], [2])- self.assertEqual([m.id for m in new_base.muscles_secondary.all()], [4])+ # New exercise was created+ new_exercise = ExerciseBase.objects.get(uuid='1b020b3a-3732-4c7e-92fd-a0cec90ed69b')+ self.assertEqual(new_exercise.category_id, 2)+ self.assertEqual([e.id for e in new_exercise.equipment.all()], [2])+ self.assertEqual([m.id for m in new_exercise.muscles.all()], [2])+ self.assertEqual([m.id for m in new_exercise.muscles_secondary.all()], [4])- translation_de = new_base.get_translation('de')+ translation_de = new_exercise.get_translation('de')self.assertEqual(translation_de.language_id, 1)self.assertEqual(translation_de.name, 'Zweihandiges Kettlebell')self.assertEqual(translation_de.description, 'Hier könnte Ihre Werbung stehen!')@@ -708,16 +708,16 @@ class TestSyncMethods(WgerTestCase):'Wichtig die Übung richtig zu machen',)- translation_en = new_base.get_translation('en')+ translation_en = new_exercise.get_translation('en')self.assertEqual(translation_en.language_id, 2)self.assertEqual(translation_en.name, '2 Handed Kettlebell Swing')self.assertEqual(translation_en.description, 'TBD')- # Existing base was updated- base = ExerciseBase.objects.get(uuid='ae3328ba-9a35-4731-bc23-5da50720c5aa')- self.assertEqual(base.category_id, 3)+ # Existing exercise was updated+ exercise = ExerciseBase.objects.get(uuid='ae3328ba-9a35-4731-bc23-5da50720c5aa')+ self.assertEqual(exercise.category_id, 3)- translation_de = base.get_translation('de')+ translation_de = exercise.get_translation('de')self.assertEqual(translation_de.name, 'A new, better, updated name')self.assertEqual(translation_de.pk, 2)self.assertEqual(translation_de.alias_set.count(), 2)@@ -727,5 +727,5 @@ class TestSyncMethods(WgerTestCase):self.assertEqual(translation_de.exercisecomment_set.count(), 1)self.assertEqual(translation_de.exercisecomment_set.first().comment, 'Foobar')- translation_fr = base.get_translation('fr')+ translation_fr = exercise.get_translation('fr')self.assertEqual(str(translation_fr.uuid), '581338a1-8e52-405b-99eb-f0724c528bc8')diff --git a/wger/manager/api/serializers.py b/wger/manager/api/serializers.pyindex 9cc1ebb6c..b3029aaea 100644--- a/wger/manager/api/serializers.py+++ b/wger/manager/api/serializers.py@@ -31,7 +31,6 @@ from wger.manager.models import (ScheduleStep,Set,SetsConfig,- Setting,Slot,SlotConfig,WeightConfig,@@ -441,24 +440,3 @@ class SetSerializer(serializers.ModelSerializer):class Meta:model = Setfields = ['id', 'exerciseday', 'sets', 'order', 'comment']---class SettingSerializer(serializers.ModelSerializer):- """- Workout setting serializer- """-- class Meta:- model = Setting- fields = [- 'id',- 'set',- 'exercise_base',- 'repetition_unit',- 'reps',- 'weight',- 'weight_unit',- 'rir',- 'order',- 'comment',- ]diff --git a/wger/manager/api/views.py b/wger/manager/api/views.pyindex 24582f76b..d7c34ab10 100644--- a/wger/manager/api/views.py+++ b/wger/manager/api/views.py@@ -36,7 +36,6 @@ from wger.manager.api.serializers import (ScheduleSerializer,ScheduleStepSerializer,SetSerializer,- SettingSerializer,WorkoutDayDataDisplayModeSerializer,WorkoutDayDataGymModeSerializer,WorkoutLogSerializer,@@ -408,53 +407,6 @@ class SetViewSet(WgerOwnerObjectModelViewSet):"""return [(Day, 'exerciseday')]- @action(detail=True)- def computed_settings(self, request, pk):- """Returns the synthetic settings for this set"""-- out = SettingSerializer(self.get_object().compute_settings, many=True).data- return Response({'results': out})---class SettingViewSet(WgerOwnerObjectModelViewSet):- """- API endpoint for repetition setting objects- """-- serializer_class = SettingSerializer- is_private = True- ordering_fields = '__all__'- filterset_fields = (- 'exercise_base',- 'order',- 'reps',- 'weight',- 'set',- 'order',- )-- def get_queryset(self):- """- Only allow access to appropriate objects- """- # REST API generation- if getattr(self, 'swagger_fake_view', False):- return Setting.objects.none()-- return Setting.objects.filter(set__exerciseday__training__user=self.request.user)-- def perform_create(self, serializer):- """- Set the order- """- serializer.save(order=1)-- def get_owner_objects(self):- """- Return objects to check for ownership permission- """- return [(Set, 'set')]-class WorkoutLogViewSet(WgerOwnerObjectModelViewSet):"""diff --git a/wger/manager/management/commands/dummy-generator-routines.py b/wger/manager/management/commands/dummy-generator-routines.pynew file mode 100644index 000000000..e9a53b2be--- /dev/null+++ b/wger/manager/management/commands/dummy-generator-routines.py@@ -0,0 +1,150 @@+# This file is part of wger Workout Manager.+#+# wger Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# wger Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License++# Standard Library+import datetime+import logging+import random+import uuid++# Django+from django.contrib.auth.models import User+from django.core.management.base import BaseCommand++# wger+from wger.exercises.models import ExerciseBase+from wger.manager.models import (+ DayNg,+ RepsConfig,+ Routine,+ SetsConfig,+ Slot,+ SlotConfig,+ WeightConfig,+)+++logger = logging.getLogger(__name__)+++class Command(BaseCommand):+ """+ Dummy generator for routines+ """++ help = 'Dummy generator for routines'++ def add_arguments(self, parser):+ parser.add_argument(+ '--routines',+ action='store',+ default=10,+ dest='nr_plans',+ type=int,+ help='The number of routines to create per user (default: 10)',+ )+ parser.add_argument(+ '--user-id',+ action='store',+ dest='user_id',+ type=int,+ help='Add only to the specified user-ID (default: all users)',+ )++ def handle(self, **options):+ self.stdout.write(f"** Generating {options['nr_plans']} dummy routine(s) per user")++ users = (+ [User.objects.get(pk=options['user_id'])] if options['user_id'] else User.objects.all()+ )++ for user in users:+ self.stdout.write(f'- processing user {user.username}')++ # Add plan+ for _ in range(options['nr_plans']):+ uid = str(uuid.uuid4()).split('-')+ start_date = datetime.date.today() - datetime.timedelta(days=random.randint(0, 100))++ routine = Routine(+ user=user,+ name=f'Dummy routine - {uid[0]}',+ start=start_date,+ end=start_date + datetime.timedelta(weeks=6),+ )+ routine.save()++ # Select a random number of days and juggle them till they are all connected+ nr_of_days = random.randint(2, 5)++ day_list = []+ is_first_day = False+ for _ in range(nr_of_days):+ uid = str(uuid.uuid4()).split('-')+ day = DayNg(routine=routine, name=f'Dummy day - {uid[0]}')+ day.save()+ if is_first_day:+ routine.first_day = day+ routine.save()++ is_first_day = False+ day_list.append(day)++ next_day = None+ for day in reversed(day_list):+ if next_day:+ day.next_day = next_day+ day.save()+ next_day = day+ day_list[-1].next_day = day_list[0]+ day_list[-1].save()++ # Add exercises (no supersets, all very simple)+ exercise_list = [i for i in ExerciseBase.objects.all()]+ for day in day_list:+ nr_of_exercises = random.randint(3, 6)+ exercises = random.choices(exercise_list, k=nr_of_exercises)+ order = 1+ for exercise in exercises:+ slot = Slot(day=day, order=order)+ slot.save()+ order += 1++ slot_config = SlotConfig(exercise=exercise, order=order, slot=slot)+ slot_config.save()++ reps = random.choice([1, 3, 5, 8, 10, 12, 15])+ sets = random.randint(2, 4)+ weight = random.randint(20, 100)++ SetsConfig(+ slot_config=slot_config,+ value=sets,+ iteration=1,+ replace=True,+ ).save()++ RepsConfig(+ slot_config=slot_config,+ value=reps,+ iteration=1,+ replace=True,+ ).save()++ WeightConfig(+ slot_config=slot_config,+ value=weight,+ iteration=1,+ replace=True,+ ).save()diff --git a/wger/manager/management/commands/dummy-generator-workout-diary.py b/wger/manager/management/commands/dummy-generator-workout-diary.pyindex 836a9ba94..5e270a42a 100644--- a/wger/manager/management/commands/dummy-generator-workout-diary.py+++ b/wger/manager/management/commands/dummy-generator-workout-diary.py@@ -42,10 +42,10 @@ class Command(BaseCommand):parser.add_argument('--diary-entries',action='store',- default=30,+ default=5,dest='nr_diary_entries',type=int,- help='The number of workout logs to create per day (default: 30)',+ help='The number of workout logs to create per day (default: 5)',)parser.add_argument('--user-id',@@ -68,15 +68,15 @@ class Command(BaseCommand):# Create a log for each workout day, set, setting, reps, weight, datefor routine in Routine.objects.filter(user=user):- for day in routine.day_set.all():- for workout_set in day.set_set.all():- for setting in workout_set.setting_set.all():+ for day in routine.days.all():+ for slot in day.slots.all():+ for config in slot.configs.all():for reps in (8, 10, 12):for i in range(options['nr_diary_entries']):date = datetime.date.today() - datetime.timedelta(weeks=i)log = WorkoutLog(user=user,- exercise=setting.exercise_base,+ exercise=config.exercise,routine=routine,reps=reps,weight=50 - reps + random.randint(1, 10),diff --git a/wger/manager/management/commands/dummy-generator-workout-plans.py b/wger/manager/management/commands/dummy-generator-workout-plans.pydeleted file mode 100644index dee7dcf57..000000000--- a/wger/manager/management/commands/dummy-generator-workout-plans.py+++ /dev/null@@ -1,126 +0,0 @@-# This file is part of wger Workout Manager.-#-# wger Workout Manager is free software: you can redistribute it and/or modify-# it under the terms of the GNU Affero General Public License as published by-# the Free Software Foundation, either version 3 of the License, or-# (at your option) any later version.-#-# wger Workout Manager is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU Affero General Public License--# Standard Library-import datetime-import logging-import random-import uuid--# Django-from django.contrib.auth.models import User-from django.core.management.base import BaseCommand--# wger-from wger.core.models import DaysOfWeek-from wger.exercises.models import Exercise-from wger.manager.models import (- Day,- Set,- Setting,- Workout,-)---logger = logging.getLogger(__name__)---class Command(BaseCommand):- """- Dummy generator for workout plans- """-- help = 'Dummy generator for workout plans'-- def add_arguments(self, parser):- parser.add_argument(- '--plans',- action='store',- default=10,- dest='nr_plans',- type=int,- help='The number of workout plans to create per user (default: 10)',- )- parser.add_argument(- '--user-id',- action='store',- dest='user_id',- type=int,- help='Add only to the specified user-ID (default: all users)',- )-- def handle(self, **options):- self.stdout.write(f"** Generating {options['nr_plans']} dummy workout plan(s) per user")-- users = (- [User.objects.get(pk=options['user_id'])] if options['user_id'] else User.objects.all()- )-- for user in users:- self.stdout.write(f'- processing user {user.username}')-- # Add plan- for _ in range(options['nr_plans']):- uid = str(uuid.uuid4()).split('-')- start_date = datetime.date.today() - datetime.timedelta(days=random.randint(0, 100))- workout = Workout(- user=user,- name=f'Dummy workout - {uid[1]}',- creation_date=start_date,- )- workout.save()-- # Select a random number of workout days- nr_of_days = random.randint(1, 5)- day_list = [i for i in range(1, 8)]- random.shuffle(day_list)-- # Load all exercises to a list- exercise_list = [i for i in Exercise.objects.filter(language_id=2)]-- for day in day_list[0:nr_of_days]:- uid = str(uuid.uuid4()).split('-')- weekday = DaysOfWeek.objects.get(pk=day)-- day = Day(- training=workout,- description=f'Dummy day - {uid[0]}',- )- day.save()- day.day.add(weekday)-- # Select a random number of exercises- nr_of_exercises = random.randint(3, 10)- random.shuffle(exercise_list)- day_exercises = exercise_list[0:nr_of_exercises]- order = 1- for exercise in day_exercises:- reps = random.choice([1, 3, 5, 8, 10, 12, 15])- sets = random.randint(2, 4)-- day_set = Set(- exerciseday=day,- sets=sets,- order=order,- )- day_set.save()-- setting = Setting(- set=day_set,- exercise_base=exercise.exercise_base,- reps=reps,- order=order,- )- setting.save()- order += 1diff --git a/wger/manager/migrations/0021_flexible_routines_cleanup.py b/wger/manager/migrations/0021_flexible_routines_cleanup.pyindex 0c8d5e3f0..67dcf0559 100644--- a/wger/manager/migrations/0021_flexible_routines_cleanup.py+++ b/wger/manager/migrations/0021_flexible_routines_cleanup.py@@ -22,4 +22,16 @@ class Migration(migrations.Migration):old_name='exercise_base',new_name='exercise',),+ migrations.DeleteModel(+ name='Workout',+ ),+ migrations.DeleteModel(+ name='Day',+ ),+ migrations.DeleteModel(+ name='Setting',+ ),+ migrations.DeleteModel(+ name='Set',+ ),]diff --git a/wger/manager/tests/test_set.py b/wger/manager/tests/test_set.pydeleted file mode 100644index 6ae0bba84..000000000--- a/wger/manager/tests/test_set.py+++ /dev/null@@ -1,483 +0,0 @@-# This file is part of wger Workout Manager.-#-# wger Workout Manager is free software: you can redistribute it and/or modify-# it under the terms of the GNU Affero General Public License as published by-# the Free Software Foundation, either version 3 of the License, or-# (at your option) any later version.-#-# wger Workout Manager is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU Affero General Public License--# Standard Library-import logging-from decimal import Decimal-from typing import List-from unittest import skip--# Django-from django.core.cache import cache-from django.urls import (- reverse,- reverse_lazy,-)--# wger-from wger.core.tests import api_base_test-from wger.core.tests.base_testcase import (- STATUS_CODES_FAIL,- WgerAddTestCase,- WgerTestCase,-)-from wger.exercises.models import ExerciseBase-from wger.manager.models import (- Day,- Set,- Setting,-)-from wger.utils.cache import cache_mapper---logger = logging.getLogger(__name__)---class SetAddTestCase(WgerAddTestCase):- """- Test adding a set to a day- """-- object_class = Set- url = reverse_lazy('manager:set:add', kwargs={'day_pk': 5})- user_success = 'test'- user_fail = 'admin'- data = {- 'exercise_list': 1, # Only for mobile version- 'sets': 4,- 'exercise1-TOTAL_FORMS': 4,- 'exercise1-INITIAL_FORMS': 0,- 'exercise1-MAX_NUM_FORMS': 1000,- 'exercise1-0-reps': 10,- 'exercise1-0-repetition_unit': 1,- 'exercise1-0-weight_unit': 1,- 'exercise1-1-reps': 12,- 'exercise1-1-repetition_unit': 1,- 'exercise1-1-weight_unit': 1,- 'exercise1-2-reps': 10,- 'exercise1-2-repetition_unit': 1,- 'exercise1-2-weight_unit': 1,- 'exercise1-3-reps': 12,- 'exercise1-3-repetition_unit': 1,- 'exercise1-3-weight_unit': 1,- }- data_ignore = (- 'exercise1-TOTAL_FORMS',- 'exercise1-INITIAL_FORMS',- 'exercise1-MAX_NUM_FORMS',- 'exercise_list',- 'exercise1-0-reps',- 'exercise1-0-repetition_unit',- 'exercise1-0-weight_unit',- 'exercise1-1-reps',- 'exercise1-1-repetition_unit',- 'exercise1-1-weight_unit',- 'exercise1-2-reps',- 'exercise1-2-repetition_unit',- 'exercise1-2-weight_unit',- 'exercise1-3-reps',- 'exercise1-3-repetition_unit',- 'exercise1-3-weight_unit',- )-- def test_add_set(self, fail=False):- """- Tests adding a set and corresponding settings at the same time- """-- # POST the data- self.user_login('test')- base_ids = [1, 2]- post_data = {- 'exercise_list': 1, # Only for mobile version- 'sets': 4,- 'exercise1-TOTAL_FORMS': 4,- 'exercise1-INITIAL_FORMS': 0,- 'exercise1-MAX_NUM_FORMS': 1000,- 'exercise1-0-reps': 10,- 'exercise1-0-repetition_unit': 1,- 'exercise1-0-weight_unit': 1,- 'exercise1-1-reps': 12,- 'exercise1-1-repetition_unit': 1,- 'exercise1-1-weight_unit': 1,- 'exercise1-2-reps': 10,- 'exercise1-2-repetition_unit': 1,- 'exercise1-2-weight_unit': 1,- 'exercise1-3-reps': 12,- 'exercise1-3-repetition_unit': 1,- 'exercise1-3-weight_unit': 1,- 'exercise2-TOTAL_FORMS': 4,- 'exercise2-INITIAL_FORMS': 0,- 'exercise2-MAX_NUM_FORMS': 1000,- 'exercise2-0-reps': 8,- 'exercise2-0-repetition_unit': 1,- 'exercise2-0-weight_unit': 1,- 'exercise2-1-reps': 10,- 'exercise2-1-repetition_unit': 2,- 'exercise2-1-weight_unit': 2,- 'exercise2-2-reps': 8,- 'exercise2-2-repetition_unit': 1,- 'exercise2-2-weight_unit': 1,- 'exercise2-3-reps': 10,- 'exercise2-3-repetition_unit': 2,- 'exercise2-3-weight_unit': 2,- }- response = self.client.post(reverse('manager:set:add', kwargs={'day_pk': 5}), post_data)- self.assertEqual(response.status_code, 302)-- set_obj = Set.objects.get(pk=Set.objects.latest('id').id)- base1 = ExerciseBase.objects.get(pk=1)-- # Check that everything got where it's supposed to- for bases in set_obj.exercise_bases:- self.assertIn(bases.id, base_ids)-- settings = Setting.objects.filter(set=set_obj)- for setting in settings:- if setting.exercise_base == base1:- self.assertIn(setting.reps, (10, 12))- else:- self.assertIn(setting.reps, (8, 10))---class SetDeleteTestCase(WgerTestCase):- """- Tests deleting a set from a workout- """-- def delete_set(self, fail=True):- """- Helper function to test deleting a set from a workout- """-- # Fetch the overview page- count_before = Set.objects.count()- response = self.client.get(reverse('manager:set:delete', kwargs={'pk': 3}))- count_after = Set.objects.count()-- if fail:- self.assertIn(response.status_code, (302, 403))- self.assertEqual(count_before, count_after)- else:- self.assertEqual(response.status_code, 302)- self.assertEqual(count_before - 1, count_after)- self.assertRaises(Set.DoesNotExist, Set.objects.get, pk=3)-- def test_delete_set_anonymous(self):- """- Tests deleting a set from a workout as an anonymous user- """-- self.delete_set(fail=True)-- def test_delete_set_owner(self):- """- Tests deleting a set from a workout as the owner user- """-- self.user_login('admin')- self.delete_set(fail=True)-- def test_delete_set_other(self):- """- Tests deleting a set from a workout as a logged user not owning the data- """-- self.user_login('test')- self.delete_set(fail=False)---class TestSetOrderTestCase(WgerTestCase):- """- Tests that the order of the (existing) sets in a workout is preservead- when adding new ones- """-- def add_set(self, exercises_id):- """- Helper function that adds a set to a day- """- nr_sets = 4- post_data = {- 'exercises': exercises_id,- 'exercise_list': exercises_id[0], # Only for mobile version,- 'sets': nr_sets,- }- for exercise_id in exercises_id:- post_data[f'exercise{exercise_id}-TOTAL_FORMS'] = nr_sets- post_data[f'exercise{exercise_id}-INITIAL_FORMS'] = 0- post_data[f'exercise{exercise_id}-MAX_NUM_FORMS'] = 1000- for set_nr in range(0, nr_sets):- post_data[f'exercise{exercise_id}-{set_nr}-repetition_unit'] = 1- post_data[f'exercise{exercise_id}-{set_nr}-weight_unit'] = 1- post_data[f'exercise{exercise_id}-{set_nr}-reps'] = 8-- response = self.client.post(reverse('manager:set:add', kwargs={'day_pk': 5}), post_data)-- return response-- def get_order(self):- """- Helper function that reads the order of the the sets in a day- """-- day = Day.objects.get(pk=5)- order = ()-- for day_set in day.set_set.select_related():- order += (day_set.id,)-- return order-- @skip('Fix later')- def test_set_order(self, logged_in=False):- """- Helper function that add some sets and checks the order- """- self.user_login('test')- orig = self.get_order()- exercises = (1, 2, 3, 81, 84, 91, 111)-- for i in range(0, 7):- self.add_set([exercises[i]])- prev = self.get_order()- orig += (i + 4,)- self.assertEqual(orig, prev)---class TestSetAddFormset(WgerTestCase):- """- Tests the functionality of the formset mini-view that is used in the add- set page- """-- def get_formset(self):- """- Helper function- """- exercise = ExerciseBase.objects.get(pk=1)- response = self.client.get(- reverse('manager:set:get-formset', kwargs={'base_pk': 1, 'reps': 4})- )-- self.assertEqual(response.status_code, 200)- self.assertEqual(response.context['exercise'], exercise)- self.assertTrue(response.context['formset'])-- def test_get_formset_logged_in(self):- """- Tests the formset view as an authorized user- """-- self.user_login('test')- self.get_formset()---class SetEditEditTestCase(WgerTestCase):- """- Tests editing a set- """-- def edit_set(self, fail=False):- """- Helper function- """-- # Fetch the edit page- response = self.client.get(reverse('manager:set:edit', kwargs={'pk': 3}))- entry_before = Set.objects.get(pk=3)-- if fail:- self.assertIn(response.status_code, STATUS_CODES_FAIL)- else:- self.assertEqual(response.status_code, 200)-- # Try to edit the object- response = self.client.post(- reverse('manager:set:edit', kwargs={'pk': 3}),- {- 'exercise2-TOTAL_FORMS': 1,- 'exercise2-INITIAL_FORMS': 1,- 'exercise2-MAX_NUM_FORMS': 1,- 'exercise2-MIN_NUM_FORMS': 1,- 'exercise2-0-reps': 5,- 'exercise2-0-id': 3,- 'exercise2-0-repetition_unit': 2,- 'exercise2-0-weight_unit': 3,- 'exercise2-0-rir': '1.5',- },- )-- entry_after = Set.objects.get(pk=3)-- # Check the results- if fail:- self.assertIn(response.status_code, STATUS_CODES_FAIL)- self.assertEqual(entry_before, entry_after)-- else:- self.assertEqual(response.status_code, 302)-- # The page we are redirected to doesn't trigger an error- response = self.client.get(response['Location'])- self.assertEqual(response.status_code, 200)-- # Setting was updated- setting = Setting.objects.get(pk=3)- self.assertEqual(setting.reps, 5)- self.assertEqual(setting.repetition_unit_id, 2)- self.assertEqual(setting.weight_unit_id, 3)- self.assertEqual(setting.rir, '1.5')-- self.post_test_hook()-- def test_edit_set_authorized(self):- """- Tests editing the object as an authorized user- """-- self.user_login('admin')- self.edit_set(fail=True)-- def test_edit_set_other(self):- """- Tests editing the object as an unauthorized, logged in user- """-- self.user_login('test')- self.edit_set(fail=False)---class SetSmartReprTestCase(WgerTestCase):- """Tests the "smart text representation" for sets"""-- def test_smart_repr_one_setting(self):- """- Tests the representation with one setting- """- set_obj = Set.objects.get(pk=1)-- setting_text = set_obj.reps_smart_text(set_obj.exercise_bases[0])- self.assertEqual(setting_text, '2 × 8 (3 RiR)')-- def test_smart_repr_custom_setting(self):- """- Tests the representation with several settings- """- set_obj = Set(exerciseday_id=1, order=1, sets=4)- set_obj.save()- setting1 = Setting(- set=set_obj,- exercise_base_id=1,- repetition_unit_id=1,- reps=8,- weight=Decimal(90),- weight_unit_id=1,- rir='3',- order=1,- )- setting1.save()- setting2 = Setting(- set=set_obj,- exercise_base_id=1,- repetition_unit_id=1,- reps=10,- weight=Decimal(80),- weight_unit_id=1,- rir='2.5',- order=2,- )- setting2.save()- setting3 = Setting(- set=set_obj,- exercise_base_id=1,- repetition_unit_id=1,- reps=10,- weight=Decimal(80),- weight_unit_id=1,- rir='2',- order=3,- )- setting3.save()- setting4 = Setting(- set=set_obj,- exercise_base_id=1,- repetition_unit_id=1,- reps=12,- weight=Decimal(80),- weight_unit_id=1,- rir='1',- order=4,- )- setting4.save()-- setting_text = set_obj.reps_smart_text(ExerciseBase.objects.get(pk=1))- self.assertEqual(- setting_text,- '8 (90 kg, 3 RiR) – 10 (80 kg, 2.5 RiR) – ' '10 (80 kg, 2 RiR) – 12 (80 kg, 1 RiR)',- )-- def test_synthetic_settings(self):- set_obj = Set(exerciseday_id=1, order=1, sets=4)- set_obj.save()- setting1 = Setting(- set=set_obj,- exercise_base_id=1,- repetition_unit_id=1,- reps=8,- weight=Decimal(90),- weight_unit_id=1,- rir='3',- order=1,- )- setting1.save()- setting2 = Setting(- set=set_obj,- exercise_base_id=3,- repetition_unit_id=1,- reps=10,- weight=Decimal(80),- weight_unit_id=1,- rir='2.5',- order=2,- )- setting2.save()- settings: List[Setting] = set_obj.compute_settings-- # Check that there are 2 x 4 entries (2 Exercises x 4 Sets)- self.assertEqual(len(settings), 8)-- # Check interleaved settings- for i in range(0, len(settings)):- if (i % 2) == 0:- self.assertEqual(settings[i].exercise_base_id, 1)- self.assertEqual(settings[i].reps, 8)- self.assertEqual(settings[i].weight, Decimal(90))- self.assertEqual(settings[i].rir, '3')- else:- self.assertEqual(settings[i].exercise_base_id, 3)- self.assertEqual(settings[i].reps, 10)- self.assertEqual(settings[i].weight, Decimal(80))- self.assertEqual(settings[i].rir, '2.5')---class SetApiTestCase(api_base_test.ApiBaseResourceTestCase):- """- Tests the set overview resource- """-- pk = 3- resource = Set- private_resource = True- data = {'exerciseday': 5, 'sets': 4}diff --git a/wger/manager/urls.py b/wger/manager/urls.pyindex bba566601..936e60a3b 100644--- a/wger/manager/urls.py+++ b/wger/manager/urls.py@@ -196,6 +196,21 @@ patterns_workout = [),]+# sub patterns for workouts+patterns_routine = [+ path(+ 'overview',+ ReactView.as_view(login_required=True),+ name='overview',+ ),+ path(+ '<int:pk>/view',+ # ReactView.as_view(login_required=True),+ workout.view,+ name='view',+ ),+]+# sub patterns for workout sessionspatterns_session = [re_path(@@ -373,6 +388,7 @@ patterns_step = [urlpatterns = [path('', include((patterns_workout, 'workout'), namespace='workout')),+ path('routine/', include((patterns_routine, 'routine'), namespace='routine')),path('template/', include((patterns_templates, 'template'), namespace='template')),path('log/', include((patterns_log, 'log'), namespace='log')),path('day/', include((patterns_day, 'day'), namespace='day')),diff --git a/wger/urls.py b/wger/urls.pyindex 3fcc7d1bd..2ee0b83dd 100644--- a/wger/urls.py+++ b/wger/urls.py@@ -65,7 +65,6 @@ router = routers.DefaultRouter()# Manager approuter.register(r'day', manager_api_views.DayViewSet, basename='day')router.register(r'set', manager_api_views.SetViewSet, basename='Set')-router.register(r'setting', manager_api_views.SettingViewSet, basename='Setting')router.register(r'workout', manager_api_views.WorkoutViewSet, basename='workout')router.register(r'routine', manager_api_views.RoutineViewSet, basename='routine')router.register(r'templates', manager_api_views.UserWorkoutTemplateViewSet, basename='templates')diff --git a/wger/utils/constants.py b/wger/utils/constants.pyindex 1a24c0a13..25294bf2f 100644--- a/wger/utils/constants.py+++ b/wger/utils/constants.py@@ -69,3 +69,10 @@ DOWNLOAD_INGREDIENT_OPTIONS = (# APIAPI_MAX_ITEMS = 999++# Known exercises+UUID_SQUATS = 'a2f5b6ef-b780-49c0-8d96-fdaff23e27ce'+UUID_CURLS = '1ae6a28d-10e7-4ecf-af4f-905f8193e2c6'+UUID_FRENCH_PRESS = '95a7e546-e8f8-4521-a76b-983d94161b25'+UUID_CRUNCHES = 'b186f1f8-4957-44dc-bf30-d0b00064ce6f'+UUID_LEG_RAISES = 'c2078aac-e4e2-4103-a845-6252a3eb795e'