Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Move toggle to fit to week to routine object

Roland Geiderb2b56f042bf1
diff --git a/wger/manager/api/serializers.py b/wger/manager/api/serializers.py
index 234881ec5..7fad3aea0 100644
--- a/wger/manager/api/serializers.py
+++ b/wger/manager/api/serializers.py
@@ -55,6 +55,7 @@ class RoutineSerializer(serializers.ModelSerializer):
'created',
'start',
'end',
+ 'fit_in_week',
)
@@ -72,7 +73,6 @@ class DaySerializer(serializers.ModelSerializer):
'name',
'description',
'is_rest',
- 'last_day_in_week',
'need_logs_to_advance',
'type',
)
@@ -246,7 +246,6 @@ class DayStructureSerializer(serializers.ModelSerializer):
'name',
'description',
'is_rest',
- 'last_day_in_week',
'need_logs_to_advance',
'slots',
)
@@ -268,6 +267,7 @@ class RoutineStructureSerializer(serializers.ModelSerializer):
'created',
'start',
'end',
+ 'fit_in_week',
'days',
)
diff --git a/wger/manager/fixtures/test-routine-data.json b/wger/manager/fixtures/test-routine-data.json
index 3faf38591..57c352983 100644
--- a/wger/manager/fixtures/test-routine-data.json
+++ b/wger/manager/fixtures/test-routine-data.json
@@ -6,9 +6,10 @@
"user": 1,
"name": "A test routine",
"description": "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna",
- "created": "2024-03-01T23:34:30",
+ "created": "2024-03-01T23:34:30+01:00",
"start": "2024-03-01",
- "end": "2024-06-01"
+ "end": "2024-06-01",
+ "fit_in_week": false
}
},
{
@@ -18,9 +19,10 @@
"user": 2,
"name": "Empty routine",
"description": "",
- "created": "2024-03-01T23:34:30",
+ "created": "2024-03-01T23:34:30+01:00",
"start": "2024-03-01",
- "end": "2024-03-01"
+ "end": "2024-03-01",
+ "fit_in_week": false
}
},
{
@@ -30,9 +32,10 @@
"user": 2,
"name": "Another empty routine",
"description": "",
- "created": "2024-03-01T23:34:30",
+ "created": "2024-03-01T23:34:30+01:00",
"start": "2024-03-01",
- "end": "2024-03-01"
+ "end": "2024-03-01",
+ "fit_in_week": false
}
},
{
@@ -40,7 +43,7 @@
"model": "manager.day",
"fields": {
"routine": 1,
- "order": 2,
+ "order": 1,
"is_rest": false
}
},
@@ -58,7 +61,7 @@
"model": "manager.day",
"fields": {
"routine": 1,
- "order": 1,
+ "order": 2,
"is_rest": false
}
},
@@ -161,7 +164,7 @@
"iteration": 1,
"value": 5,
"operation": "r",
- "step": null,
+ "step": "abs",
"need_log_to_apply": false
}
},
@@ -173,7 +176,7 @@
"iteration": 1,
"value": 2,
"operation": "r",
- "step": null,
+ "step": "abs",
"need_log_to_apply": false
}
},
@@ -185,7 +188,7 @@
"iteration": 1,
"value": 5,
"operation": "r",
- "step": null,
+ "step": "abs",
"need_log_to_apply": false
}
},
@@ -197,7 +200,7 @@
"iteration": 1,
"value": 3,
"operation": "r",
- "step": null,
+ "step": "abs",
"need_log_to_apply": false
}
},
@@ -209,7 +212,7 @@
"iteration": 1,
"value": 80,
"operation": "r",
- "step": null,
+ "step": "abs",
"need_log_to_apply": false
}
},
@@ -221,7 +224,7 @@
"iteration": 1,
"value": 20,
"operation": "r",
- "step": null,
+ "step": "abs",
"need_log_to_apply": false
}
},
@@ -233,7 +236,7 @@
"iteration": 1,
"value": 80,
"operation": "r",
- "step": null,
+ "step": "abs",
"need_log_to_apply": false
}
},
@@ -245,7 +248,7 @@
"iteration": 1,
"value": 50,
"operation": "r",
- "step": null,
+ "step": "abs",
"need_log_to_apply": false
}
},
@@ -257,7 +260,7 @@
"iteration": 1,
"value": 4,
"operation": "r",
- "step": null,
+ "step": "abs",
"need_log_to_apply": false
}
},
@@ -269,7 +272,7 @@
"iteration": 1,
"value": 5,
"operation": "r",
- "step": null,
+ "step": "abs",
"need_log_to_apply": false
}
},
@@ -281,7 +284,7 @@
"iteration": 1,
"value": 6,
"operation": "r",
- "step": null,
+ "step": "abs",
"need_log_to_apply": false
}
},
@@ -293,7 +296,7 @@
"iteration": 1,
"value": 4,
"operation": "r",
- "step": null,
+ "step": "abs",
"need_log_to_apply": false
}
}
diff --git a/wger/manager/migrations/0018_flexible_routines.py b/wger/manager/migrations/0018_flexible_routines.py
index 8ab2fa48b..49e14270c 100644
--- a/wger/manager/migrations/0018_flexible_routines.py
+++ b/wger/manager/migrations/0018_flexible_routines.py
@@ -55,7 +55,6 @@ class Migration(migrations.Migration):
),
),
('is_rest', models.BooleanField(default=False)),
- ('last_day_in_week', models.BooleanField(default=False)),
('need_logs_to_advance', models.BooleanField(default=False)),
('order', models.PositiveIntegerField(default=1, verbose_name='Order')),
],
@@ -258,6 +257,10 @@ class Migration(migrations.Migration):
verbose_name='Workout template',
),
),
+ (
+ 'fit_in_week',
+ models.BooleanField(default=False),
+ )
],
options={
'ordering': ['-created'],
diff --git a/wger/manager/migrations/0019_flexible_routines_migration.py b/wger/manager/migrations/0019_flexible_routines_migration.py
index 3be4ee815..fab2ff559 100644
--- a/wger/manager/migrations/0019_flexible_routines_migration.py
+++ b/wger/manager/migrations/0019_flexible_routines_migration.py
@@ -44,6 +44,7 @@ def migrate_routines(apps) -> dict[int, Any]:
end=next_monday + timedelta(weeks=4 * 6),
is_template=workout.is_template,
is_public=workout.is_public,
+ fit_in_week=False,
)
routine.save()
diff --git a/wger/manager/models/day.py b/wger/manager/models/day.py
index 33bf4c47d..3ee943ebd 100644
--- a/wger/manager/models/day.py
+++ b/wger/manager/models/day.py
@@ -95,13 +95,6 @@ class Day(models.Model):
Needs logs to advance to the next day
"""
- last_day_in_week = models.BooleanField(
- default=False,
- )
- """
- Flag indicating that this is the last workout day in the week
- """
-
def __str__(self):
"""
Return a more human-readable representation
diff --git a/wger/manager/models/routine.py b/wger/manager/models/routine.py
index 663ded97c..4a8f71e11 100644
--- a/wger/manager/models/routine.py
+++ b/wger/manager/models/routine.py
@@ -93,6 +93,10 @@ class Routine(models.Model):
null=False,
)
+ fit_in_week = models.BooleanField(
+ default=False,
+ )
+
def get_absolute_url(self):
"""
Returns the canonical URL to view a workout
@@ -127,8 +131,6 @@ class Routine(models.Model):
def day_sequence(self):
"""
Return a sequence of days.
-
- Each day object points to the next one in the sequence till it loops back
"""
return list(self.days.all())
@@ -185,7 +187,9 @@ class Routine(models.Model):
counter[current_day] += 1
index = (index + 1) % nr_days
- if current_day.last_day_in_week:
+ # If we reach the end of the available days, check whether we want to fill up the
+ # week with empty days, unless the routine already consists of 7 training days
+ if nr_days % 7 != 0 and index == 0 and self.fit_in_week:
days_til_monday = 7 - current_date.weekday()
skip_til_date = current_date + datetime.timedelta(days=days_til_monday)
diff --git a/wger/manager/tests/test_routine.py b/wger/manager/tests/test_routine.py
index 5ee830c2d..791f967ca 100644
--- a/wger/manager/tests/test_routine.py
+++ b/wger/manager/tests/test_routine.py
@@ -145,11 +145,10 @@ class RoutineTestCase(WgerTestCase):
def test_date_sequence_week_skip(self):
"""
- Test that the last_day_in_week flag works
+ Test that the fit_in_week flag works
"""
-
- self.day3.last_day_in_week = True
- self.day3.save()
+ self.routine.fit_in_week = True
+ self.routine.save()
self.assertListEqual(
self.routine.date_sequence,