diff --git a/apps/challenges/migrations/0108_alter_leaderboarddata_is_disabled_null.py b/apps/challenges/migrations/0108_alter_leaderboarddata_is_disabled_null.py new file mode 100644 index 0000000000..acc8e20568 --- /dev/null +++ b/apps/challenges/migrations/0108_alter_leaderboarddata_is_disabled_null.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.20 on 2023-11-07 06:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('challenges', '0107_leaderboarddata_is_disabled'), + ] + + operations = [ + migrations.AlterField( + model_name='leaderboarddata', + name='is_disabled', + field=models.BooleanField(default=False, null=True), + ), + ] diff --git a/apps/challenges/models.py b/apps/challenges/models.py index 3199ff66b2..2c374e1659 100644 --- a/apps/challenges/models.py +++ b/apps/challenges/models.py @@ -512,7 +512,7 @@ class LeaderboardData(TimeStampedModel): submission = models.ForeignKey("jobs.Submission", on_delete=models.CASCADE) leaderboard = models.ForeignKey("Leaderboard", on_delete=models.CASCADE) result = JSONField() - is_disabled = models.BooleanField(default=False) + is_disabled = models.BooleanField(default=False, null=True) error = JSONField(null=True, blank=True) def __str__(self): diff --git a/apps/challenges/views.py b/apps/challenges/views.py index ea96224c55..d4b298dcb8 100644 --- a/apps/challenges/views.py +++ b/apps/challenges/views.py @@ -24,6 +24,7 @@ from django.db import transaction from django.http import HttpResponse from django.utils import timezone +from django.db.models import Q from rest_framework import permissions, status from rest_framework.decorators import ( @@ -4706,7 +4707,10 @@ def get_leaderboard_data(request, challenge_phase_split_pk): return Response(response_data, status=status.HTTP_401_UNAUTHORIZED) try: challenge_phase_split = get_challenge_phase_split_model(challenge_phase_split_pk) - leaderboard_data = LeaderboardData.objects.filter(challenge_phase_split=challenge_phase_split, is_disabled=False) + leaderboard_data = LeaderboardData.objects.filter( + Q(is_disabled=False) | Q(is_disabled__isnull=True), + challenge_phase_split=challenge_phase_split + ) except LeaderboardData.DoesNotExist: response_data = { "error": "Leaderboard data not found!" diff --git a/apps/jobs/utils.py b/apps/jobs/utils.py index 159aaacebb..5b9963bdd9 100644 --- a/apps/jobs/utils.py +++ b/apps/jobs/utils.py @@ -357,7 +357,7 @@ def calculate_distinct_sorted_leaderboard_data( leaderboard_data = LeaderboardData.objects.exclude( Q(submission__created_by__email__in=challenge_hosts_emails) & Q(submission__is_baseline=False) - ).filter(is_disabled=False) + ).filter(Q(is_disabled=False) | Q(is_disabled__isnull=True)) # Get all the successful submissions related to the challenge phase split all_valid_submission_status = [Submission.FINISHED] @@ -517,9 +517,9 @@ def get_leaderboard_data_model(submission_pk, challenge_phase_split_pk): [Class Object] -- LeaderboardData model object """ leaderboard_data = LeaderboardData.objects.get( + Q(is_disabled=False) | Q(is_disabled__isnull=True), submission=submission_pk, challenge_phase_split__pk=challenge_phase_split_pk, - is_disabled=False, ) return leaderboard_data diff --git a/apps/jobs/views.py b/apps/jobs/views.py index 87e4cb7925..21ab53cd9e 100644 --- a/apps/jobs/views.py +++ b/apps/jobs/views.py @@ -19,6 +19,7 @@ from django.db import transaction, IntegrityError from django.db.models import Count from django.utils import timezone +from django.db.models import Q from rest_framework_expiring_authtoken.authentication import ( ExpiringTokenAuthentication, @@ -2265,7 +2266,10 @@ def update_leaderboard_data(request, leaderboard_data_pk): """ try: - leaderboard_data = LeaderboardData.objects.get(pk=leaderboard_data_pk, is_disabled=False) + leaderboard_data = LeaderboardData.objects.get( + Q(is_disabled=False) | Q(is_disabled__isnull=True), + pk=leaderboard_data_pk + ) except LeaderboardData.DoesNotExist: response_data = {"error": "Leaderboard data does not exist"} return Response(response_data, status=status.HTTP_404_NOT_FOUND)