Self hosted FLOSS fitness/workout, nutrition and weight tracker
Properly filter out PR trophies
Roland Geiderb28f1a2faf8b
diff --git a/wger/trophies/services/trophy.py b/wger/trophies/services/trophy.pyindex 45cbfae2f..c01ec5876 100644--- a/wger/trophies/services/trophy.py+++ b/wger/trophies/services/trophy.py@@ -203,7 +203,10 @@ class TrophyService:result = []# Get all active trophies- trophies = Trophy.objects.filter(is_active=True).order_by('order', 'name')+ trophies = Trophy.objects.filter(is_active=True)+ if not include_repeatable:+ trophies = trophies.filter(is_repeatable=False)+ trophies = trophies.order_by('order', 'name')# Get user's earned trophiesearned = {diff --git a/wger/trophies/tests/test_integration.py b/wger/trophies/tests/test_integration.pyindex 1e1fbf91d..d0d932a92 100644--- a/wger/trophies/tests/test_integration.py+++ b/wger/trophies/tests/test_integration.py@@ -261,6 +261,20 @@ class TrophyIntegrationTestCase(WgerTestCase):self.assertEqual(lifter_progress['current_value'], 2500)self.assertEqual(lifter_progress['target_value'], 5000)+ def test_get_all_trophy_progress_excludes_repeatable_by_default(self):+ """Repeatable (PR) trophies are excluded from progress by default"""+ progress_list = TrophyService.get_all_trophy_progress(self.user)++ pr_in_list = any(p['trophy'].id == self.personal_record_trophy.id for p in progress_list)+ self.assertFalse(pr_in_list)++ def test_get_all_trophy_progress_includes_repeatable_when_requested(self):+ """Repeatable (PR) trophies are included when include_repeatable=True"""+ progress_list = TrophyService.get_all_trophy_progress(self.user, include_repeatable=True)++ pr_in_list = any(p['trophy'].id == self.personal_record_trophy.id for p in progress_list)+ self.assertTrue(pr_in_list)+def test_trophy_not_awarded_twice(self):"""Test same trophy is not awarded twice"""# Create user statistics