Skip to content

Commit

Permalink
Merge pull request #1825 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
get logs to public
  • Loading branch information
adnankattekaden authored Dec 14, 2023
2 parents 3895773 + 75f744e commit cb834ca
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
14 changes: 12 additions & 2 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import requests
from django.db import models
from django.db.models import Case, When, Value, CharField, Count, Q, F, Sum
from django.db.models import Subquery, OuterRef
from django.db.models import Sum, F, Case, When, Value, CharField, Count, Q
from django.db.models.functions import Coalesce
from rest_framework.views import APIView

Expand All @@ -15,7 +15,8 @@
from utils.response import CustomResponse
from utils.types import IntegrationType, OrganizationType, RoleType
from utils.utils import CommonUtils
from .serializer import StudentInfoSerializer, CollegeInfoSerializer, LearningCircleEnrollmentSerializer
from .serializer import StudentInfoSerializer, CollegeInfoSerializer, LearningCircleEnrollmentSerializer, \
UserLeaderboardSerializer


class LcDashboardAPI(APIView):
Expand Down Expand Up @@ -578,3 +579,12 @@ def get(self, request):
user_karma['igs'] = []

return CustomResponse(response=user_karma_by_ig).get_success_response()


class BekenAPI(APIView):
def get(self, request):
user_info = User.objects.exclude(
user_role_link_user__role__title__in=[RoleType.ENABLER.value, RoleType.MENTOR.value]).order_by(
'-wallet_user__karma')[:100]
data = UserLeaderboardSerializer(user_info, many=True)
return CustomResponse(response=data.data).get_success_response()
29 changes: 29 additions & 0 deletions api/common/serializer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from rest_framework import serializers

from db.user import User


class StudentInfoSerializer(serializers.Serializer):
first_name = serializers.CharField()
Expand Down Expand Up @@ -29,3 +31,30 @@ class LearningCircleEnrollmentSerializer(serializers.Serializer):
organisation = serializers.CharField()
district = serializers.CharField(allow_null=True)
karma_earned = serializers.IntegerField()


class UserLeaderboardSerializer(serializers.ModelSerializer):
rank = serializers.SerializerMethodField()
interest_groups = serializers.SerializerMethodField()
organizations = serializers.SerializerMethodField()
karma = serializers.IntegerField(source="wallet_user.karma")
fullname = serializers.SerializerMethodField()

class Meta:
model = User
fields = (
'fullname',
"rank",
"karma",
"interest_groups",
"organizations",
)

def get_fullname(self, obj):
return obj.fullname

def get_organizations(self, obj):
return obj.user_organization_link_user.all().values_list("org__title", flat=True)

def get_interest_groups(self, obj):
return obj.user_ig_link_user.all().values_list("ig__name", flat=True)
2 changes: 2 additions & 0 deletions api/common/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
path('profile-pic/<str:muid>/', common_views.UserProfilePicAPI.as_view()),
path('list-ig/', common_views.ListIGAPI.as_view()),
path('list-ig-top100/', common_views.ListTopIgUsersAPI.as_view()),

path('leaderboard/top-100/', common_views.BekenAPI.as_view()),
]
2 changes: 1 addition & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
path('protected/', include('api.protected.urls')),
path('hackathon/', include('api.hackathon.urls')),
path('notification/', include('api.notification.urls')),
path('get-log/', include('api.common.urls')),
path('public/', include('api.common.urls')),
path('top100/', include('api.top100_coders.urls')),

path("__debug__/", include(debug_toolbar.urls)),
Expand Down

0 comments on commit cb834ca

Please sign in to comment.