diff --git a/api/dashboard/discord_moderator/discord_mod_views.py b/api/dashboard/discord_moderator/discord_mod_views.py index de89ac82..23d7fae4 100644 --- a/api/dashboard/discord_moderator/discord_mod_views.py +++ b/api/dashboard/discord_moderator/discord_mod_views.py @@ -4,9 +4,10 @@ from rest_framework.views import APIView from db.task import KarmaActivityLog +from utils.utils import CommonUtils from utils.permission import CustomizePermission from utils.response import CustomResponse -from .serializer import KarmaActivityLogSerializer +from .serializer import KarmaActivityLogSerializer,LeaderboardSerializer class TaskList(APIView): @@ -14,9 +15,23 @@ class TaskList(APIView): def get(self, request): tasks = KarmaActivityLog.objects.all() - serializer = KarmaActivityLogSerializer(tasks, many=True) - return CustomResponse(response=serializer.data).get_success_response() + paginated_queryset = CommonUtils.get_paginated_queryset( + tasks, + request, + ['id', 'full_name', 'task_name', 'status', 'discordlink'] + ) + + serializer = KarmaActivityLogSerializer( + paginated_queryset.get("queryset"), + many=True + ) + return CustomResponse().paginated_response( + data=serializer.data, + pagination=paginated_queryset.get( + "pagination" + ) + ) class PendingTasks(APIView): authentication_classes = [CustomizePermission] @@ -65,4 +80,19 @@ def get(self, request): for name, info in data.items() ] - return CustomResponse(response=response_data).get_success_response() + paginated_queryset = CommonUtils.get_paginated_queryset( + response_data, + request, + [] + ) + serializer = LeaderboardSerializer( + paginated_queryset.get("queryset"), + many=True + ) + return CustomResponse().paginated_response( + data=serializer.data, + pagination=paginated_queryset.get( + "pagination" + ) + ) + diff --git a/api/dashboard/discord_moderator/serializer.py b/api/dashboard/discord_moderator/serializer.py index ed8c470c..8f959efb 100644 --- a/api/dashboard/discord_moderator/serializer.py +++ b/api/dashboard/discord_moderator/serializer.py @@ -22,3 +22,13 @@ def get_status(self, obj): return "Appraiser Approved" else: return "Pending" + + +class LeaderboardSerializer(serializers.ModelSerializer): + name = serializers.CharField(max_length=100) + count = serializers.IntegerField() + muid = serializers.CharField(max_length=100) + + class Meta: + model = KarmaActivityLog + fields = ['name', 'count', 'muid'] \ No newline at end of file diff --git a/db/apps.py b/db/apps.py index 39863731..06244273 100644 --- a/db/apps.py +++ b/db/apps.py @@ -11,6 +11,7 @@ class DbConfig(AppConfig): name = "db" def ready(self) -> None: + # from db import organization _ready = super().ready() self.check_system_user_exists() return _ready