Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Remove the 'replace' flag

Roland Geider88589f6a2a3c
diff --git a/wger/manager/api/consts.py b/wger/manager/api/consts.py
index eb870d8ae..3fd4da44a 100644
--- a/wger/manager/api/consts.py
+++ b/wger/manager/api/consts.py
@@ -5,6 +5,5 @@ CONFIG_FIELDS = (
'value',
'operation',
'step',
- 'replace',
'need_log_to_apply',
)
diff --git a/wger/manager/fixtures/test-routine-data.json b/wger/manager/fixtures/test-routine-data.json
index c7491d42e..63807ae9b 100644
--- a/wger/manager/fixtures/test-routine-data.json
+++ b/wger/manager/fixtures/test-routine-data.json
@@ -160,9 +160,8 @@
"slot_config_id": 1,
"iteration": 1,
"value": 5,
- "operation": null,
+ "operation": "r",
"step": null,
- "replace": true,
"need_log_to_apply": false
}
},
@@ -173,9 +172,8 @@
"slot_config_id": 2,
"iteration": 1,
"value": 2,
- "operation": null,
+ "operation": "r",
"step": null,
- "replace": true,
"need_log_to_apply": false
}
},
@@ -186,9 +184,8 @@
"slot_config_id": 3,
"iteration": 1,
"value": 5,
- "operation": null,
+ "operation": "r",
"step": null,
- "replace": true,
"need_log_to_apply": false
}
},
@@ -199,9 +196,8 @@
"slot_config_id": 4,
"iteration": 1,
"value": 3,
- "operation": null,
+ "operation": "r",
"step": null,
- "replace": true,
"need_log_to_apply": false
}
},
@@ -212,9 +208,8 @@
"slot_config_id": 1,
"iteration": 1,
"value": 80,
- "operation": null,
+ "operation": "r",
"step": null,
- "replace": true,
"need_log_to_apply": false
}
},
@@ -225,9 +220,8 @@
"slot_config_id": 2,
"iteration": 1,
"value": 20,
- "operation": null,
+ "operation": "r",
"step": null,
- "replace": true,
"need_log_to_apply": false
}
},
@@ -238,9 +232,8 @@
"slot_config_id": 3,
"iteration": 1,
"value": 80,
- "operation": null,
+ "operation": "r",
"step": null,
- "replace": true,
"need_log_to_apply": false
}
},
@@ -251,9 +244,8 @@
"slot_config_id": 4,
"iteration": 1,
"value": 50,
- "operation": null,
+ "operation": "r",
"step": null,
- "replace": true,
"need_log_to_apply": false
}
},
@@ -264,9 +256,8 @@
"slot_config_id": 1,
"iteration": 1,
"value": 4,
- "operation": null,
+ "operation": "r",
"step": null,
- "replace": true,
"need_log_to_apply": false
}
},
@@ -277,9 +268,8 @@
"slot_config_id": 2,
"iteration": 1,
"value": 5,
- "operation": null,
+ "operation": "r",
"step": null,
- "replace": true,
"need_log_to_apply": false
}
},
@@ -290,9 +280,8 @@
"slot_config_id": 3,
"iteration": 1,
"value": 6,
- "operation": null,
+ "operation": "r",
"step": null,
- "replace": true,
"need_log_to_apply": false
}
},
@@ -303,9 +292,8 @@
"slot_config_id": 4,
"iteration": 1,
"value": 4,
- "operation": null,
+ "operation": "r",
"step": null,
- "replace": true,
"need_log_to_apply": false
}
}
diff --git a/wger/manager/management/commands/dummy-generator-routines.py b/wger/manager/management/commands/dummy-generator-routines.py
index 7bc98a3f8..82ae322ac 100644
--- a/wger/manager/management/commands/dummy-generator-routines.py
+++ b/wger/manager/management/commands/dummy-generator-routines.py
@@ -33,7 +33,7 @@ from wger.manager.models import (
SlotConfig,
WeightConfig,
)
-
+from wger.manager.models.abstract_config import OperationChoices
logger = logging.getLogger(__name__)
@@ -132,19 +132,19 @@ class Command(BaseCommand):
slot_config=slot_config,
value=sets,
iteration=1,
- replace=True,
+ operation=OperationChoices.REPLACE,
).save()
RepsConfig(
slot_config=slot_config,
value=reps,
iteration=1,
- replace=True,
+ operation=OperationChoices.REPLACE,
).save()
WeightConfig(
slot_config=slot_config,
value=weight,
iteration=1,
- replace=True,
+ operation=OperationChoices.REPLACE,
).save()
diff --git a/wger/manager/migrations/0018_flexible_routines.py b/wger/manager/migrations/0018_flexible_routines.py
index 43f9d9fdc..27404989f 100644
--- a/wger/manager/migrations/0018_flexible_routines.py
+++ b/wger/manager/migrations/0018_flexible_routines.py
@@ -344,10 +344,10 @@ class Migration(migrations.Migration):
(
'operation',
models.CharField(
- choices=[('+', 'Plus'), ('-', 'Minus')],
+ choices=[('+', 'Plus'), ('-', 'Minus'), ('r', 'Replace')],
default='+',
max_length=1,
- null=True,
+ null=False,
),
),
(
@@ -359,7 +359,6 @@ class Migration(migrations.Migration):
null=True,
),
),
- ('replace', models.BooleanField(default=False)),
('need_log_to_apply', models.BooleanField(default=False, null=True)),
(
'slot_config',
@@ -392,10 +391,10 @@ class Migration(migrations.Migration):
(
'operation',
models.CharField(
- choices=[('+', 'Plus'), ('-', 'Minus')],
+ choices=[('+', 'Plus'), ('-', 'Minus'), ('r', 'Replace')],
default='+',
max_length=1,
- null=True,
+ null=False,
),
),
(
@@ -407,7 +406,6 @@ class Migration(migrations.Migration):
null=True,
),
),
- ('replace', models.BooleanField(default=False)),
('need_log_to_apply', models.BooleanField(default=False, null=True)),
(
'slot_config',
@@ -440,10 +438,10 @@ class Migration(migrations.Migration):
(
'operation',
models.CharField(
- choices=[('+', 'Plus'), ('-', 'Minus')],
+ choices=[('+', 'Plus'), ('-', 'Minus'), ('r', 'Replace')],
default='+',
max_length=1,
- null=True,
+ null=False,
),
),
(
@@ -455,7 +453,6 @@ class Migration(migrations.Migration):
null=True,
),
),
- ('replace', models.BooleanField(default=False)),
('need_log_to_apply', models.BooleanField(default=False, null=True)),
(
'slot_config',
@@ -488,10 +485,10 @@ class Migration(migrations.Migration):
(
'operation',
models.CharField(
- choices=[('+', 'Plus'), ('-', 'Minus')],
+ choices=[('+', 'Plus'), ('-', 'Minus'), ('r', 'Replace')],
default='+',
max_length=1,
- null=True,
+ null=False,
),
),
(
@@ -503,7 +500,6 @@ class Migration(migrations.Migration):
null=True,
),
),
- ('replace', models.BooleanField(default=False)),
('need_log_to_apply', models.BooleanField(default=False, null=True)),
(
'slot_config',
@@ -536,10 +532,10 @@ class Migration(migrations.Migration):
(
'operation',
models.CharField(
- choices=[('+', 'Plus'), ('-', 'Minus')],
+ choices=[('+', 'Plus'), ('-', 'Minus'), ('r', 'Replace')],
default='+',
max_length=1,
- null=True,
+ null=False,
),
),
(
@@ -551,7 +547,6 @@ class Migration(migrations.Migration):
null=True,
),
),
- ('replace', models.BooleanField(default=False)),
('need_log_to_apply', models.BooleanField(default=False, null=True)),
(
'slot_config',
@@ -584,10 +579,10 @@ class Migration(migrations.Migration):
(
'operation',
models.CharField(
- choices=[('+', 'Plus'), ('-', 'Minus')],
+ choices=[('+', 'Plus'), ('-', 'Minus'), ('r', 'Replace')],
default='+',
max_length=1,
- null=True,
+ null=False,
),
),
(
@@ -599,7 +594,6 @@ class Migration(migrations.Migration):
null=True,
),
),
- ('replace', models.BooleanField(default=False)),
('need_log_to_apply', models.BooleanField(default=False, null=True)),
(
'slot_config',
@@ -631,10 +625,10 @@ class Migration(migrations.Migration):
(
'operation',
models.CharField(
- choices=[('+', 'Plus'), ('-', 'Minus')],
+ choices=[('+', 'Plus'), ('-', 'Minus'), ('r', 'Replace')],
default='+',
max_length=1,
- null=True,
+ null=False,
),
),
(
@@ -646,7 +640,6 @@ class Migration(migrations.Migration):
null=True,
),
),
- ('replace', models.BooleanField(default=False)),
('need_log_to_apply', models.BooleanField(default=False, null=True)),
(
'slot_config',
@@ -678,10 +671,10 @@ class Migration(migrations.Migration):
(
'operation',
models.CharField(
- choices=[('+', 'Plus'), ('-', 'Minus')],
+ choices=[('+', 'Plus'), ('-', 'Minus'), ('r', 'Replace')],
default='+',
max_length=1,
- null=True,
+ null=False,
),
),
(
@@ -693,7 +686,6 @@ class Migration(migrations.Migration):
null=True,
),
),
- ('replace', models.BooleanField(default=False)),
('need_log_to_apply', models.BooleanField(default=False, null=True)),
(
'slot_config',
diff --git a/wger/manager/migrations/0019_flexible_routines_migration.py b/wger/manager/migrations/0019_flexible_routines_migration.py
index 5dfaaa504..1c997f3e2 100644
--- a/wger/manager/migrations/0019_flexible_routines_migration.py
+++ b/wger/manager/migrations/0019_flexible_routines_migration.py
@@ -27,6 +27,8 @@ def migrate_routines(apps) -> dict[int, Any]:
RiRConfig = apps.get_model('manager', 'RiRConfig')
RestConfig = apps.get_model('manager', 'RestConfig')
+ REPLACE_OP = 'r'
+
workouts_to_routines = {}
for workout in Workout.objects.all():
@@ -92,7 +94,7 @@ def migrate_routines(apps) -> dict[int, Any]:
slot_config=slot_config,
value=setting.weight,
iteration=1,
- replace=True,
+ operation=REPLACE_OP,
).save()
if setting.reps:
@@ -100,7 +102,7 @@ def migrate_routines(apps) -> dict[int, Any]:
slot_config=slot_config,
value=setting.reps,
iteration=1,
- replace=True,
+ operation=REPLACE_OP,
).save()
if setting.rir:
@@ -108,21 +110,21 @@ def migrate_routines(apps) -> dict[int, Any]:
slot_config=slot_config,
value=setting.rir,
iteration=1,
- replace=True,
+ operation=REPLACE_OP,
).save()
RestConfig(
slot_config=slot_config,
value=120,
iteration=1,
- replace=True,
+ operation=REPLACE_OP,
).save()
SetsConfig(
slot_config=slot_config,
value=set_obj.sets,
iteration=1,
- replace=True,
+ operation=REPLACE_OP,
).save()
routine.first_day = day_dict[1]
diff --git a/wger/manager/models/abstract_config.py b/wger/manager/models/abstract_config.py
index b4bac66ff..83ce32f70 100644
--- a/wger/manager/models/abstract_config.py
+++ b/wger/manager/models/abstract_config.py
@@ -17,10 +17,13 @@
# Django
from django.db import models
+from wger.utils.context_processor import processor
+
class OperationChoices(models.TextChoices):
PLUS = '+'
MINUS = '-'
+ REPLACE = 'r'
class StepChoices(models.TextChoices):
@@ -57,7 +60,7 @@ class AbstractChangeConfig(models.Model):
operation = models.CharField(
choices=OperationChoices.choices,
max_length=1,
- default=OperationChoices.PLUS,
+ default=OperationChoices.REPLACE,
null=True,
)
"""The operation"""
@@ -66,18 +69,10 @@ class AbstractChangeConfig(models.Model):
choices=StepChoices.choices,
max_length=10,
default=StepChoices.ABSOLUTE,
- null=True,
+ null=False,
)
"""The step by which the change will happen"""
- replace = models.BooleanField(
- default=False,
- )
- """
- Flag indicating that there is no increase, but that the value will simply
- be replaced with the new one
- """
-
need_log_to_apply = models.BooleanField(
default=False,
null=True,
@@ -87,22 +82,41 @@ class AbstractChangeConfig(models.Model):
apply the rules anyway
"""
+ @property
+ def replace(self):
+ """
+ Flag indicating that there is no increase, but that the value will simply
+ be replaced with the new one
+ """
+ return self.operation == OperationChoices.REPLACE
+
def save(self, **kwargs):
- # Cleanup some combinations. While these would be ignored in the
- # calculations anyway, this makes it cleaner
+ """
+ Cleanup some combinations. While these would be ignored in the
+ calculations anyway, this makes it cleaner
+ """
# Override values for the first iteration.
if self.iteration == 1:
- self.replace = True
+ self.operation = OperationChoices.REPLACE
# Override values for replace
if self.replace:
self.need_log_to_apply = None
self.step = None
- self.operation = None
super().save(**kwargs)
+ def delete(self, using=None, keep_parents=False):
+ """
+ There must be a config object for the first iteration
+ """
+
+ if self.iteration == 1:
+ return
+
+ return super().delete(using=using, keep_parents=keep_parents)
+
def get_owner_object(self):
"""
Config has no owner information