Skip to content

Commit

Permalink
Merge pull request #1873 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
public lc list
  • Loading branch information
adnankattekaden authored Dec 28, 2023
2 parents 67842f3 + 8e77e80 commit 0bc3b0d
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 3 deletions.
69 changes: 67 additions & 2 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

from db.learning_circle import LearningCircle
from db.learning_circle import UserCircleLink
from db.organization import Organization
from db.organization import Organization,Department,District,State,Country
from db.task import InterestGroup, KarmaActivityLog, UserIgLink
from db.user import User, UserRoleLink
from utils.response import CustomResponse
from utils.types import IntegrationType, OrganizationType, RoleType
from utils.utils import CommonUtils
from .serializer import StudentInfoSerializer, CollegeInfoSerializer, LearningCircleEnrollmentSerializer, \
UserLeaderboardSerializer
UserLeaderboardSerializer,OrgSerializer,DistrictSerializer,StateSerializer,CountrySerializer


class LcDashboardAPI(APIView):
Expand Down Expand Up @@ -580,3 +580,68 @@ def get(self, request):
'-wallet_user__karma')[:100]
data = UserLeaderboardSerializer(user_info, many=True)
return CustomResponse(response=data.data).get_success_response()


class LcCollegeAPI(APIView):
def get(self, request):
org_queryset = Organization.objects.filter(
Q(org_type=OrganizationType.COLLEGE.value),
Q(district_id=request.data.get("district")),
)
department_queryset = Department.objects.all()

college_serializer_data = OrgSerializer(
org_queryset, many=True
).data

department_serializer_data = OrgSerializer(
department_queryset, many=True
).data

return CustomResponse(
response={
"colleges": college_serializer_data,
"departments": department_serializer_data,
}
).get_success_response()



class LcDistrictAPI(APIView):
def get(self, request):
district = District.objects.filter(zone__state_id=request.data.get("state"))

serializer = DistrictSerializer(district, many=True)

return CustomResponse(
response={
"districts": serializer.data,
}
).get_success_response()

class LcStateAPI(APIView):
def get(self, request):
state = State.objects.filter(country_id=request.data.get("country"))
serializer = StateSerializer(state, many=True)

return CustomResponse(
response={
"states": serializer.data,
}
).get_success_response()


class LcCountryAPI(APIView):
def get(self, request):
countries = Country.objects.all()

serializer = CountrySerializer(countries, many=True)

return CustomResponse(
response={
"countries": serializer.data,
}
).get_success_response()



31 changes: 30 additions & 1 deletion api/common/serializer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from rest_framework import serializers

from db.user import User

from db.organization import (
Country,
Department,
District,
Organization,
State,
UserOrganizationLink,
Zone,
)

class StudentInfoSerializer(serializers.Serializer):
full_name = serializers.CharField()
Expand Down Expand Up @@ -54,3 +62,24 @@ def get_organizations(self, obj):

def get_interest_groups(self, obj):
return obj.user_ig_link_user.all().values_list("ig__name", flat=True)



class OrgSerializer(serializers.ModelSerializer):
class Meta:
model = Organization
fields = ["id", "title"]

class DistrictSerializer(serializers.ModelSerializer):
class Meta:
model = District
fields = ["id", "name"]

class StateSerializer(serializers.ModelSerializer):
class Meta:
model = State
fields = ["id", "name"]
class CountrySerializer(serializers.ModelSerializer):
class Meta:
model = Country
fields = ["id", "name"]
6 changes: 6 additions & 0 deletions api/common/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@
path('list-ig-top100/', common_views.ListTopIgUsersAPI.as_view()),

path('leaderboard/top-100/', common_views.BekenAPI.as_view()),


path("list/college/", common_views.LcCollegeAPI.as_view()),
path("list/district/", common_views.LcDistrictAPI.as_view()),
path("list/state/", common_views.LcStateAPI.as_view()),
path("list/country/", common_views.LcCountryAPI.as_view()),
]

0 comments on commit 0bc3b0d

Please sign in to comment.