diff --git a/api/launchpad/launchpad_views.py b/api/launchpad/launchpad_views.py index 95ec1a4d..3827fc07 100644 --- a/api/launchpad/launchpad_views.py +++ b/api/launchpad/launchpad_views.py @@ -74,9 +74,17 @@ def get(self, request): ["full_name", "karma", "org", "district_name", "state"] ) + final_users = paginated_queryset.get("queryset") + if request.query_params.get("search"): + final_users = list(final_users) + for user in final_users: + user.rank = next(rank_user.rank for rank_user in rank_list if rank_user.muid == user.muid) + serializer = LaunchpadLeaderBoardSerializer( - paginated_queryset.get("queryset"), many=True + final_users, + many=True ) + return CustomResponse().paginated_response( data=serializer.data, pagination=paginated_queryset.get("pagination") ) @@ -132,14 +140,21 @@ def get(self, request): for index, user in enumerate(rank_list): user.rank = index + 1 + paginated_queryset = CommonUtils.get_paginated_queryset( users, request, ["full_name", "karma", "org", "district_name", "state"] ) + final_users = paginated_queryset.get("queryset") + if request.query_params.get("search"): + final_users = list(final_users) + for user in final_users: + user.rank = next(rank_user.rank for rank_user in rank_list if rank_user.muid == user.muid) + serializer = TaskCompletedLeaderBoardSerializer( - paginated_queryset.get("queryset"), + final_users, many=True ) return CustomResponse().paginated_response( diff --git a/api/launchpad/serializers.py b/api/launchpad/serializers.py index 2784664c..b58b74cc 100644 --- a/api/launchpad/serializers.py +++ b/api/launchpad/serializers.py @@ -73,6 +73,7 @@ class Meta: class TaskCompletedLeaderBoardSerializer(serializers.ModelSerializer): + # rank = serializers.SerializerMethodField('get_rank') rank = serializers.IntegerField() karma = serializers.IntegerField() is_public = serializers.BooleanField(source='user_settings_user.is_public',default=False) @@ -83,6 +84,9 @@ class TaskCompletedLeaderBoardSerializer(serializers.ModelSerializer): class Meta: model = User fields = ("muid", "is_public", "rank", "full_name", "karma", "org", "district_name", "state", "profile_pic") + + def get_rank(self, obj): + return getattr(obj, 'rank', None) class LaunchpadParticipantsSerializer(serializers.ModelSerializer):