From f89c6cff300634ab9289c8bab958b65e2df03698 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 16 Nov 2022 18:32:50 +0000 Subject: [PATCH] Allow sorting by pinball score --- apiserver/apiserver/api/models.py | 2 +- apiserver/apiserver/api/serializers.py | 5 +++++ apiserver/apiserver/api/views.py | 4 ++++ webclient/src/Members.js | 14 ++++++++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apiserver/apiserver/api/models.py b/apiserver/apiserver/api/models.py index 6e36e48..66fee6a 100644 --- a/apiserver/apiserver/api/models.py +++ b/apiserver/apiserver/api/models.py @@ -246,7 +246,7 @@ class PinballScore(models.Model): # no history - MY_FIELDS = ['started_at', 'game_id', 'player', 'score'] + MY_FIELDS = ['started_at', 'game_id', 'player', 'score', 'user'] def __str__(self): return str(self.started_at) diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index 96ffcd7..e576bb4 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -183,6 +183,7 @@ class TransactionSerializer(serializers.ModelSerializer): # hide info for non-vetted members so someone sitting # in our parking lot can't scrape all our info class OtherMemberSerializer(serializers.ModelSerializer): + pinball_score = serializers.IntegerField(required=False) last_name = serializers.SerializerMethodField() class Meta: @@ -196,6 +197,7 @@ class OtherMemberSerializer(serializers.ModelSerializer): 'application_date', 'photo_small', 'public_bio', + 'pinball_score', ] def get_last_name(self, obj): @@ -206,6 +208,8 @@ class OtherMemberSerializer(serializers.ModelSerializer): # vetted member viewing other members class VettedOtherMemberSerializer(serializers.ModelSerializer): + pinball_score = serializers.IntegerField(required=False) + class Meta: model = models.Member fields = [ @@ -218,6 +222,7 @@ class VettedOtherMemberSerializer(serializers.ModelSerializer): 'photo_small', 'photo_large', 'public_bio', + 'pinball_score', ] diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py index df2e108..f24ffe7 100644 --- a/apiserver/apiserver/api/views.py +++ b/apiserver/apiserver/api/views.py @@ -132,6 +132,10 @@ class SearchViewSet(Base, Retrieve): ).exclude(last_scanned__isnull=True).order_by('-last_scanned') else: queryset = [] + elif sort == 'pinball_score': + queryset = queryset.annotate( + pinball_score=Max('user__scores__score'), + ).exclude(pinball_score__isnull=True).order_by('-pinball_score') elif sort == 'everyone': queryset = queryset.annotate(Count('user__transactions')).order_by('-user__transactions__count', 'id') elif sort == 'best_looking': diff --git a/webclient/src/Members.js b/webclient/src/Members.js index 9af98aa..8433a25 100644 --- a/webclient/src/Members.js +++ b/webclient/src/Members.js @@ -11,6 +11,7 @@ import AbortController from 'abort-controller'; const memberSorts = { recently_vetted: 'Recently Vetted', last_scanned: 'Last Scanned', + pinball_score: 'Pinball Score', newest_active: 'Newest', //newest_overall: 'Newest Overall', oldest_active: 'Oldest', @@ -227,8 +228,17 @@ export function Members(props) { {x.member.preferred_name} {x.member.last_name} - Status: {x.member.status || 'Unknown'} - Joined: {x.member.application_date || 'Unknown'} + {sort === 'pinball_score' ? + <> + Score: {x.member.pinball_score || 'Unknown'} + Rank: {i === 0 ? 'Pinball Wizard' : 'Not the Pinball Wizard'} + + : + <> + Status: {x.member.status || 'Unknown'} + Joined: {x.member.application_date || 'Unknown'} + + } ID: {x.member.id}