Skip to content

Commit

Permalink
Merge pull request #1940 from Mishalabdullah/dev
Browse files Browse the repository at this point in the history
checks for error in campusstudenineach level
  • Loading branch information
gtechmulearn authored May 11, 2024
2 parents 788c99d + 1a06498 commit b2a2f1a
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions api/dashboard/campus/campus_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,34 @@ def get(self, request):


class CampusStudentInEachLevelAPI(APIView):
authentication_classes = [CustomizePermission]

@role_required([RoleType.CAMPUS_LEAD.value, RoleType.LEAD_ENABLER.value])
def get(self, request):
user_id = JWTUtils.fetch_user_id(request)

if not (user_org_link := get_user_college_link(user_id)):
return CustomResponse(
general_message="User have no organization"
).get_failure_response()

if user_org_link.org is None:
return CustomResponse(
general_message="Campus lead has no college"
).get_failure_response()

level_with_student_count = Level.objects.annotate(
students=Count(
"user_lvl_link_level__user",
filter=Q(
user_lvl_link_level__user__user_organization_link_user__org=user_org_link.org
),
)
).values(level=F("level_order"), students=F("students"))
# authentication_classes = [CustomizePermission]

# @role_required([RoleType.CAMPUS_LEAD.value, RoleType.LEAD_ENABLER.value])
def get():
pass
# user_id = JWTUtils.fetch_user_id(request)

# if not (user_org_link := get_user_college_link(user_id)):
# return CustomResponse(
# general_message="User have no organization"
# ).get_failure_response()

# if user_org_link.org is None:
# return CustomResponse(
# general_message="Campus lead has no college"
# ).get_failure_response()

# level_with_student_count = Level.objects.annotate(
# students=Count(
# "user_lvl_link_level__user",
# filter=Q(
# user_lvl_link_level__user__user_organization_link_user__org=user_org_link.org
# ),
# )
# ).values(level=F("level_order"), students=F("students"))

# return CustomResponse(response=level_with_student_count).get_success_response()

return CustomResponse(response=level_with_student_count).get_success_response()


class CampusStudentDetailsAPI(APIView):
Expand Down

0 comments on commit b2a2f1a

Please sign in to comment.