Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Allow setting max rir values

Roland Geiderf1a9670d62c1
diff --git a/wger/manager/api/serializers.py b/wger/manager/api/serializers.py
index 9e12de1d1..6c5829045 100644
--- a/wger/manager/api/serializers.py
+++ b/wger/manager/api/serializers.py
@@ -24,6 +24,7 @@ from wger.manager.models import (
Day,
MaxRepsConfig,
MaxRestConfig,
+ MaxRiRConfig,
MaxSetsConfig,
MaxWeightConfig,
RepsConfig,
@@ -150,6 +151,16 @@ class RiRConfigSerializer(serializers.ModelSerializer):
fields = CONFIG_FIELDS
+class MaxRiRConfigSerializer(serializers.ModelSerializer):
+ """
+ RiR Config serializer
+ """
+
+ class Meta:
+ model = MaxRiRConfig
+ fields = CONFIG_FIELDS
+
+
class RestConfigSerializer(serializers.ModelSerializer):
"""
Rest Config serializer
@@ -182,6 +193,7 @@ class SlotEntryStructureSerializer(serializers.ModelSerializer):
set_nr_configs = SetNrConfigSerializer(source='setsconfig_set', many=True)
max_set_nr_configs = MaxSetNrConfigSerializer(source='maxsetsconfig_set', many=True)
rir_configs = RiRConfigSerializer(source='rirconfig_set', many=True)
+ max_rir_configs = MaxRiRConfigSerializer(source='maxrirconfig_set', many=True)
rest_configs = RestConfigSerializer(source='restconfig_set', many=True)
max_rest_configs = RestConfigSerializer(source='maxrestconfig_set', many=True)
@@ -207,6 +219,7 @@ class SlotEntryStructureSerializer(serializers.ModelSerializer):
'set_nr_configs',
'max_set_nr_configs',
'rir_configs',
+ 'max_rir_configs',
'rest_configs',
'max_rest_configs',
)
diff --git a/wger/manager/api/views.py b/wger/manager/api/views.py
index 320352352..b0723faaf 100644
--- a/wger/manager/api/views.py
+++ b/wger/manager/api/views.py
@@ -38,6 +38,7 @@ from wger.manager.api.serializers import (
LogStatsDataSerializer,
MaxRepsConfigSerializer,
MaxRestConfigSerializer,
+ MaxRiRConfigSerializer,
MaxSetNrConfigSerializer,
MaxWeightConfigSerializer,
RepsConfigSerializer,
@@ -62,6 +63,7 @@ from wger.manager.models import (
Day,
MaxRepsConfig,
MaxRestConfig,
+ MaxRiRConfig,
MaxSetsConfig,
MaxWeightConfig,
RepsConfig,
@@ -764,3 +766,21 @@ class RiRConfigViewSet(AbstractConfigViewSet):
return RiRConfig.objects.none()
return RiRConfig.objects.filter(slot_entry__slot__day__routine__user=self.request.user)
+
+
+class MaxRiRConfigViewSet(AbstractConfigViewSet):
+ """
+ API endpoint for set config objects
+ """
+
+ serializer_class = MaxRiRConfigSerializer
+
+ def get_queryset(self):
+ """
+ Only allow access to appropriate objects
+ """
+ # REST API generation
+ if getattr(self, 'swagger_fake_view', False):
+ return MaxRiRConfig.objects.none()
+
+ return MaxRiRConfig.objects.filter(slot_entry__slot__day__routine__user=self.request.user)
diff --git a/wger/manager/migrations/0018_flexible_routines.py b/wger/manager/migrations/0018_flexible_routines.py
index 1db250e1a..7c23fdc51 100644
--- a/wger/manager/migrations/0018_flexible_routines.py
+++ b/wger/manager/migrations/0018_flexible_routines.py
@@ -472,7 +472,13 @@ class Migration(migrations.Migration):
),
),
('iteration', models.PositiveIntegerField()),
- ('value', models.DecimalField(decimal_places=2, max_digits=6)),
+ (
+ 'value',
+ models.DecimalField(
+ decimal_places=1,
+ max_digits=2,
+ ),
+ ),
(
'operation',
models.CharField(
@@ -506,6 +512,62 @@ class Migration(migrations.Migration):
'unique_together': {('slot_entry', 'iteration')},
},
),
+ migrations.CreateModel(
+ name='MaxRiRConfig',
+ fields=[
+ (
+ 'id',
+ models.AutoField(
+ auto_created=True,
+ primary_key=True,
+ serialize=False,
+ verbose_name='ID',
+ ),
+ ),
+ ('iteration', models.PositiveIntegerField()),
+ (
+ 'operation',
+ models.CharField(
+ choices=[('+', 'Plus'), ('-', 'Minus'), ('r', 'Replace')],
+ default='r',
+ max_length=1,
+ ),
+ ),
+ (
+ 'step',
+ models.CharField(
+ choices=[
+ ('na', 'Not Applicable'),
+ ('abs', 'Absolute'),
+ ('percent', 'Percent'),
+ ],
+ default='abs',
+ max_length=10,
+ ),
+ ),
+ ('need_log_to_apply', models.BooleanField(default=False)),
+ ('repeat', models.BooleanField(default=False)),
+ (
+ 'value',
+ models.DecimalField(
+ decimal_places=1,
+ max_digits=2,
+ ),
+ ),
+ (
+ 'slot_entry',
+ models.ForeignKey(
+ on_delete=django.db.models.deletion.CASCADE,
+ to='manager.slotentry',
+ ),
+ ),
+ ],
+ options={
+ 'ordering': ['slot_entry', 'iteration'],
+ 'abstract': False,
+ 'unique_together': {('slot_entry', 'iteration')},
+ },
+ ),
migrations.CreateModel(
name='RestConfig',
fields=[
diff --git a/wger/manager/models/__init__.py b/wger/manager/models/__init__.py
index d88dec281..d72a5ff96 100644
--- a/wger/manager/models/__init__.py
+++ b/wger/manager/models/__init__.py
@@ -27,7 +27,10 @@ from .rest_config import (
MaxRestConfig,
RestConfig,
)
-from .rir_config import RiRConfig
+from .rir_config import (
+ MaxRiRConfig,
+ RiRConfig,
+)
from .routine import Routine
from .schedule import Schedule
from .schedule_step import ScheduleStep
diff --git a/wger/manager/models/rir_config.py b/wger/manager/models/rir_config.py
index 02bc0ba5f..7cc3617b8 100644
--- a/wger/manager/models/rir_config.py
+++ b/wger/manager/models/rir_config.py
@@ -14,6 +14,9 @@
# 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.db import models
+
# wger
from wger.manager.models import AbstractChangeConfig
@@ -23,4 +26,18 @@ class RiRConfig(AbstractChangeConfig):
Configuration model for the number of RiR for a workout set
"""
- pass
+ value = models.DecimalField(
+ decimal_places=1,
+ max_digits=2,
+ )
+
+
+class MaxRiRConfig(AbstractChangeConfig):
+ """
+ Configuration model for the upper limit of RiR for a workout set
+ """
+
+ value = models.DecimalField(
+ decimal_places=1,
+ max_digits=2,
+ )
diff --git a/wger/manager/models/slot_entry.py b/wger/manager/models/slot_entry.py
index 2a1c8de62..085c19dd3 100644
--- a/wger/manager/models/slot_entry.py
+++ b/wger/manager/models/slot_entry.py
@@ -85,8 +85,6 @@ class SlotEntry(models.Model):
)
"""
The amount by which the repetitions will be rounded
-
- Note that this will happen in the UI, and not in the backend
"""
weight_unit = models.ForeignKey(
@@ -107,8 +105,6 @@ class SlotEntry(models.Model):
)
"""
The amount by which the weight will be rounded
-
- Note that this will happen in the UI, and not in the backend
"""
order = models.PositiveIntegerField(
diff --git a/wger/manager/urls.py b/wger/manager/urls.py
index f83bd0782..0ed44c513 100644
--- a/wger/manager/urls.py
+++ b/wger/manager/urls.py
@@ -33,6 +33,7 @@ from wger.manager.views import (
workout,
)
+
# sub patterns for workout logs
patterns_log = [
path(
diff --git a/wger/urls.py b/wger/urls.py
index 0886dd950..8252c9f5c 100644
--- a/wger/urls.py
+++ b/wger/urls.py
@@ -131,6 +131,7 @@ router.register(
basename='max-rest-config',
)
router.register(r'rir-config', manager_api_views.RiRConfigViewSet, basename='rir-config')
+router.register(r'max-rir-config', manager_api_views.MaxRiRConfigViewSet, basename='max-rir-config')
router.register(r'workoutlog', manager_api_views.WorkoutLogViewSet, basename='workoutlog')
router.register(r'schedulestep', manager_api_views.ScheduleStepViewSet, basename='schedulestep')
router.register(r'schedule', manager_api_views.ScheduleViewSet, basename='schedule')