Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add some filtersets
Roland Geider939ff94cd4e7
diff --git a/wger/trophies/api/filtersets.py b/wger/trophies/api/filtersets.pyindex f30ff9c9f..911e2d7e6 100644--- a/wger/trophies/api/filtersets.py+++ b/wger/trophies/api/filtersets.py@@ -37,6 +37,7 @@ class TrophyFilterSet(filters.FilterSet):'is_active': ['exact'],'is_hidden': ['exact'],'is_progressive': ['exact'],+ 'is_repeatable': ['exact'],}@@ -49,7 +50,11 @@ class UserTrophyFilterSet(filters.FilterSet):model = UserTrophyfields = {'id': ['exact', 'in'],- 'trophy': ['exact', 'in'],'earned_at': ['exact', 'gt', 'gte', 'lt', 'lte'],'is_notified': ['exact'],+ 'trophy': ['exact', 'in'],+ 'trophy__is_active': ['exact'],+ 'trophy__is_hidden': ['exact'],+ 'trophy__is_repeatable': ['exact'],+ 'trophy__trophy_type': ['exact', 'in'],}diff --git a/wger/trophies/api/serializers.py b/wger/trophies/api/serializers.pyindex 120947fa3..bf5e073e2 100644--- a/wger/trophies/api/serializers.py+++ b/wger/trophies/api/serializers.py@@ -57,6 +57,7 @@ class TrophySerializer(serializers.ModelSerializer):'trophy_type','is_hidden','is_progressive',+ 'is_repeatable','order',)read_only_fields = fields@@ -98,6 +99,7 @@ class UserTrophySerializer(serializers.ModelSerializer):'earned_at','progress','is_notified',+ 'context_data',)read_only_fields = fieldsdiff --git a/wger/trophies/api/views.py b/wger/trophies/api/views.pyindex c3e9723aa..675b79fcb 100644--- a/wger/trophies/api/views.py+++ b/wger/trophies/api/views.py@@ -121,17 +121,18 @@ class TrophyViewSet(viewsets.ReadOnlyModelViewSet):return Response([])include_hidden = request.user.is_staff+ include_repeatable = request.GET.get('include_repeatable', 'false') == 'true'progress_data = TrophyService.get_all_trophy_progress(request.user,include_hidden=include_hidden,+ include_repeatable=include_repeatable,)serializer = TrophyProgressSerializer(progress_data,many=True,-# Important: provide request in context for image URL building- context={'request': request}+ context={'request': request},)return Response(serializer.data)@@ -151,7 +152,7 @@ class UserTrophyViewSet(viewsets.ReadOnlyModelViewSet):serializer_class = UserTrophySerializerfilterset_class = UserTrophyFilterSet- ordering_fields = ['earned_at', 'trophy__name']+ ordering_fields = ['earned_at', 'trophy__trophy_type', 'trophy__name']ordering = ['-earned_at']is_private = Truediff --git a/wger/trophies/services/trophy.py b/wger/trophies/services/trophy.pyindex 999f92e8c..5cbc229cd 100644--- a/wger/trophies/services/trophy.py+++ b/wger/trophies/services/trophy.py@@ -35,7 +35,6 @@ from wger.trophies.models import (UserTrophy,)-logger = logging.getLogger(__name__)# Trophy settings from WGER_SETTINGS (defined in settings_global.py)@@ -180,7 +179,12 @@ class TrophyService:)@classmethod- def get_all_trophy_progress(cls, user: User, include_hidden: bool = False) -> List[Dict]:+ def get_all_trophy_progress(+ cls,+ user: User,+ include_hidden: bool = False,+ include_repeatable: bool = False,+ ) -> List[Dict]:"""Get all trophies with progress information for a user.@@ -190,6 +194,7 @@ class TrophyService:Args:user: The user to get trophy progress forinclude_hidden: If True, include hidden trophies even if not earned+ include_repeatable: If True, include repeatable (PR) trophiesReturns:List of dicts with trophy info and progress@@ -201,7 +206,11 @@ class TrophyService:# Get user's earned trophiesearned = {- ut.trophy_id: ut for ut in UserTrophy.objects.filter(user=user).select_related('trophy')+ ut.trophy_id: ut+ for ut in UserTrophy.objects.filter(+ user=user,+ trophy__is_repeatable=include_repeatable,+ ).select_related('trophy')}for trophy in trophies: