Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Don't use a boolean flag for dropsets

Roland Geiderb445b8b91dfd
diff --git a/wger/manager/api/serializers.py b/wger/manager/api/serializers.py
index 1b70b5bff..86fc15353 100644
--- a/wger/manager/api/serializers.py
+++ b/wger/manager/api/serializers.py
@@ -197,7 +197,7 @@ class SlotConfigSerializer(serializers.ModelSerializer):
'weight_rounding',
'order',
'comment',
- 'is_dropset',
+ 'type',
'class_name',
'weight_configs',
'reps_configs',
@@ -278,7 +278,7 @@ class SetConfigSerializer(serializers.ModelSerializer):
'id',
'slot',
'exercise',
- 'is_dropset',
+ 'type',
'repetition_unit',
'repetition_rounding',
'weight_unit',
@@ -304,6 +304,7 @@ class SetConfigDataSerializer(serializers.Serializer):
reps_rounding = serializers.DecimalField(max_digits=4, decimal_places=2)
rir = serializers.DecimalField(max_digits=5, decimal_places=2)
rest = serializers.DecimalField(max_digits=5, decimal_places=2)
+ type = serializers.CharField()
class SetExerciseDataSerializer(serializers.Serializer):
diff --git a/wger/manager/dataclasses.py b/wger/manager/dataclasses.py
index 579b0e1cf..9a0ca3a38 100644
--- a/wger/manager/dataclasses.py
+++ b/wger/manager/dataclasses.py
@@ -30,7 +30,7 @@ from typing import (
@dataclass
class SetConfigData:
- exercise: int # 'ExerciseBase'
+ exercise: int
weight: Decimal | int | None
reps: Decimal | int | None
@@ -43,6 +43,9 @@ class SetConfigData:
weight_rounding: Decimal | int | None = 1.25
reps_rounding: Decimal | int | None = 1
+ type: str = 'normal'
+ slot_config_id: int | None = None
+
@dataclass
class SetExerciseData:
diff --git a/wger/manager/migrations/0018_flexible_routines.py b/wger/manager/migrations/0018_flexible_routines.py
index dd7212073..53e1a9868 100644
--- a/wger/manager/migrations/0018_flexible_routines.py
+++ b/wger/manager/migrations/0018_flexible_routines.py
@@ -95,11 +95,21 @@ class Migration(migrations.Migration):
(
'id',
models.AutoField(
- auto_created=True, primary_key=True, serialize=False, verbose_name='ID'
+ auto_created=True,
+ primary_key=True,
+ serialize=False,
+ verbose_name='ID',
),
),
('order', models.PositiveIntegerField(blank=True)),
- ('is_dropset', models.BooleanField(default=False)),
+ (
+ 'type',
+ models.CharField(
+ choices=[('normal', 'Normal'), ('dropset', 'Dropset'), ('myo', 'Myo')],
+ default='normal',
+ max_length=10,
+ ),
+ ),
('comment', models.CharField(blank=True, max_length=100)),
('class_name', models.CharField(blank=True, max_length=50, null=True)),
(
diff --git a/wger/manager/migrations/0020_add_routine_labels.py b/wger/manager/migrations/0020_add_routine_labels.py
index 9f90dec4a..079177a30 100644
--- a/wger/manager/migrations/0020_add_routine_labels.py
+++ b/wger/manager/migrations/0020_add_routine_labels.py
@@ -1,4 +1,4 @@
-# Generated by Django 4.2.13 on 2024-05-31 16:40
+# Generated by Django 4.2.13 on 2024-06-12 09:09
from django.db import migrations, models
import django.db.models.deletion
@@ -65,16 +65,22 @@ class Migration(migrations.Migration):
models.PositiveIntegerField(default=2, verbose_name='End'),
),
('label', models.CharField(max_length=35, verbose_name='Label')),
- ('comment', models.CharField(max_length=500, verbose_name='Comment')),
+ (
+ 'comment',
+ models.CharField(default='', max_length=500, verbose_name='Comment'),
+ ),
(
'routine',
models.ForeignKey(
- null=True,
on_delete=django.db.models.deletion.CASCADE,
+ related_name='labels',
to='manager.routine',
verbose_name='Routine',
),
),
],
+ options={
+ 'ordering': ['start_offset'],
+ },
),
]
diff --git a/wger/manager/models/routine.py b/wger/manager/models/routine.py
index 97d92176e..e088b4781 100644
--- a/wger/manager/models/routine.py
+++ b/wger/manager/models/routine.py
@@ -87,11 +87,12 @@ class Routine(models.Model):
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'
+ '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'),
diff --git a/wger/manager/models/slot.py b/wger/manager/models/slot.py
index 180266c41..61a89b807 100644
--- a/wger/manager/models/slot.py
+++ b/wger/manager/models/slot.py
@@ -6,7 +6,7 @@ from django.db import models
from django.utils.translation import gettext_lazy as _
# wger
-from wger.manager.dataclasses import SetExerciseData
+from wger.manager.dataclasses import SetExerciseData, SetConfigData
from wger.manager.models import DayNg
@@ -60,16 +60,16 @@ class Slot(models.Model):
return [SetExerciseData(data=s.get_config(iteration), config=s) for s in self.configs.all()]
- def get_sets(self, iteration: int) -> list[SetExerciseData]:
+ def get_sets(self, iteration: int) -> list[SetConfigData]:
"""
Calculates the sets as they would be performed in the gym
- Note that this is only different from the list of sets supersets, since
+ Note that this is only different from the list of sets in supersets, since
they will be "interleaved". E.g.:
- Exercise 1, 4 Sets
- Exercise 2, 3 Sets
- Exercise 3, 2 Sets
- (the other weight, reps, etc. settings are not important)
+ (the other weight, reps, etc. settings are not important here)
Would result in:
- Exercise 1
diff --git a/wger/manager/models/slot_config.py b/wger/manager/models/slot_config.py
index 52e84bff3..a656d724a 100644
--- a/wger/manager/models/slot_config.py
+++ b/wger/manager/models/slot_config.py
@@ -36,12 +36,22 @@ from wger.manager.models.abstract_config import (
)
+class SetType(models.TextChoices):
+ NORMAL = 'normal'
+ DROPSET = 'dropset'
+ MYO = 'myo'
+
+
class SlotConfig(models.Model):
"""
Set configuration for an exercise (weight, reps, etc.)
"""
- slot = models.ForeignKey('Slot', on_delete=models.CASCADE, related_name='configs')
+ slot = models.ForeignKey(
+ 'Slot',
+ on_delete=models.CASCADE,
+ related_name='configs',
+ )
exercise = models.ForeignKey(
ExerciseBase,
@@ -98,8 +108,11 @@ class SlotConfig(models.Model):
blank=True,
)
- is_dropset = models.BooleanField(
- default=False,
+ type = models.CharField(
+ choices=SetType.choices,
+ max_length=10,
+ default=SetType.NORMAL,
+ null=False,
)
class_name = models.CharField(
@@ -219,6 +232,7 @@ class SlotConfig(models.Model):
reps_unit=self.repetition_unit.pk if reps is not None else None,
rir=self.get_rir(iteration),
rest=self.get_rest(iteration),
+ type=self.type,
)
def get_sets(self, iteration: int) -> Decimal | None: