Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev server #2121

Merged
merged 23 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ef7de54
"fix: modified verify endpoint to return reciept as json"
ParthipPR Jun 24, 2024
acc172a
Merge pull request #2117 from ParthipPR/dev
jelanmathewjames Jun 24, 2024
cb327ff
Merge pull request #2118 from gtech-mulearn/dev
jelanmathewjames Jun 24, 2024
bdacfa9
feat: Add conditional filtering to ListParticipantsAPI and CollegeDat…
jelanmathewjames Jun 25, 2024
5a390d1
Merge branch 'dev' of https://github.com/jelanmathewjames/mulearnback…
jelanmathewjames Jun 25, 2024
f5df165
Merge pull request #2119 from jelanmathewjames/dev
jelanmathewjames Jun 25, 2024
a68a66d
Merge pull request #2120 from gtech-mulearn/dev
jelanmathewjames Jun 25, 2024
1b1f770
"feat: Added payment method to response from verifiction endpoint"
ParthipPR Jun 26, 2024
25b3123
Merge pull request #2122 from ParthipPR/dev
jelanmathewjames Jun 26, 2024
fd3e638
Merge pull request #2123 from gtech-mulearn/dev
jelanmathewjames Jun 26, 2024
93b6b6c
"feat: Added payment id to the response of verify endpoint"
ParthipPR Jun 26, 2024
2e3d12b
Merge pull request #2124 from ParthipPR/dev
jelanmathewjames Jun 26, 2024
488fc5e
Merge pull request #2125 from gtech-mulearn/dev
jelanmathewjames Jun 26, 2024
88197e1
Fix retrieval of 'current_user' query parameter and response data ass…
AlfrinP Jul 3, 2024
002b2e8
Merge pull request #2126 from AlfrinP/dev
jelanmathewjames Jul 3, 2024
796e219
Merge pull request #2127 from gtech-mulearn/dev
jelanmathewjames Jul 3, 2024
b546757
refactor: Update UserProfileUpdateSerializer to validate email unique…
jelanmathewjames Jul 3, 2024
3b609e4
Merge pull request #2128 from jelanmathewjames/dev
jelanmathewjames Jul 3, 2024
a306544
Merge pull request #2129 from gtech-mulearn/dev
jelanmathewjames Jul 3, 2024
0b93b1e
feat: Update allowed organization types in launchpad leaderboard
jelanmathewjames Jul 5, 2024
742a071
Merge branch 'dev' of https://github.com/jelanmathewjames/mulearnback…
jelanmathewjames Jul 5, 2024
61c7807
Merge pull request #2130 from jelanmathewjames/dev
jelanmathewjames Jul 5, 2024
d80982d
Merge pull request #2131 from gtech-mulearn/dev
jelanmathewjames Jul 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion api/donate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}
Expand All @@ -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()
70 changes: 44 additions & 26 deletions api/launchpad/launchpad_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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():
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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 []
Expand Down
12 changes: 11 additions & 1 deletion api/launchpad/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading