Skip to content

Commit

Permalink
Return badges sorted by highest level
Browse files Browse the repository at this point in the history
  • Loading branch information
eleurent committed Jun 26, 2024
1 parent b738475 commit 89c8f12
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/nature_go/badge/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class UserBadgeSerializer(serializers.ModelSerializer):

class Meta:
model = UserBadge
fields = ['badge', 'progress', 'highest_unlocked_level']
fields = ['badge', 'progress', 'unlocked_level']

def get_badge(self, obj):
if isinstance(obj.badge.logic, SpeciesBadgeLogic):
Expand Down
5 changes: 4 additions & 1 deletion backend/nature_go/badge/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class BadgeListView(ListAPIView):

def get_queryset(self):
update_user_badges(self.request.user)
return UserBadge.objects.filter(user=self.request.user)
queryset = UserBadge.objects.filter(user=self.request.user)
levels = ["Bronze", "Silver", "Gold"]
index_or_minus_one = lambda x: levels.index(x.unlocked_level) if x.unlocked_level in levels else -1
return sorted(queryset, key=index_or_minus_one, reverse=True)


class BadgeDetailView(RetrieveAPIView):
Expand Down

0 comments on commit 89c8f12

Please sign in to comment.