Skip to content
Open
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
4 changes: 2 additions & 2 deletions wger/manager/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ class SetConfigDataSerializer(serializers.Serializer):
max_sets = serializers.IntegerField(allow_null=True)
weight = DecimalOrIntegerField(max_digits=6, decimal_places=2)
max_weight = DecimalOrIntegerField(max_digits=6, decimal_places=2)
weight_unit = serializers.IntegerField(allow_null=True)
weight_unit = serializers.IntegerField()
weight_rounding = serializers.DecimalField(max_digits=4, decimal_places=2)
repetitions = DecimalOrIntegerField(max_digits=6, decimal_places=2)
max_repetitions = DecimalOrIntegerField(max_digits=6, decimal_places=2)
repetitions_unit = serializers.IntegerField(allow_null=True)
repetitions_unit = serializers.IntegerField()
repetitions_rounding = serializers.DecimalField(max_digits=4, decimal_places=2)
rir = DecimalOrIntegerField(max_digits=2, decimal_places=1)
max_rir = DecimalOrIntegerField(max_digits=2, decimal_places=1)
Expand Down
42 changes: 42 additions & 0 deletions wger/manager/migrations/0024_fill_null_weight_repetitions_units.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from django.db import migrations
from django.db.migrations.state import StateApps


def fill_null_units_slot_entry(apps: StateApps, schema_editor):
"""
Backfill all null unit values in SlotEntry with their defaults.
REP_UNIT_REPETITIONS = 1 , WEIGHT_UNIT_KG = 1
"""
SlotEntry = apps.get_model("manager", "SlotEntry")

SlotEntry.objects.filter(repetition_unit__isnull=True).update(repetition_unit_id=1)
SlotEntry.objects.filter(weight_unit__isnull=True).update(weight_unit_id=1)


def fill_null_units_workout_log(apps: StateApps, schema_editor):
"""
Backfill all null unit values in WorkoutLog with their defaults.
"""
WorkoutLog = apps.get_model("manager", "WorkoutLog")

# Only fill repetitions_unit where repetitions is also not null
WorkoutLog.objects.filter(
repetitions_unit__isnull=True,
repetitions__isnull=False,
).update(repetitions_unit_id=1)

# Only fill weight_unit where weight is also not null
WorkoutLog.objects.filter(
weight_unit__isnull=True,
weight__isnull=False,
).update(weight_unit_id=1)


class Migration(migrations.Migration):
dependencies = [
("manager", "0023_change_validators"),
]

operations = [
migrations.RunPython(fill_null_units_slot_entry, fill_null_units_workout_log),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('manager', '0024_fill_null_weight_repetitions_units'),
('core', '0022_move_email_verified_to_emailaddress'),
]

operations = [
# SlotEntry: make repetition_unit non-nullable
migrations.AlterField(
model_name='slotentry',
name='repetition_unit',
field=models.ForeignKey(
default=1,
on_delete=django.db.models.deletion.CASCADE,
to='core.repetitionunit',
),
),
# SlotEntry: make weight_unit non-nullable
migrations.AlterField(
model_name='slotentry',
name='weight_unit',
field=models.ForeignKey(
default=1,
on_delete=django.db.models.deletion.CASCADE,
to='core.weightunit',
verbose_name='Unit',
),
),
# WorkoutLog: make repetition_unit non-nullable
migrations.AlterField(
model_name='workoutlog',
name='repetitions_unit',
field=models.ForeignKey(
default=1,
on_delete=django.db.models.deletion.CASCADE,
to='core.repetitionunit',
verbose_name='Repetitions unit',
),
),
# WorkoutLog: make weight_unit non-nullable
migrations.AlterField(
model_name='workoutlog',
name='weight_unit',
field=models.ForeignKey(
default=1,
on_delete=django.db.models.deletion.CASCADE,
to='core.weightunit',
verbose_name='Weight unit',
),
),
]
10 changes: 0 additions & 10 deletions wger/manager/models/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ class WorkoutLog(models.Model):
verbose_name='Repetitions unit',
default=REP_UNIT_REPETITIONS,
on_delete=models.CASCADE,
null=True,
blank=True,
)
"""
The repetition unit of the log. This can be e.g. a repetition, a minute, etc.
Expand Down Expand Up @@ -148,8 +146,6 @@ class WorkoutLog(models.Model):
verbose_name='Weight unit',
default=WEIGHT_UNIT_KG,
on_delete=models.CASCADE,
null=True,
blank=True,
)
"""
The weight unit of the log. This can be e.g. kg, lb, km/h, etc.
Expand Down Expand Up @@ -238,12 +234,6 @@ def clean(self):
if self.repetitions is None and self.weight is None:
raise ValidationError('Both repetitions and weight cannot be null at the same time.')

if self.repetitions is not None and self.repetitions_unit is None:
raise ValidationError('Repetitions unit must be present if repetitions have a value.')

if self.weight is not None and self.weight_unit is None:
raise ValidationError('Weight unit must be present if weight has a value.')

def save(self, *args, **kwargs):
"""
Plumbing
Expand Down
4 changes: 0 additions & 4 deletions wger/manager/models/slot_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ class SlotEntry(models.Model):
RepetitionUnit,
default=REP_UNIT_REPETITIONS,
on_delete=models.CASCADE,
null=True,
blank=True,
)
"""
The repetition unit of a set. This can be e.g. a repetition, a minute, etc.
Expand All @@ -132,8 +130,6 @@ class SlotEntry(models.Model):
verbose_name='Unit',
default=WEIGHT_UNIT_KG,
on_delete=models.CASCADE,
null=True,
blank=True,
)
"""
The weight unit of a set. This can be e.g. kg, lb, km/h, etc.
Expand Down
Loading