Self hosted FLOSS fitness/workout, nutrition and weight tracker
Keep the slot order in SlotData.exercises
Ian Andersond7be78e110de
diff --git a/wger/manager/dataclasses.py b/wger/manager/dataclasses.pyindex f5aca5e8c..f2edd5d91 100644--- a/wger/manager/dataclasses.py+++ b/wger/manager/dataclasses.py@@ -182,12 +182,8 @@ class SlotData:@propertydef exercises(self) -> List[int]:- out = set()-- for set_config in self.sets:- out.add(set_config.exercise)-- return list(out)+ # dict.fromkeys removes duplicates and keeps the order of the sets+ return list(dict.fromkeys(set_config.exercise for set_config in self.sets))@propertydef is_superset(self) -> bool:diff --git a/wger/manager/tests/test_set_config_data.py b/wger/manager/tests/test_set_config_data.pyindex cafa4a3e9..65f1ac02a 100644--- a/wger/manager/tests/test_set_config_data.py+++ b/wger/manager/tests/test_set_config_data.py@@ -20,6 +20,7 @@ from wger.core.tests.base_testcase import WgerTestCasefrom wger.manager.api.serializers import SetConfigDataSerializerfrom wger.manager.dataclasses import (SetConfigData,+ SlotData,round_value,)from wger.manager.models.abstract_config import MAX_COMPOUND_RIR@@ -187,3 +188,21 @@ class SetConfigDataTestCase(WgerTestCase):data = SetConfigDataSerializer(self.config).dataself.assertEqual(Decimal(data['rir']), capped_rir)+++class SlotDataExercisesTestCase(WgerTestCase):+ """+ Test that the list of exercises of a slot keeps the order of its sets+ """++ def test_exercises_keep_set_order(self):+ # Two rounds of a circuit, the ids are chosen so that a plain set+ # would return them in a different order+ exercise_ids = [2034, 2115, 974, 2108, 2116] * 2+ slot_data = SlotData(+ comment='',+ sets=[SetConfigData(exercise=i, sets=1) for i in exercise_ids],+ )++ self.assertEqual(slot_data.exercises, [2034, 2115, 974, 2108, 2116])+ self.assertTrue(slot_data.is_superset)