diff --git a/api/donate/views.py b/api/donate/views.py index 9e790564..57ee2bcc 100644 --- a/api/donate/views.py +++ b/api/donate/views.py @@ -105,6 +105,8 @@ def post(self, request): transaction_details = { "Amount": float(data['amount']) / 100, "Currency": data.get('currency', None), + "payment_id":data['id'], + "Payment_method":data['method'], "Name": data['notes']['name'], "Email": data['notes']['email'], } @@ -119,6 +121,6 @@ def post(self, request): if serializer.is_valid(): serializer.save() - return create_receipt(transaction_details) + return CustomResponse(response = transaction_details).get_success_response() except razorpay.errors.SignatureVerificationError as e: return CustomResponse(general_message = "Payment Verification Failed").get_failure_response() diff --git a/api/launchpad/launchpad_views.py b/api/launchpad/launchpad_views.py index d551c30a..fd7833b3 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, @@ -44,7 +44,7 @@ def get(self, request): ) ).filter( Q(user_organization_link_user__id__in=UserOrganizationLink.objects.filter( - org__org_type__in=allowed_org_types + org__org_type__in=["College", "School", "Company", "Community"] ).values("id")) | Q(user_organization_link_user__id__isnull=True) ).annotate( karma=Subquery(total_karma_subquery, output_field=IntegerField()), @@ -106,10 +106,20 @@ def get(self, request): Q(level__in=allowed_levels) | Q(level__isnull=True) ).distinct() + if district := request.query_params.get("district"): + users = users.filter(district_name=district) + if org := request.query_params.get("org"): + users = users.filter(org=org) + if level := request.query_params.get("level"): + users = users.filter(level=level) + if state := request.query_params.get("state"): + users = users.filter(state=state) + paginated_queryset = CommonUtils.get_paginated_queryset( users, request, - ["full_name", "level", "org", "district_name", "state"] + ["full_name", "level", "org", "district_name", "state"], + sort_fields={"full_name": "full_name", "org": "org", "district_name": "district_name", "state": "state", "level": "level"} ) serializer = LaunchpadParticipantsSerializer( @@ -188,27 +198,35 @@ 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"): + org = org.filter(title=title) + if state := request.query_params.get("state"): + org = org.filter(state=state) + paginated_queryset = CommonUtils.get_paginated_queryset( org, request, - ["title", "district_name", "state"] + ["title", "district_name", "state"], + sort_fields={"title": "title", "district_name": "district_name", "state": "state"} ) serializer = CollegeDataSerializer( @@ -230,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 @@ -255,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(): @@ -273,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) @@ -299,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): @@ -336,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 @@ -354,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") @@ -403,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 [] diff --git a/api/launchpad/serializers.py b/api/launchpad/serializers.py index b000e217..3f55279f 100644 --- a/api/launchpad/serializers.py +++ b/api/launchpad/serializers.py @@ -180,12 +180,22 @@ def update(self, instance, validated_data): class UserProfileUpdateSerializer(serializers.ModelSerializer): id = serializers.CharField(max_length=36, read_only=True) + full_name = serializers.CharField(required=False, allow_blank=True, allow_null=True) + phone_number = serializers.CharField(required=False, allow_blank=True, allow_null=True) + district = serializers.CharField(required=False, allow_blank=True, allow_null=True) + zone = serializers.CharField(required=False, allow_blank=True, allow_null=True) + email = serializers.EmailField(required=False) colleges = serializers.SerializerMethodField() class Meta: model = LaunchPadUsers - fields = ("id", "full_name", "phone_number", "district", "zone", "email") + fields = ("id", "full_name", "phone_number", "district", "zone", "email", "colleges") + def validate(self, attrs): + if LaunchPadUsers.objects.filter(email=attrs.get("email")).exclude(id=self.instance.id).exists(): + raise serializers.ValidationError("Email already exists") + return super().validate(attrs) + def update(self, instance, validated_data): instance.full_name = validated_data.get("full_name", instance.full_name) instance.phone_number = validated_data.get("phone_number", instance.phone_number)