Skip to content

Commit

Permalink
Merge pull request #2127 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jelanmathewjames authored Jul 3, 2024
2 parents 488fc5e + 002b2e8 commit 796e219
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 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 Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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
Expand All @@ -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():
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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 []
Expand Down

0 comments on commit 796e219

Please sign in to comment.