Self hosted FLOSS fitness/workout, nutrition and weight tracker
Fix edge case when grouping exercises
Roland Geider5c1489f0ac90
diff --git a/wger/manager/models/day.py b/wger/manager/models/day.pyindex 37ae64d58..6a9e00773 100644--- a/wger/manager/models/day.py+++ b/wger/manager/models/day.py@@ -172,7 +172,7 @@ class Day(models.Model):# one exerciseelse:exercise_id = exercises[0]- if exercise_id != last_exercise_id:+ if current_slot is None or exercise_id != last_exercise_id:current_slot = slot_dataout.append(slot_data)last_exercise_id = exercise_iddiff --git a/wger/manager/tests/test_day.py b/wger/manager/tests/test_day.pyindex 1174e043d..2530a3e31 100644--- a/wger/manager/tests/test_day.py+++ b/wger/manager/tests/test_day.py@@ -19,7 +19,11 @@ from decimal import Decimal# wgerfrom wger.core.tests.base_testcase import WgerTestCasefrom wger.manager.dataclasses import SetConfigData-from wger.manager.models import Day+from wger.manager.models import (+ Day,+ Slot,+ SlotEntry,+)class DaySlotTestCase(WgerTestCase):@@ -182,6 +186,23 @@ class DaySlotTestCase(WgerTestCase):),)+ def test_slots_display_mode_superset_resets_grouping(self):+ """+ Test that a superset between two single-exercise slots of the same+ exercise does not crash the display-mode grouping+ """++ day = Day.objects.get(pk=1)++ # Prepend a single-exercise slot for the same exercise used after the+ # superset, producing the sequence: single(3), superset(1, 2), single(3)+ slot = Slot.objects.create(day=day, order=0, comment='leading slot')+ SlotEntry.objects.create(slot=slot, exercise_id=3, order=1)++ slots = day.get_slots_display_mode(1)++ self.assertEqual([s.exercises for s in slots], [[3], [1, 2], [3]])+class DayModelTestCase(WgerTestCase):"""