Self hosted FLOSS fitness/workout, nutrition and weight tracker
Remove name_original from the exercise model
Roland Geider330c4973d680
diff --git a/wger/exercises/fixtures/test-exercises.json b/wger/exercises/fixtures/test-exercises.jsonindex 31d74eb42..e5dbc5563 100644--- a/wger/exercises/fixtures/test-exercises.json+++ b/wger/exercises/fixtures/test-exercises.json@@ -94,6 +94,8 @@"uuid": "acad394936fb44819a72be2ddae2bc05","category": 2,"status": "2",+ "creation_date": "2020-01-10",+ "update_date": "2020-11-01T22:10:00+01:00","muscles": [1,2@@ -111,6 +113,8 @@"uuid": "029a6eac67f242d9b71d9d692b0a35b0","category": 2,"status": "2",+ "creation_date": "2014-11-01",+ "update_date": "2018-11-01T00:00:00+01:00","muscles": [2],@@ -128,6 +132,8 @@"uuid": "c2dc11e9b14a49cb9d11d1b9441f16f4","category": 3,"status": "2",+ "creation_date": "2020-01-10",+ "update_date": "2020-11-01T22:10:00+01:00","muscles": [1],@@ -141,6 +147,8 @@"uuid": "9838235ce38f4ca6921e9d237d8e0813","category": 3,"status": "2",+ "creation_date": "2022-01-10",+ "update_date": "2022-02-02T06:45:11+01:00","muscles": [1],@@ -155,6 +163,8 @@"uuid": "e9e35f0c45b14d64b00db707a94c6fb8","category": 1,"status": "2",+ "creation_date": "2002-08-15",+ "update_date": "2008-08-08T08:08:08+01:00","muscles": [],"variations": null}@@ -168,7 +178,9 @@"language": 1,"exercise_base": 1,"description": "",- "name": "An exercise"+ "name": "An exercise",+ "creation_date": "2002-08-15",+ "update_date": "2008-08-08T08:08:08+01:00"}},{@@ -180,7 +192,9 @@"language": 2,"exercise_base": 2,"description": "",- "name": "Very cool exercise"+ "name": "Very cool exercise",+ "creation_date": "2022-01-10",+ "update_date": "2022-02-02T06:45:11+01:00"}},{@@ -192,7 +206,9 @@"language": 1,"exercise_base": 3,"description": "",- "name": "Boring exercise"+ "name": "Boring exercise",+ "creation_date": "2022-01-10",+ "update_date": "2022-02-02T06:45:11+01:00"}},{@@ -205,7 +221,9 @@"description": "","exercise_base": 3,"license_author": "test",- "name": "Pending exercise"+ "name": "Pending exercise",+ "creation_date": "2022-01-10",+ "update_date": "2022-02-02T06:45:11+01:00"}},{@@ -217,7 +235,9 @@"language": 1,"exercise_base": 4,"description": "",- "name": "Needed for demo user"+ "name": "Needed for demo user",+ "creation_date": "2022-01-10",+ "update_date": "2022-02-02T06:45:11+01:00"}},{@@ -229,7 +249,9 @@"language": 1,"exercise_base": 4,"description": "",- "name": "Needed for demo user"+ "name": "Needed for demo user",+ "creation_date": "2022-01-10",+ "update_date": "2022-02-02T06:45:11+01:00"}},{@@ -241,7 +263,9 @@"language": 2,"exercise_base": 4,"description": "",- "name": "Needed for demo user"+ "name": "Needed for demo user",+ "creation_date": "2022-01-10",+ "update_date": "2022-02-02T06:45:11+01:00"}},{@@ -253,7 +277,9 @@"language": 2,"exercise_base": 4,"description": "",- "name": "Needed for demo user"+ "name": "Needed for demo user",+ "creation_date": "2022-01-10",+ "update_date": "2022-02-02T06:45:11+01:00"}},{@@ -265,7 +291,9 @@"language": 2,"exercise_base": 4,"description": "",- "name": "Needed for demo user"+ "name": "Needed for demo user",+ "creation_date": "2022-01-10",+ "update_date": "2022-02-02T06:45:11+01:00"}},{@@ -277,7 +305,9 @@"language": 2,"exercise_base": 4,"description": "",- "name": "Needed for demo user"+ "name": "Needed for demo user",+ "creation_date": "2022-01-10",+ "update_date": "2022-02-02T06:45:11+01:00"}},{diff --git a/wger/exercises/management/commands/redo-capitalize-names.py b/wger/exercises/management/commands/redo-capitalize-names.pydeleted file mode 100644index 6dd83467f..000000000--- a/wger/exercises/management/commands/redo-capitalize-names.py+++ /dev/null@@ -1,46 +0,0 @@-# -*- coding: utf-8 *-*--# 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--# Django-from django.core.management.base import BaseCommand--# wger-from wger.exercises.models import Exercise-from wger.utils.helpers import smart_capitalize---class Command(BaseCommand):- """- Re-calculates the capitalized exercise names-- This is a safe operation, since the original names (as entered by the user)- are still available.- """-- help = 'Re-calculates the capitalized exercise names'-- def handle(self, **options):-- exercises = Exercise.objects.all()- for exercise in exercises:- if options['verbosity'] > 1:- self.stdout.write(- '#{} {} -> {}'.format(- exercise.id, exercise.name, smart_capitalize(exercise.name_original)- )- )- exercise.name = smart_capitalize(exercise.name_original)- exercise.save()diff --git a/wger/exercises/models/exercise.py b/wger/exercises/models/exercise.pyindex f1aff0940..6a652636b 100644--- a/wger/exercises/models/exercise.py+++ b/wger/exercises/models/exercise.py@@ -42,7 +42,6 @@ from wger.utils.cache import (delete_template_fragment_cache,reset_workout_canonical_form,)-from wger.utils.helpers import smart_capitalizefrom wger.utils.managers import SubmissionManagerfrom wger.utils.models import (AbstractLicenseModel,@@ -66,14 +65,7 @@ class Exercise(AbstractSubmissionModel, AbstractLicenseModel, models.Model):"""Description on how to perform the exercise"""name = models.CharField(max_length=200, verbose_name=_('Name'))- """The exercise's name, with correct uppercase"""-- name_original = models.CharField(- max_length=200,- verbose_name=_('Name'),- default='',- )- """The exercise's name, as entered by the user"""+ """The exercise's name"""creation_date = models.DateField(_('Date'),@@ -83,6 +75,12 @@ class Exercise(AbstractSubmissionModel, AbstractLicenseModel, models.Model):)"""The submission date"""+ update_date = models.DateTimeField(+ _('Date'),+ auto_now=True+ )+ """Datetime of the last modification"""+language = models.ForeignKey(Language,verbose_name=_('Language'),@@ -129,7 +127,6 @@ class Exercise(AbstractSubmissionModel, AbstractLicenseModel, models.Model):"""Reset all cached infos"""- self.name = smart_capitalize(self.name_original)super(Exercise, self).save(*args, **kwargs)# Cached template fragments@@ -270,7 +267,7 @@ class Exercise(AbstractSubmissionModel, AbstractLicenseModel, models.Model):subject = _('New user submitted exercise')message = _('The user {0} submitted a new exercise "{1}".'- ).format(request.user.username, self.name_original)+ ).format(request.user.username, self.name)mail.mail_admins(str(subject),str(message),diff --git a/wger/exercises/tests/test_exercise.py b/wger/exercises/tests/test_exercise.pyindex 4a54ab4bd..fcaa6e0de 100644--- a/wger/exercises/tests/test_exercise.py+++ b/wger/exercises/tests/test_exercise.py@@ -246,7 +246,7 @@ class ExercisesTestCase(WgerTestCase):count_before = Exercise.objects.count()response = self.client.post(reverse('exercise:exercise:add'), {- 'name_original': random_string(),+ 'name': random_string(),'license': 1,'exercise_base': {'category': 2,@@ -286,7 +286,7 @@ class ExercisesTestCase(WgerTestCase):response = self.client.post(reverse('exercise:exercise:add'), {'category': 2,- 'name_original': 'Squats',+ 'name': 'Squats','license': 1,'muscles': [1, 2]}@@ -305,10 +305,10 @@ class ExercisesTestCase(WgerTestCase):# Add an exercisecount_before = Exercise.objects.count()description = 'a nice, long and accurate description for the exercise'- name_original = random_string()+ name = random_string()response = self.client.post(reverse('exercise:exercise:add'), {- 'name_original': name_original,+ 'name': name,'license': 1,'description': description,'category': 2,@@ -339,13 +339,13 @@ class ExercisesTestCase(WgerTestCase):self.assertEqual(response.context['active_tab'], WORKOUT_TAB)exercise_1 = Exercise.objects.get(pk=exercise_id)- self.assertEqual(exercise_1.name, name_original)+ self.assertEqual(exercise_1.name, name)# Wrong category - addingresponse = self.client.post(reverse('exercise:exercise:add'), {'category': 111,- 'name_original': random_string(),+ 'name': random_string(),'license': 1,'category': 111,'muscles': [1, 2]@@ -357,7 +357,7 @@ class ExercisesTestCase(WgerTestCase):response = self.client.post(reverse('exercise:exercise:edit', kwargs={'pk': '1'}), {'category': 111,- 'name_original': random_string(),+ 'name': random_string(),'license': 1,'category': 111,'muscles': [1, 2]@@ -372,7 +372,7 @@ class ExercisesTestCase(WgerTestCase):response = self.client.post(reverse('exercise:exercise:add'), {'category': 1,- 'name_original': random_string(),+ 'name': random_string(),'license': 1,'category': 1,'muscles': []@@ -384,7 +384,7 @@ class ExercisesTestCase(WgerTestCase):response = self.client.post(reverse('exercise:exercise:edit', kwargs={'pk': '1'}), {'category': 1,- 'name_original': random_string(),+ 'name': random_string(),'license': 1,'category': 1,'muscles': []diff --git a/wger/exercises/views/exercises.py b/wger/exercises/views/exercises.pyindex 0046b81e9..7032ffadc 100644--- a/wger/exercises/views/exercises.py+++ b/wger/exercises/views/exercises.py@@ -196,7 +196,7 @@ class ExerciseForm(ModelForm):model = Exercisewidgets = {'equipment': TranslatedSelectMultiple()}fields = [- 'name_original',+ 'name','category','description','muscles',@@ -209,12 +209,12 @@ class ExerciseForm(ModelForm):class Media:js = (settings.STATIC_URL + 'yarn/tinymce/tinymce.min.js', )- def clean_name_original(self):+ def clean_name(self):"""Throws a validation error if the newly submitted name is too similar toan existing exercise's name"""- name_original = self.cleaned_data['name_original']+ name = self.cleaned_data['name']if not self.instance.id:language = load_language()@@ -222,19 +222,19 @@ class ExerciseForm(ModelForm):.filter(language=language)for exercise in exercises:exercise_name = str(exercise)- min_edit_dist = levenshtein(exercise_name.casefold(), name_original.casefold())+ min_edit_dist = levenshtein(exercise_name.casefold(), name.casefold())if min_edit_dist < MIN_EDIT_DISTANCE_THRESHOLD:raise ValidationError(_(- '%(name_original)s is too similar to existing exercise '+ '%(name)s is too similar to existing exercise ''"%(exercise_name)s"'),params={- 'name_original': name_original,+ 'name': name,'exercise_name': exercise_name},)- return name_original+ return nameclass ExercisesEditAddView(WgerFormMixin):@@ -261,7 +261,7 @@ class ExercisesEditAddView(WgerFormMixin):form.fields['muscles_secondary'].initial = \exercise.exercise_base.muscles_secondary.all()form.helper.layout = Layout(- "name_original",+ "name","description","category","equipment",@@ -417,7 +417,7 @@ class ExerciseDeleteView("""model = Exercise- fields = ('description', 'name_original')+ fields = ('description', 'name')success_url = reverse_lazy('exercise:exercise:overview')delete_message_extra = gettext_lazy('This will delete the exercise from all workouts.')messages = gettext_lazy('Successfully deleted')diff --git a/wger/urls.py b/wger/urls.pyindex 481036167..002157cc2 100644--- a/wger/urls.py+++ b/wger/urls.py@@ -103,6 +103,11 @@ router.register(exercises_api_views.ExerciseViewSet,basename='exercise',)+router.register(+ r'exercise-translation',+ exercises_api_views.ExerciseTranslationViewSet,+ basename='exercise-translation',+)router.register(r'exercise-base',exercises_api_views.ExerciseBaseViewSet,@@ -118,7 +123,10 @@ router.register(exercises_api_views.ExerciseCategoryViewSet,basename='exercisecategory',)-router.register(r'video', exercises_api_views.ExerciseVideoViewSet, basename='video')+router.register(r'video',+ exercises_api_views.ExerciseVideoViewSet,+ basename='video',+)router.register(r'exerciseimage',exercises_api_views.ExerciseImageViewSet,diff --git a/wger/utils/helpers.py b/wger/utils/helpers.pyindex 763e300f5..6a02e6a2e 100644--- a/wger/utils/helpers.py+++ b/wger/utils/helpers.py@@ -218,28 +218,6 @@ def normalize_decimal(d):return normalized-def smart_capitalize(input):- """- A "smart" capitalizer-- This is used to capitalize e.g. exercise names. This is different than python's- capitalize and the similar django template tag mainly because of side effects- when applied to all caps words. E.g. the German "KH" (Kurzhantel) is capitalized- to "Kh" or "ß" to "SS". Because of this, only words with more than 2 letters as- well as the ones starting with "ß" are ignored.-- :param input: the input string- :return: the capitalized string- """- out = []- for word in input.split(' '):- if len(word) > 2 and word[0] != 'ß':- out.append(word[:1].upper() + word[1:])- else:- out.append(word)- return ' '.join(out)--def levenshtein(s1, s2):"""The Levenshtein distancediff --git a/wger/utils/tests/test_capitalizer.py b/wger/utils/tests/test_capitalizer.pydeleted file mode 100644index 255e2127e..000000000--- a/wger/utils/tests/test_capitalizer.py+++ /dev/null@@ -1,35 +0,0 @@-# -*- coding: utf-8 *-*--# 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--# wger-from wger.core.tests.base_testcase import WgerTestCase-from wger.utils.helpers import smart_capitalize---class CapitalizerTestCase(WgerTestCase):- """- Tests the "intelligent" capitalizer- """-- def test_capitalizer(self):- """- Tests different combinations of input strings- """- self.assertEqual(smart_capitalize("some long words"), "Some Long Words")- self.assertEqual(smart_capitalize("Here a short one"), "Here a Short One")- self.assertEqual(smart_capitalize("meine gym AG"), "Meine Gym AG")- self.assertEqual(smart_capitalize("ßpecial case"), "ßpecial Case")- self.assertEqual(smart_capitalize("fIRST lettER only"), "FIRST LettER Only")