Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Remove old workout model and associated views

Roland Geiderc5930a89d300
diff --git a/wger/manager/api/serializers.py b/wger/manager/api/serializers.py
index 2abeb2247..199e1a8f8 100644
--- a/wger/manager/api/serializers.py
+++ b/wger/manager/api/serializers.py
@@ -35,7 +35,6 @@ from wger.manager.models import (
Slot,
SlotEntry,
WeightConfig,
- Workout,
WorkoutLog,
WorkoutSession,
)
@@ -398,26 +397,6 @@ class WorkoutDayDataGymModeSerializer(serializers.Serializer):
slots = SlotDataSerializer(many=True, source='slots_gym_mode')
-class WorkoutSerializer(serializers.ModelSerializer):
- """
- Workout serializer
- """
-
- class Meta:
- model = Workout
- fields = ('id', 'name', 'creation_date', 'description')
-
-
-class WorkoutTemplateSerializer(serializers.ModelSerializer):
- """
- Workout template serializer
- """
-
- class Meta:
- model = Workout
- fields = ('id', 'name', 'creation_date', 'description', 'is_public')
-
-
class WorkoutSessionSerializer(serializers.ModelSerializer):
"""
Workout session serializer
diff --git a/wger/manager/api/views.py b/wger/manager/api/views.py
index 7ebb570c6..7e8bc659e 100644
--- a/wger/manager/api/views.py
+++ b/wger/manager/api/views.py
@@ -59,9 +59,7 @@ from wger.manager.api.serializers import (
WorkoutDayDataDisplayModeSerializer,
WorkoutDayDataGymModeSerializer,
WorkoutLogSerializer,
- WorkoutSerializer,
WorkoutSessionSerializer,
- WorkoutTemplateSerializer,
)
from wger.manager.models import (
Day,
@@ -237,60 +235,6 @@ class RoutineViewSet(viewsets.ModelViewSet):
return Response(out)
-class WorkoutViewSet(viewsets.ModelViewSet):
- """
- API endpoint for routine objects
- """
-
- serializer_class = WorkoutSerializer
- is_private = True
- ordering_fields = '__all__'
- filterset_fields = ('name', 'description', 'creation_date')
-
- def get_queryset(self):
- """
- Only allow access to appropriate objects
- """
- # REST API generation
- if getattr(self, 'swagger_fake_view', False):
- return Routine.objects.none()
-
- return Routine.objects.filter(user=self.request.user)
-
- def perform_create(self, serializer):
- """
- Set the owner
- """
- serializer.save(user=self.request.user)
-
- @action(detail=True)
- def log_data(self, request, pk):
- """
- Returns processed log data for graphing
-
- Basically, these are the logs for the workout and for a specific exercise base.
-
- If on a day there are several entries with the same number of repetitions,
- but different weights, only the entry with the higher weight is shown in the chart
- """
- base_id = request.GET.get('id')
- if not base_id:
- return Response("Please provide an base ID in the 'id' GET parameter")
-
- base = get_object_or_404(Exercise, pk=base_id)
- logs = base.workoutlog_set.filter(
- user=self.request.user,
- weight_unit__in=(1, 2),
- repetition_unit=1,
- workout=self.get_object(),
- )
- entry_logs, chart_data = process_log_entries(logs)
- serialized_logs = {}
- for key, values in entry_logs.items():
- serialized_logs[str(key)] = [WorkoutLogSerializer(entry).data for entry in values]
- return Response({'chart_data': json.loads(chart_data), 'logs': serialized_logs})
-
-
class UserRoutineTemplateViewSet(viewsets.ReadOnlyModelViewSet):
"""
API endpoint for routine template objects
diff --git a/wger/manager/forms.py b/wger/manager/forms.py
deleted file mode 100644
index 3cc26e944..000000000
--- a/wger/manager/forms.py
+++ /dev/null
@@ -1,103 +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.forms import (
- BooleanField,
- CharField,
- ChoiceField,
- Form,
- ModelForm,
- ModelMultipleChoiceField,
- widgets,
-)
-from django.utils.translation import (
- gettext as _,
- gettext_lazy,
-)
-
-# Third Party
-from crispy_forms.helper import FormHelper
-from crispy_forms.layout import Submit
-
-# wger
-from wger.manager.models import Workout
-
-
-class WorkoutForm(ModelForm):
- class Meta:
- model = Workout
- fields = (
- 'name',
- 'description',
- )
-
-
-class WorkoutMakeTemplateForm(ModelForm):
- class Meta:
- model = Workout
- fields = (
- 'is_template',
- 'is_public',
- )
-
-
-class WorkoutCopyForm(Form):
- name = CharField(max_length=100, help_text=_('The name of the workout'), required=False)
- description = CharField(
- max_length=1000,
- help_text=_(
- 'A short description or goal of the workout. For '
- "example 'Focus on back' or 'Week 1 of program xy'."
- ),
- widget=widgets.Textarea,
- required=False,
- )
-
-
-class OrderedModelMultipleChoiceField(ModelMultipleChoiceField):
- """Ordered multiple choice field"""
-
- def clean(self, value):
- int_list = [int(i) for i in value]
- qs = super(OrderedModelMultipleChoiceField, self).clean(int_list)
- return sorted(qs, key=lambda x: int_list.index(x.pk))
-
-
-class WorkoutScheduleDownloadForm(Form):
- """
- Form for the workout schedule download
- """
-
- pdf_type = ChoiceField(
- label=gettext_lazy('Type'),
- choices=(('log', gettext_lazy('Log')), ('table', gettext_lazy('Table'))),
- )
- images = BooleanField(label=gettext_lazy('with images'), required=False)
- comments = BooleanField(label=gettext_lazy('with comments'), required=False)
-
- def __init__(self):
- super(WorkoutScheduleDownloadForm, self).__init__()
- self.helper = FormHelper()
- self.helper.form_tag = False
- self.helper.add_input(
- Submit(
- 'submit',
- _('Download'),
- css_class='btn-success btn-block',
- css_id='download-pdf-button-schedule',
- )
- )
diff --git a/wger/manager/models/__init__.py b/wger/manager/models/__init__.py
index ca7a980ff..a5fb60b5a 100644
--- a/wger/manager/models/__init__.py
+++ b/wger/manager/models/__init__.py
@@ -43,4 +43,3 @@ from .weight_config import (
MaxWeightConfig,
WeightConfig,
)
-from .workout import Workout
diff --git a/wger/manager/models/workout.py b/wger/manager/models/workout.py
deleted file mode 100644
index 0a0718932..000000000
--- a/wger/manager/models/workout.py
+++ /dev/null
@@ -1,116 +0,0 @@
-# This file is part of wger Workout Manager <https://github.com/wger-project>.
-# Copyright (C) 2013 - 2021 wger Team
-#
-# 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 Affero General Public License for more details.
-#
-# 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/>.
-
-# Django
-from django.contrib.auth.models import User
-from django.core.exceptions import ValidationError
-from django.db import models
-from django.urls import reverse
-from django.utils.translation import gettext_lazy as _
-
-# wger
-from wger.manager.managers import (
- WorkoutAndTemplateManager,
- WorkoutManager,
- WorkoutTemplateManager,
-)
-
-
-class Workout(models.Model):
- """
- Model for a training schedule
- """
-
- objects = WorkoutManager()
- templates = WorkoutTemplateManager()
- both = WorkoutAndTemplateManager()
-
- class Meta:
- """
- Metaclass to set some other properties
- """
-
- ordering = [
- '-creation_date',
- ]
-
- creation_date = models.DateField(_('Creation date'), auto_now_add=True)
- name = models.CharField(
- verbose_name=_('Name'),
- max_length=100,
- blank=True,
- help_text=_('The name of the workout'),
- )
- description = models.TextField(
- verbose_name=_('Description'),
- max_length=1000,
- blank=True,
- help_text=_(
- 'A short description or goal of the workout. For '
- "example 'Focus on back' or 'Week 1 of program "
- "xy'."
- ),
- )
- is_template = models.BooleanField(
- verbose_name=_('Workout template'),
- help_text=_(
- 'Marking a workout as a template will freeze it and allow you to ' 'make copies of it'
- ),
- default=False,
- null=False,
- )
- is_public = models.BooleanField(
- verbose_name=_('Public template'),
- help_text=_('A public template is available to other users'),
- default=False,
- null=False,
- )
-
- user = models.ForeignKey(
- User,
- verbose_name=_('User'),
- on_delete=models.CASCADE,
- )
-
- def get_absolute_url(self):
- """
- Returns the canonical URL to view a workout
- """
- return reverse(
- 'manager:template:view' if self.is_template else 'manager:workout:view',
- kwargs={'pk': self.id},
- )
-
- def __str__(self):
- """
- Return a more human-readable representation
- """
- if self.name:
- return self.name
- else:
- return f'{_("Workout")} ({self.creation_date})'
-
- def clean(self):
- if self.is_public and not self.is_template:
- raise ValidationError(
- _('You must mark this workout as a template before declaring it public')
- )
-
- def get_owner_object(self):
- """
- Returns the object that has owner information
- """
- return self
diff --git a/wger/manager/signals.py b/wger/manager/signals.py
index 0da1d1bf1..b304a3e05 100644
--- a/wger/manager/signals.py
+++ b/wger/manager/signals.py
@@ -134,3 +134,4 @@ pre_delete.connect(update_cache_sets_config, sender=SetsConfig)
pre_delete.connect(update_cache_rest_config, sender=RestConfig)
pre_delete.connect(update_cache_max_rest_config, sender=MaxRestConfig)
pre_delete.connect(update_cache_rir_config, sender=RiRConfig)
+pre_delete.connect(update_cache_log, sender=WorkoutLog)
diff --git a/wger/manager/tests/test_workout_template.py b/wger/manager/tests/test_workout_template.py
deleted file mode 100644
index f58c98663..000000000
--- a/wger/manager/tests/test_workout_template.py
+++ /dev/null
@@ -1,83 +0,0 @@
-# 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.urls import reverse
-
-# wger
-from wger.core.tests.base_testcase import WgerTestCase
-from wger.manager.models import Workout
-
-
-class WorkoutTemplateManagerTestCase(WgerTestCase):
- """
- Test accessing the workout template DB manager
- """
-
- def test_managers(self):
- """
- Test that the DB managers correctly filter the workouts
- """
- self.assertEqual(Workout.objects.all().count(), 3)
- self.assertEqual(Workout.templates.all().count(), 0)
- self.assertEqual(Workout.both.all().count(), 3)
-
- workout = Workout.objects.get(pk=3)
- workout.is_template = True
- workout.save()
- self.assertEqual(Workout.objects.all().count(), 2)
- self.assertEqual(Workout.templates.all().count(), 1)
- self.assertEqual(Workout.both.all().count(), 3)
-
- workout.is_public = True
- workout.save()
- self.assertEqual(Workout.objects.all().count(), 2)
- self.assertEqual(Workout.templates.all().count(), 1)
- self.assertEqual(Workout.both.all().count(), 3)
-
-
-class SwitchViewsTestCase(WgerTestCase):
- """
- Test the views that convert a workout to a template and viceversa
- """
-
- def test_make_template(self):
- """
- Test accessing the template view for a regular workout
- """
- response = self.client.get(reverse('manager:workout:make-template', kwargs={'pk': 3}))
- self.assertEqual(response.status_code, 403)
-
- self.user_login('test')
- response = self.client.get(reverse('manager:workout:make-template', kwargs={'pk': 3}))
- self.assertEqual(response.status_code, 200)
-
- self.user_login('admin')
- response = self.client.get(reverse('manager:workout:make-template', kwargs={'pk': 3}))
- self.assertEqual(response.status_code, 403)
-
- def test_make_workout(self):
- """
- Test marking a template a workout again
- """
- response = self.client.get(reverse('manager:template:make-workout', kwargs={'pk': 3}))
- self.assertEqual(response.status_code, 403)
-
- self.user_login('test')
- response = self.client.get(reverse('manager:template:make-workout', kwargs={'pk': 3}))
- self.assertEqual(response.status_code, 302)
-
- self.user_login('admin')
- response = self.client.get(reverse('manager:template:make-workout', kwargs={'pk': 3}))
- self.assertEqual(response.status_code, 403)
diff --git a/wger/manager/urls.py b/wger/manager/urls.py
index 23d7dda97..9e992852a 100644
--- a/wger/manager/urls.py
+++ b/wger/manager/urls.py
@@ -27,6 +27,7 @@ from wger.manager.views import (
routine,
)
+
# sub patterns for templates
patterns_templates = [
path(
diff --git a/wger/urls.py b/wger/urls.py
index 740802882..4c301ac24 100644
--- a/wger/urls.py
+++ b/wger/urls.py
@@ -62,7 +62,6 @@ router = routers.DefaultRouter()
#
# Manager app
-router.register(r'workout', manager_api_views.WorkoutViewSet, basename='workout')
router.register(r'routine', manager_api_views.RoutineViewSet, basename='routine')
router.register(r'templates', manager_api_views.UserRoutineTemplateViewSet, basename='templates')
router.register(