Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Rename get_exercise

Roland Geider2726ce25aa03
diff --git a/wger/exercises/models/base.py b/wger/exercises/models/base.py
index a38cf5d17..5e87c6055 100644
--- a/wger/exercises/models/base.py
+++ b/wger/exercises/models/base.py
@@ -13,6 +13,7 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
# Standard Library
import datetime
import uuid
@@ -131,7 +132,7 @@ class ExerciseBase(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
"""
Return a more human-readable representation
"""
- return f"base {self.uuid} ({self.get_exercise().name})"
+ return f"base {self.uuid} ({self.get_translation()})"
def get_absolute_url(self):
"""
@@ -179,7 +180,8 @@ class ExerciseBase(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
The latest update datetime of all exercises, videos and images.
"""
return max(
- self.last_update, *[image.last_update for image in self.exerciseimage_set.all()],
+ self.last_update,
+ *[image.last_update for image in self.exerciseimage_set.all()],
*[video.last_update for video in self.exercisevideo_set.all()],
*[translation.last_update for translation in self.exercises.all()],
datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc)
@@ -208,7 +210,7 @@ class ExerciseBase(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
return []
return self.variations.exercisebase_set.filter(~Q(id=self.id))
- def get_exercise(self, language: Optional[str] = None):
+ def get_translation(self, language: Optional[str] = None):
"""
Returns the exercise for the given language. If the language is not
available, return the English translation.
@@ -251,7 +253,7 @@ class ExerciseBase(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
log = DeletionLog(
model_type=DeletionLog.MODEL_BASE,
uuid=self.uuid,
- comment=f"Exercise base of {self.get_exercise(ENGLISH_SHORT_NAME)}",
+ comment=f"Exercise base of {self.get_translation(ENGLISH_SHORT_NAME)}",
replaced_by=replace_by,
)
log.save()
diff --git a/wger/exercises/sync.py b/wger/exercises/sync.py
index 0a2ff3777..7174a8592 100644
--- a/wger/exercises/sync.py
+++ b/wger/exercises/sync.py
@@ -130,6 +130,7 @@ def sync_exercises(
Alias.objects.filter(exercise=translation).delete()
for alias in translation_data['aliases']:
+ print(alias)
Alias.objects.get_or_create(exercise=translation, alias=alias['alias'])
print_fn('')
diff --git a/wger/exercises/tests/test_exercise_base.py b/wger/exercises/tests/test_exercise_base.py
index ab42a7507..caa4a964a 100644
--- a/wger/exercises/tests/test_exercise_base.py
+++ b/wger/exercises/tests/test_exercise_base.py
@@ -57,7 +57,7 @@ class ExerciseBaseTestCase(WgerTestCase):
"""
Test that the base correctly returns translated exercises
"""
- exercise = ExerciseBase.objects.get(pk=1).get_exercise('de')
+ exercise = ExerciseBase.objects.get(pk=1).get_translation('de')
self.assertEqual(exercise.name, 'An exercise')
def test_language_utils_no_translation_exists(self):
@@ -65,7 +65,7 @@ class ExerciseBaseTestCase(WgerTestCase):
Test that the base correctly returns the English translation if the
requested language does not exist
"""
- exercise = ExerciseBase.objects.get(pk=1).get_exercise('fr')
+ exercise = ExerciseBase.objects.get(pk=1).get_translation('fr')
self.assertEqual(exercise.name, 'Test exercise 123')
def test_language_utils_no_translation_fallback(self):
@@ -73,7 +73,7 @@ class ExerciseBaseTestCase(WgerTestCase):
Test that the base correctly returns the first translation if for whatever
reason English is not available
"""
- exercise = ExerciseBase.objects.get(pk=2).get_exercise('pt')
+ exercise = ExerciseBase.objects.get(pk=2).get_translation('pt')
self.assertEqual(exercise.name, 'Very cool exercise')
diff --git a/wger/exercises/tests/test_exercise_base_model.py b/wger/exercises/tests/test_exercise_base_model.py
index 82b081b55..d7a88d563 100644
--- a/wger/exercises/tests/test_exercise_base_model.py
+++ b/wger/exercises/tests/test_exercise_base_model.py
@@ -75,15 +75,15 @@ class ExerciseBaseModelTestCase(WgerTestCase):
)
def test_exercise_en(self):
- translation = self.exercise.get_exercise()
+ translation = self.exercise.get_translation()
self.assertEqual(translation.language.short_name, 'en')
def test_get_exercise_fr(self):
- translation = self.exercise.get_exercise('fr')
+ translation = self.exercise.get_translation('fr')
self.assertEqual(translation.language.short_name, 'fr')
def test_get_exercise_unknown(self):
- translation = self.exercise.get_exercise('kg')
+ translation = self.exercise.get_translation('kg')
self.assertEqual(translation.language.short_name, 'en')
def test_get_languages(self):
diff --git a/wger/exercises/tests/test_sync.py b/wger/exercises/tests/test_sync.py
index 0ead61e82..f950470d6 100644
--- a/wger/exercises/tests/test_sync.py
+++ b/wger/exercises/tests/test_sync.py
@@ -689,7 +689,7 @@ class TestSyncMethods(WgerTestCase):
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])
- translation_de = new_base.get_exercise('de')
+ translation_de = new_base.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!')
@@ -699,7 +699,7 @@ class TestSyncMethods(WgerTestCase):
'Wichtig die Übung richtig zu machen',
)
- translation_en = new_base.get_exercise('en')
+ translation_en = new_base.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')
@@ -708,15 +708,15 @@ class TestSyncMethods(WgerTestCase):
base = ExerciseBase.objects.get(uuid='ae3328ba-9a35-4731-bc23-5da50720c5aa')
self.assertEqual(base.category_id, 3)
- translation_de = base.get_exercise('de')
+ translation_de = base.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)
- self.assertEqual(translation_de.alias_set.all()[0].alias, 'yet another name')
- self.assertEqual(translation_de.alias_set.all()[1].alias, 'A new alias here')
+ self.assertEqual(translation_de.alias_set.all()[0].alias, 'A new alias here')
+ self.assertEqual(translation_de.alias_set.all()[1].alias, 'yet another name')
self.assertEqual(translation_de.exercisecomment_set.count(), 1)
self.assertEqual(translation_de.exercisecomment_set.first().comment, 'Foobar')
- translation_fr = base.get_exercise('fr')
+ translation_fr = base.get_translation('fr')
self.assertEqual(str(translation_fr.uuid), '581338a1-8e52-405b-99eb-f0724c528bc8')
diff --git a/wger/manager/helpers.py b/wger/manager/helpers.py
index 79bc32981..5a7481cec 100644
--- a/wger/manager/helpers.py
+++ b/wger/manager/helpers.py
@@ -93,7 +93,7 @@ def render_workout_day(day, nr_of_weeks=7, images=False, comments=False, only_ta
# Exercises
for base in set_obj.exercise_bases:
- exercise = base.get_exercise()
+ exercise = base.get_translation()
group_exercise_marker[set_obj.id]['end'] = len(data)
# Process the settings
diff --git a/wger/manager/templates/set/formset.html b/wger/manager/templates/set/formset.html
index 47cb26702..e78bfb05d 100644
--- a/wger/manager/templates/set/formset.html
+++ b/wger/manager/templates/set/formset.html
@@ -1,7 +1,7 @@
{% load wger_extras crispy_forms_tags i18n %}
-<div id="formset-base-{{base.id}}" class="mt-3">
+<div id="formset-base-{{ base.id }}" class="mt-3">
<label class="control-label fw-bold">
- {{base.get_exercise.name}}
+ {{ base.get_translation.name }}
</label>
{{ formset.management_form }}
diff --git a/wger/manager/views/ical.py b/wger/manager/views/ical.py
index 6a4be31aa..0ef81804b 100644
--- a/wger/manager/views/ical.py
+++ b/wger/manager/views/ical.py
@@ -44,7 +44,6 @@ from wger.utils.helpers import (
next_weekday,
)
-
logger = logging.getLogger(__name__)
"""
Exports workouts and schedules as an iCal file that can be imported to a
@@ -96,7 +95,7 @@ def get_events_workout(calendar, workout, duration, start_date=None):
description_list = []
for set_obj in day.set_set.all():
for base in set_obj.exercise_bases:
- description_list.append(str(base.get_exercise()))
+ description_list.append(str(base.get_translation()))
description = ', '.join(description_list) if description_list else day.description
# Make an event for each weekday