Skip to content

Commit

Permalink
Merge pull request #2073 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
Dev server
  • Loading branch information
jelanmathewjames authored Jun 16, 2024
2 parents cbb4a75 + 399b448 commit 7b688d0
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 6 deletions.
61 changes: 58 additions & 3 deletions api/launchpad/launchpad_views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.db.models import Sum, Max, Prefetch, F, OuterRef, Subquery, IntegerField
from django.db.models import Sum, Max, Prefetch, F, OuterRef, Subquery, IntegerField, Count, Q

from rest_framework.views import APIView

from .serializers import LaunchpadLeaderBoardSerializer, LaunchpadParticipantsSerializer
from .serializers import LaunchpadLeaderBoardSerializer, LaunchpadParticipantsSerializer, CollegeDataSerializer
from utils.response import CustomResponse
from utils.utils import CommonUtils
from db.user import User, UserRoleLink
from db.organization import UserOrganizationLink
from db.organization import UserOrganizationLink, Organization
from db.task import KarmaActivityLog


Expand Down Expand Up @@ -174,3 +174,58 @@ def get(self, request):
}

return CustomResponse(response=level_counts).get_success_response()

class CollegeData(APIView):
def get(self, request):
allowed_levels = [
"IEEE Launchpad Level 1",
"IEEE Launchpad Level 2",
"IEEE Launchpad Level 3",
"IEEE Launchpad Level 4"
]

org = Organization.objects.filter(
org_type="College",
).prefetch_related(
Prefetch(
"user_organization_link_org",
queryset=UserOrganizationLink.objects.filter(
user__user_role_link_user__role__title__in=allowed_levels
)
)
).filter(
user_organization_link_org__user__user_role_link_user__role__title__in=allowed_levels
).annotate(
district_name=F("district__name"),
state=F("district__zone__state__name"),
total_users=Count("user_organization_link_org__user"),
level1 = Count(
"user_organization_link_org__user",
filter=Q(user_organization_link_org__user__user_role_link_user__role__title="IEEE Launchpad Level 1")
),
level2 = Count(
"user_organization_link_org__user",
filter=Q(user_organization_link_org__user__user_role_link_user__role__title="IEEE Launchpad Level 2")
),
level3 = Count(
"user_organization_link_org__user",
filter=Q(user_organization_link_org__user__user_role_link_user__role__title="IEEE Launchpad Level 3")
),
level4 = Count(
"user_organization_link_org__user",
filter=Q(user_organization_link_org__user__user_role_link_user__role__title="IEEE Launchpad Level 4")
)
).order_by("-total_users")

paginated_queryset = CommonUtils.get_paginated_queryset(
org,
request,
["title", "district_name", "state"]
)

serializer = CollegeDataSerializer(
paginated_queryset.get("queryset"), many=True
)
return CustomResponse().paginated_response(
data=serializer.data, pagination=paginated_queryset.get("pagination")
)
25 changes: 24 additions & 1 deletion api/launchpad/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework import serializers

from db.user import User
from db.organization import UserOrganizationLink
from db.organization import UserOrganizationLink, Organization
from db.task import KarmaActivityLog


Expand Down Expand Up @@ -72,3 +72,26 @@ class LaunchpadParticipantsSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ("full_name", "level", "org", "district_name", "state")


class CollegeDataSerializer(serializers.ModelSerializer):
district_name = serializers.CharField()
state = serializers.CharField()
total_users = serializers.IntegerField()
level1 = serializers.IntegerField()
level2 = serializers.IntegerField()
level3 = serializers.IntegerField()
level4 = serializers.IntegerField()

class Meta:
model = Organization
fields = (
"title",
"district_name",
"state",
"total_users",
"level1",
"level2",
"level3",
"level4"
)
5 changes: 3 additions & 2 deletions api/launchpad/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
urlpatterns = [
path('leaderboard/', launchpad_views.Leaderboard.as_view()),
path('list-participants/', launchpad_views.ListParticipantsAPI.as_view()),
path('launchpad-details/', launchpad_views.LaunchpadDetailsCount.as_view())
]
path('launchpad-details/', launchpad_views.LaunchpadDetailsCount.as_view()),
path('college-data/', launchpad_views.CollegeData.as_view())
]

0 comments on commit 7b688d0

Please sign in to comment.