Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add author history to all exercise related models

Tom Bowyer18ed72cabadf
diff --git a/wger/core/tests/api_base_test.py b/wger/core/tests/api_base_test.py
index d278bcd83..bf06a9651 100644
--- a/wger/core/tests/api_base_test.py
+++ b/wger/core/tests/api_base_test.py
@@ -290,17 +290,13 @@ class ApiPostTestCase(object):
(status.HTTP_405_METHOD_NOT_ALLOWED, status.HTTP_403_FORBIDDEN)
)
- # Different logged in user. Usually admin.
+ # Different logged in user
self.get_credentials(self.user_fail)
- response = self.client.put(self.url_detail, data=self.data)
- if self.protected_resource:
- self.assertIn(response.status_code,
- (status.HTTP_200_OK, status.HTTP_201_CREATED))
- else:
- self.assertIn(
- response.status_code,
- (status.HTTP_405_METHOD_NOT_ALLOWED, status.HTTP_403_FORBIDDEN)
- )
+ response = self.client.post(self.url_detail, data=self.data)
+ self.assertIn(
+ response.status_code,
+ (status.HTTP_405_METHOD_NOT_ALLOWED, status.HTTP_403_FORBIDDEN)
+ )
def test_post_special_endpoints(self):
"""
@@ -376,7 +372,7 @@ class ApiPatchTestCase(object):
# Different logged in user. Usually admin.
self.get_credentials(self.user_fail)
- response = self.client.put(self.url_detail, data=self.data)
+ response = self.client.patch(self.url_detail, data=self.data)
if self.protected_resource:
self.assertIn(response.status_code,
(status.HTTP_200_OK, status.HTTP_201_CREATED))
diff --git a/wger/exercises/api/serializers.py b/wger/exercises/api/serializers.py
index 9b88345fa..55b539912 100644
--- a/wger/exercises/api/serializers.py
+++ b/wger/exercises/api/serializers.py
@@ -239,6 +239,7 @@ class ExerciseTranslationSerializer(serializers.ModelSerializer):
"language",
"license",
"license_author",
+ "author_history",
)
@@ -279,6 +280,7 @@ class ExerciseInfoSerializer(serializers.ModelSerializer):
"videos",
"comments",
"variations",
+ "author_history",
]
@@ -312,4 +314,5 @@ class ExerciseBaseInfoSerializer(serializers.ModelSerializer):
"exercises",
"variations",
"images",
+ "author_history",
]
diff --git a/wger/exercises/management/commands/change-author.py b/wger/exercises/management/commands/change-exercise-author.py
similarity index 100%
rename from wger/exercises/management/commands/change-author.py
rename to wger/exercises/management/commands/change-exercise-author.py
diff --git a/wger/exercises/models/base.py b/wger/exercises/models/base.py
index 3fa2e2fa4..ada9ed3a2 100644
--- a/wger/exercises/models/base.py
+++ b/wger/exercises/models/base.py
@@ -36,7 +36,7 @@ from simple_history.models import HistoricalRecords
# wger
from wger.core.models import Language
from wger.utils.constants import DEFAULT_LANGUAGE
-from wger.utils.models import AbstractLicenseModel
+from wger.utils.models import AbstractHistoryMixin, AbstractLicenseModel
# Local
from .category import ExerciseCategory
@@ -45,7 +45,7 @@ from .muscle import Muscle
from .variation import Variation
-class ExerciseBase(AbstractLicenseModel, models.Model):
+class ExerciseBase(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
"""
Model for an exercise base
"""
diff --git a/wger/exercises/tests/test_change_author.py b/wger/exercises/tests/test_change_exercise_author.py
similarity index 84%
rename from wger/exercises/tests/test_change_author.py
rename to wger/exercises/tests/test_change_exercise_author.py
index 1f8720bad..8fafc5a5f 100644
--- a/wger/exercises/tests/test_change_author.py
+++ b/wger/exercises/tests/test_change_exercise_author.py
@@ -22,20 +22,20 @@ from wger.exercises.models.base import ExerciseBase
from wger.exercises.models.exercise import Exercise
-class ChangeAuthorTestCase(WgerTestCase):
+class ChangeExerciseAuthorTestCase(WgerTestCase):
"""
- Tests the change author command
+ Tests the change exercise author command
"""
def setUp(self):
- super(ChangeAuthorTestCase, self).setUp()
+ super(ChangeExerciseAuthorTestCase, self).setUp()
self.out = StringIO()
def test_missing_author(self):
"""
Test to ensure command handles a missing author parameter
"""
- call_command('change-author', stdout=self.out, no_color=True)
+ call_command('change-exercise-author', stdout=self.out, no_color=True)
self.assertIn('Please enter an author name', self.out.getvalue())
def test_missing_exercise(self):
@@ -46,7 +46,7 @@ class ChangeAuthorTestCase(WgerTestCase):
"--author-name",
"tom"
]
- call_command('change-author', *args, stdout=self.out, no_color=True)
+ call_command('change-exercise-author', *args, stdout=self.out, no_color=True)
self.assertIn(
'Please enter an exercise base or exercise ID', self.out.getvalue())
@@ -63,7 +63,7 @@ class ChangeAuthorTestCase(WgerTestCase):
"--exercise-base-id",
"2"
]
- call_command('change-author', *args, stdout=self.out, no_color=True)
+ call_command('change-exercise-author', *args, stdout=self.out, no_color=True)
self.assertIn(
'Exercise and/or exercise base has been updated', self.out.getvalue())
@@ -83,7 +83,7 @@ class ChangeAuthorTestCase(WgerTestCase):
"--exercise-id",
"1"
]
- call_command('change-author', *args, stdout=self.out, no_color=True)
+ call_command('change-exercise-author', *args, stdout=self.out, no_color=True)
self.assertIn(
'Exercise and/or exercise base has been updated', self.out.getvalue())
diff --git a/wger/utils/models.py b/wger/utils/models.py
index 9eacbb352..d6a70dafa 100644
--- a/wger/utils/models.py
+++ b/wger/utils/models.py
@@ -101,7 +101,7 @@ class AbstractHistoryMixin(models.Model):
@property
def author_history(self):
out = []
- for history in self.history.all():
+ for history in set(self.history.all()):
out.append(history.license_author)
return set(out)
"""Author history is the unique set of license authors from historical records"""