Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split exercise translations (resolves issue #448) #583

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ Developers
* Biplov - https://github.com/beingbiplov
* Rashmi Kamath - https://github.com/Rkamath2
* Anthony (Ryo) Wright - https://github.com/ryowright
* Nikitha Murikinati - https://github.com/nikithamurikinati
* Harlene Samra - https://github.com/harlenesamra
* Justine Cho - https://github.com/jcho17
* Vaheeshta Mehrshahi - https://github.com/vaheeshta
* Jeevika Ghosh - https://github.com/jeevikaghosh
* Austin Leung - https://github.com/austin-leung
* Derek Li - https://github.com/derekli17
* Noah Pinter - https://github.com/nopinter


Translators
-----------

Expand Down
16 changes: 12 additions & 4 deletions wger/exercises/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@
from wger.exercises.models import (
Equipment,
Exercise,
ExerciseBase,
ExerciseCategory,
ExerciseComment,
ExerciseImage,
Muscle
)


class ExerciseBaseSerializer(serializers.ModelSerializer):
"""
Exercise serializer
"""
class Meta:
model = ExerciseBase
fields = '__all__'


class ExerciseSerializer(serializers.ModelSerializer):
"""
Exercise serializer
Expand Down Expand Up @@ -71,19 +81,17 @@ class ExerciseInfoSerializer(serializers.ModelSerializer):

images = ExerciseImageSerializer(source='exerciseimage_set', many=True)
comments = ExerciseCommentSerializer(source='exercisecomment_set', many=True)
exercise_base = ExerciseBaseSerializer(source='exercisebase_set', many=True)

class Meta:
model = Exercise
depth = 1
fields = ("id",
"name",
"uuid",
"category",
"description",
"creation_date",
"muscles",
"muscles_secondary",
"equipment",
"exercise_base"
"language",
"license",
"license_author",
Expand Down
33 changes: 21 additions & 12 deletions wger/exercises/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from wger.config.models import LanguageConfig
from wger.exercises.api.serializers import (
EquipmentSerializer,
ExerciseBaseSerializer,
ExerciseCategorySerializer,
ExerciseCommentSerializer,
ExerciseImageSerializer,
Expand All @@ -55,6 +56,21 @@
from wger.utils.permissions import CreateOnlyPermission


class ExerciseBaseViewSet(viewsets.ModelViewSet):
"""
API endpoint for exercise base objects. For a read-only endpoint with all
the information of an exercise, see /api/v2/exerciseinfo/
"""
queryset = Exercise.objects.accepted()
serializer_class = ExerciseBaseSerializer
permission_classes = (IsAuthenticatedOrReadOnly, CreateOnlyPermission)
ordering_fields = '__all__'
filterset_fields = ('category',
'muscles',
'muscles_secondary',
'equipment')


class ExerciseViewSet(viewsets.ModelViewSet):
"""
API endpoint for exercise objects. For a read-only endpoint with all
Expand All @@ -64,15 +80,11 @@ class ExerciseViewSet(viewsets.ModelViewSet):
serializer_class = ExerciseSerializer
permission_classes = (IsAuthenticatedOrReadOnly, CreateOnlyPermission)
ordering_fields = '__all__'
filterset_fields = ('category',
'creation_date',
filterset_fields = ('creation_date',
'description',
'language',
'muscles',
'muscles_secondary',
'status',
'name',
'equipment',
'variations',
'license',
'license_author')
Expand Down Expand Up @@ -105,7 +117,7 @@ def search(request):
exercises = (Exercise.objects.filter(name__icontains=q)
.filter(language__in=languages)
.filter(status=Exercise.STATUS_ACCEPTED)
.order_by('category__name', 'name')
.order_by('exercise_base__category__name', 'name')
.distinct())

for exercise in exercises:
Expand All @@ -123,7 +135,7 @@ def search(request):
'data': {
'id': exercise.id,
'name': exercise.name,
'category': _(exercise.category.name),
'category': _(exercise.exercise_base.category.name),
'image': image,
'image_thumbnail': thumbnail
}
Expand All @@ -143,14 +155,11 @@ class ExerciseInfoViewset(viewsets.ReadOnlyModelViewSet):
queryset = Exercise.objects.accepted()
serializer_class = ExerciseInfoSerializer
ordering_fields = '__all__'
filterset_fields = ('category',
'creation_date',
filterset_fields = ('creation_date',
'description',
'language',
'muscles',
'muscles_secondary',
'name',
'equipment',
'exercise_base',
'license',
'variations',
'license_author')
Expand Down
Loading