From 88197e1dabc8bde9f0778b88262cd539048cba6c Mon Sep 17 00:00:00 2001 From: AlfrinP Date: Wed, 3 Jul 2024 13:57:34 +0530 Subject: [PATCH] Fix retrieval of 'current_user' query parameter and response data assignment in UserProfile's GET method --- api/launchpad/launchpad_views.py | 46 ++++++++++++++++---------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/api/launchpad/launchpad_views.py b/api/launchpad/launchpad_views.py index 3481456f..18320195 100644 --- a/api/launchpad/launchpad_views.py +++ b/api/launchpad/launchpad_views.py @@ -32,7 +32,7 @@ def get(self, request): appraiser_approved=True, task__hashtag='#lp24-introduction', ).values('user') - + users = User.objects.filter( karma_activity_log_user__task__event="launchpad", karma_activity_log_user__appraiser_approved=True, @@ -198,23 +198,23 @@ def get(self, request): state=F("district__zone__state__name"), total_users=Count("user_organization_link_org__user"), level1 = Count( - "user_organization_link_org__user", + "user_organization_link_org__user", filter=Q(user_organization_link_org__user__user_role_link_user__role__title=LaunchPadLevels.LEVEL_1.value) ), level2 = Count( - "user_organization_link_org__user", + "user_organization_link_org__user", filter=Q(user_organization_link_org__user__user_role_link_user__role__title=LaunchPadLevels.LEVEL_2.value) ), level3 = Count( - "user_organization_link_org__user", + "user_organization_link_org__user", filter=Q(user_organization_link_org__user__user_role_link_user__role__title=LaunchPadLevels.LEVEL_3.value) ), level4 = Count( - "user_organization_link_org__user", + "user_organization_link_org__user", filter=Q(user_organization_link_org__user__user_role_link_user__role__title=LaunchPadLevels.LEVEL_4.value) ) ).order_by("-total_users") - + if district := request.query_params.get("district"): org = org.filter(district_name=district) if title := request.query_params.get("title"): @@ -248,7 +248,7 @@ def post(self, request): serializer = LaunchpadUserSerializer(data=data) if not serializer.is_valid(): return CustomResponse(message=serializer.errors).get_failure_response() - + colleges = data.get('colleges') errors = {} error = False @@ -273,7 +273,7 @@ def post(self, request): if error: return CustomResponse(message=errors).get_failure_response() return CustomResponse(general_message="Successfully added user").get_success_response() - + def get(self, request): auth_mail = request.query_params.get('current_user', None) if not LaunchPadUsers.objects.filter(email=auth_mail, role=LaunchPadRoles.ADMIN.value).exists(): @@ -291,7 +291,7 @@ def get(self, request): return CustomResponse().paginated_response( data=serializer.data, pagination=paginated_queryset.get("pagination") ) - + def put(self, request, email): data = request.data auth_mail = data.pop('current_user', None) @@ -317,32 +317,32 @@ def get(self, request, email): return CustomResponse(general_message="User not found").get_failure_response() serializer = LaunchpadUserListSerializer(user) return CustomResponse(response=serializer.data).get_success_response() - - + + class UserProfile(APIView): def get(self, request): - auth_mail = request.query_params('current_user', None) + auth_mail = request.query_params.get("current_user", None) if not LaunchPadUsers.objects.filter(email=auth_mail).exists(): return CustomResponse(general_message="Unauthorized").get_failure_response() user = LaunchPadUsers.objects.get(email=auth_mail) serializer = LaunchpadUserListSerializer(user) - return CustomResponse(data=serializer.data).get_success_response() - + return CustomResponse(response=serializer.data).get_success_response() + def put(self, request): data = request.data auth_mail = data.pop('current_user', None) auth_mail = auth_mail[0] if isinstance(auth_mail, list) else auth_mail if not (user := LaunchPadUsers.objects.filter(email=auth_mail).first()): return CustomResponse(general_message="Unauthorized").get_failure_response() - + serializer = UserProfileUpdateSerializer(user, data=data) if serializer.is_valid(): serializer.save() return CustomResponse(general_message="Successfully updated user").get_success_response() return CustomResponse(message=serializer.errors).get_failure_response() - - + + class UserBasedCollegeData(APIView): def get(self, request): @@ -354,7 +354,7 @@ def get(self, request): college_ids = [college.college_id for college in colleges] allowed_levels = LaunchPadLevels.get_all_values() - + org = Organization.objects.filter( org_type="College", id__in=college_ids @@ -372,19 +372,19 @@ def get(self, request): state=F("district__zone__state__name"), total_users=Count("user_organization_link_org__user"), level1 = Count( - "user_organization_link_org__user", + "user_organization_link_org__user", filter=Q(user_organization_link_org__user__user_role_link_user__role__title=LaunchPadLevels.LEVEL_1.value) ), level2 = Count( - "user_organization_link_org__user", + "user_organization_link_org__user", filter=Q(user_organization_link_org__user__user_role_link_user__role__title=LaunchPadLevels.LEVEL_2.value) ), level3 = Count( - "user_organization_link_org__user", + "user_organization_link_org__user", filter=Q(user_organization_link_org__user__user_role_link_user__role__title=LaunchPadLevels.LEVEL_3.value) ), level4 = Count( - "user_organization_link_org__user", + "user_organization_link_org__user", filter=Q(user_organization_link_org__user__user_role_link_user__role__title=LaunchPadLevels.LEVEL_4.value) ) ).order_by("-total_users") @@ -421,7 +421,7 @@ def post(self, request): return CustomResponse(general_message={'Empty csv file.'}).get_failure_response() errors = {} error = False - + for data in excel_data[1:]: not_found_colleges = [] data['colleges'] = data['colleges'].split(",") if data.get('colleges') else []