Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Respect the trophy skip-flag for PR trophies as well

Roland Geider9fe6c75598bc
diff --git a/wger/trophies/signals.py b/wger/trophies/signals.py
index 3a42e107a..719017e79 100644
--- a/wger/trophies/signals.py
+++ b/wger/trophies/signals.py
@@ -71,12 +71,6 @@ def _trigger_trophy_evaluation(user_id: int):
evaluate_user_trophies_task.delay(user_id)
else:
# Celery not available or configured - evaluate synchronously
- # Django
- from django.contrib.auth.models import User
-
- # wger
- from wger.trophies.services import TrophyService
-
try:
user = User.objects.get(id=user_id)
TrophyService.evaluate_all_trophies(user)
@@ -107,18 +101,19 @@ def workout_log_saved(sender, instance: WorkoutLog, created: bool, **kwargs):
workout_log=instance,
)
- # Personal Record award
- trophy = Trophy.objects.get(name='Personal Record', is_active=True)
- checker = CheckerRegistry.create_checker(instance.user, trophy)
- checker.params = {'log': instance}
- existing = UserTrophy.objects.filter(
- user=instance.user, trophy=trophy, context_data__log_id=str(instance.id)
- ).exists()
- if not existing and checker and checker.check():
- context = checker.get_context_data()
- TrophyService.award_trophy(
- instance.user, trophy, progress=100.0, context_data=context
- )
+ # Personal Record award (respect the same skip rules as full evaluation)
+ if not TrophyService.should_skip_user(instance.user):
+ trophy = Trophy.objects.get(name='Personal Record', is_active=True)
+ checker = CheckerRegistry.create_checker(instance.user, trophy)
+ checker.params = {'log': instance}
+ existing = UserTrophy.objects.filter(
+ user=instance.user, trophy=trophy, context_data__log_id=str(instance.id)
+ ).exists()
+ if not existing and checker and checker.check():
+ context = checker.get_context_data()
+ TrophyService.award_trophy(
+ instance.user, trophy, progress=100.0, context_data=context
+ )
else:
# Edited log - full recalculation for accuracy
diff --git a/wger/trophies/tests/test_integration.py b/wger/trophies/tests/test_integration.py
index 1ba674371..b6f5ac30f 100644
--- a/wger/trophies/tests/test_integration.py
+++ b/wger/trophies/tests/test_integration.py
@@ -163,6 +163,18 @@ class TrophyIntegrationTestCase(WgerTestCase):
context = pr_trophies.first().context_data
self.assertIsNotNone(context)
+ def test_personal_record_not_awarded_when_user_disabled_trophies(self):
+ """No Personal Record is awarded on log creation if the user disabled trophies"""
+ UserTrophy.objects.filter(user=self.user).delete()
+ self.user.userprofile.trophies_enabled = False
+ self.user.userprofile.save()
+
+ exercise = Exercise.objects.create(category=ExerciseCategory.objects.create(name='pr_cat'))
+ WorkoutLog.objects.create(user=self.user, exercise=exercise, repetitions=10, weight=100)
+
+ pr_trophies = UserTrophy.objects.filter(user=self.user, trophy=self.personal_record_trophy)
+ self.assertEqual(pr_trophies.count(), 0)
+
def test_lifting_5000kg_earns_lifter_trophy(self):
"""Test that lifting 5000kg total earns Lifter trophy"""
# Create user statistics