From d0bf0ef160ccdd18209f3a1fc892ad7b73a0b23e Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Sun, 30 Jul 2023 21:25:52 +0500 Subject: [PATCH 1/3] by default show no phases --- src/apps/api/views/competitions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index 4dc0e4b30..bb5fb36ba 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -508,7 +508,7 @@ def perform_update(self, serializer): class PhaseViewSet(ModelViewSet): - queryset = Phase.objects.all() + queryset = Phase.objects.none() serializer_class = PhaseSerializer # TODO! Security, who can access/delete/etc this? From bf72fdb8cadc69036f97a24bd686e36fa21d6439 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Sun, 30 Jul 2023 21:54:36 +0500 Subject: [PATCH 2/3] /api/phases/ restricted while others allowed to access phases --- src/apps/api/views/competitions.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index bb5fb36ba..21b51201f 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -508,9 +508,26 @@ def perform_update(self, serializer): class PhaseViewSet(ModelViewSet): - queryset = Phase.objects.none() serializer_class = PhaseSerializer + def get_queryset(self): + # You can add your logic here to return the full queryset when needed + qs = Phase.objects.all() + return qs + + def list(self, request, *args, **kwargs): + # Check if it's a direct request to /api/phases/ + direct_request = 'pk' not in kwargs or kwargs['pk'] == 'list' + + if direct_request: + # If it's a direct request, return an empty response without any actual phase objects + return Response([], status=status.HTTP_200_OK) + + # Otherwise, allow other functions to use the list functionality as usual + queryset = self.filter_queryset(self.get_queryset()) + serializer = self.get_serializer(queryset, many=True) + return Response(serializer.data) + # TODO! Security, who can access/delete/etc this? @action(detail=True, methods=('POST',), url_name='manually_migrate') From fe1d994cb805d95032450513241fab33e3bd3c67 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Mon, 31 Jul 2023 01:07:08 +0500 Subject: [PATCH 3/3] extra code removed, extra print removed, comments changed --- src/apps/api/views/competitions.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index 21b51201f..43e1b5589 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -511,20 +511,20 @@ class PhaseViewSet(ModelViewSet): serializer_class = PhaseSerializer def get_queryset(self): - # You can add your logic here to return the full queryset when needed qs = Phase.objects.all() return qs def list(self, request, *args, **kwargs): # Check if it's a direct request to /api/phases/ + # i.e without a pk direct_request = 'pk' not in kwargs or kwargs['pk'] == 'list' if direct_request: - # If it's a direct request, return an empty response without any actual phase objects + # return empty response in direct request return Response([], status=status.HTTP_200_OK) # Otherwise, allow other functions to use the list functionality as usual - queryset = self.filter_queryset(self.get_queryset()) + queryset = self.get_queryset() serializer = self.get_serializer(queryset, many=True) return Response(serializer.data) @@ -636,7 +636,6 @@ def get_leaderboard(self, request, pk): # put detailed results in its submission for k, v in submissions_keys.items(): response['submissions'][v]['detailed_results'] = submission_detailed_results[k] - print(f"\n{response['submissions']}\n") for task in query['tasks']: # This can be used to rendered variable columns on each task