Skip to content

Commit

Permalink
Merge pull request #2068 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
Merge dev to dev-server
  • Loading branch information
jelanmathewjames authored Jun 16, 2024
2 parents 3b3fe88 + 38ac837 commit 6615eeb
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 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 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")
)

0 comments on commit 6615eeb

Please sign in to comment.