Skip to content

Commit

Permalink
Merge pull request #1990 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
update launchpad leaderboard
  • Loading branch information
jelanmathewjames authored Jun 1, 2024
2 parents 8c20cf3 + de16de1 commit 5521f6f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
20 changes: 3 additions & 17 deletions api/launchpad/launchpad_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
When,
Case,
IntegerField,
CharField,
F,
OuterRef,
Subquery,
Expand All @@ -28,7 +29,6 @@ def get(self, request):
user=OuterRef("id"),
task__event="launchpad",
appraiser_approved=True,
task__hashtag="#lp24-introduction",
)
.annotate(total_karma=Sum("karma"))
.values("total_karma")
Expand All @@ -39,35 +39,21 @@ def get(self, request):
karma_activity_log_user__appraiser_approved=True,
karma_activity_log_user__task__hashtag="#lp24-introduction",
)
.prefetch_related(
Prefetch(
"user_organization_link_user__org",
queryset=Organization.objects.filter(
org_type__in=["College", "School", "Company"]
)
.select_related("district", "district_zone_state_name")
.all(),
)
)
.annotate(
karma=Subquery(karma_subquery, output_field=IntegerField()),
time_=Max("karma_activity_log_user__created_at"),
org=F("user_organization_link_user__org__title"),
district_name=F("district__name"),
state=F("district__zone__state__name"),
)
.values("full_name", "karma", "org", "district_name", "state", "time_")
.order_by("-karma", "time_")
)

paginated_queryset = CommonUtils.get_paginated_queryset(
users,
request,
["karma", "org", "district_name", "state", "time_"],
["karma", "org", "district", "state", "time_"],
sort_fields={
"karma": "karma",
"org": "org",
"district_name": "district_name",
"district": "district",
"state": "state",
"time_": "time_",
},
Expand Down
6 changes: 3 additions & 3 deletions api/launchpad/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

class LaunchpadLeaderBoardSerializer(serializers.ModelSerializer):
karma = serializers.IntegerField()
org = serializers.CharField()
district_name = serializers.CharField()
state = serializers.CharField()
org = serializers.ReadOnlyField(source="user_organization_link_user.org.title")
district_name = serializers.ReadOnlyField(source="user_organization_link_user.org.district.name")
state = serializers.ReadOnlyField(source="user_organization_link_user.org.district.zone.state.name")

class Meta:
model = User
Expand Down

0 comments on commit 5521f6f

Please sign in to comment.