Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add convenience endpoints for workout sets

Roland Geider3e6f44b92442
diff --git a/wger/manager/api/views.py b/wger/manager/api/views.py
index 357546e7f..360405dbb 100644
--- a/wger/manager/api/views.py
+++ b/wger/manager/api/views.py
@@ -19,6 +19,7 @@
import json
# Django
+from django.http import HttpResponseNotFound
from django.shortcuts import get_object_or_404
# Third Party
@@ -243,6 +244,23 @@ 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})
+
+ @action(detail=True)
+ def smart_text(self, request, pk):
+ """Returns the smart text representation for the reps"""
+
+ try:
+ exercise = get_object_or_404(Exercise, pk=int(self.request.GET.get('exercise')))
+ except ValueError:
+ return HttpResponseNotFound()
+ return Response({'results': self.get_object().reps_smart_text(exercise=exercise)})
+
class SettingViewSet(WgerOwnerObjectModelViewSet):
"""