internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: Cloud-CV/EvalAI

Issue:
Add serializers for creating challenge using zip file.



Discussion:

Resolving patch:
diff --git a/apps/challenges/serializers.py b/apps/challenges/serializers.py
--- a/apps/challenges/serializers.py
+++ b/apps/challenges/serializers.py
@@ -2,11 +2,12 @@
 
 from hosts.serializers import ChallengeHostTeamSerializer
 
-from .models import (
-                     Challenge,
+from .models import (Challenge,
+                     ChallengeConfiguration,
                      ChallengePhase,
                      ChallengePhaseSplit,
-                     DatasetSplit,)
+                     DatasetSplit,
+                     Leaderboard,)
 
 
 class ChallengeSerializer(serializers.ModelSerializer):
@@ -63,7 +64,6 @@ class ChallengePhaseSplitSerializer(serializers.ModelSerializer):
 
     class Meta:
         model = ChallengePhaseSplit
-        fields = '__all__'
         fields = ('id', 'dataset_split', 'challenge_phase', 'challenge_phase_name', 'dataset_split_name', 'visibility')
 
     def get_dataset_split_name(self, obj):
@@ -71,3 +71,48 @@ def get_dataset_split_name(self, obj):
 
     def get_challenge_phase_name(self, obj):
         return obj.challenge_phase.name
+
+
+class ChallengeConfigSerializer(serializers.ModelSerializer):
+    """
+    Serialize the ChallengeConfiguration Model.
+    """
+    def __init__(self, *args, **kwargs):
+        super(ChallengeConfigSerializer, self).__init__(*args, **kwargs)
+        context = kwargs.get('context')
+        if context:
+            user = context.get('user')
+            kwargs['data']['user'] = user.pk
+
+    class Meta:
+        model = ChallengeConfiguration
+        fields = ('zip_configuration', 'user',)
+
+
+class LeaderboardSerializer(serializers.ModelSerializer):
+    """
+    Serialize the Leaderboard Model.
+    """
+    class Meta:
+        model = Leaderboard
+        fields = '__all__'
+
+
+class ZipChallengeSerializer(ChallengeSerializer):
+    """
+    Serializer used for creating challenge through zip file.
+    """
+    class Meta:
+        model = Challenge
+        fields = ('id', 'title', 'short_description', 'description', 'terms_and_conditions',
+                  'submission_guidelines', 'start_date', 'end_date', 'creator',
+                  'published', 'enable_forum', 'anonymous_leaderboard', 'is_active',)
+
+
+class ZipChallengePhaseSplitSerializer(serializers.ModelSerializer):
+    """
+    Serializer used for creating challenge phase split through zip file.
+    """
+    class Meta:
+        model = ChallengePhaseSplit
+        fields = '__all__'


Test patch:
Repository: Cloud-CV/EvalAI

Issue:
Change the pagination limit in leaderboard
Currently, in the VQA challenge, only 10 entries are visible on the leaderboard and there is no pagination on the client side. To show all the entries of the leaderboard, there are two ways to do that:
1. Add a pagination on the client side
2. Show all the entries on a single page (involves adding a new Pagination Class)

The second approach is a better way since then others will be able to compare their results with everyone else in the team. 



Discussion:

Resolving patch:
diff --git a/apps/base/utils.py b/apps/base/utils.py
--- a/apps/base/utils.py
+++ b/apps/base/utils.py
@@ -8,11 +8,17 @@
 from rest_framework.pagination import PageNumberPagination
 
 
-def paginated_queryset(queryset, request):
+class StandardResultSetPagination(PageNumberPagination):
+    page_size = 100
+    page_size_query_param = 'page_size'
+    max_page_size = 1000
+
+
+def paginated_queryset(queryset, request, pagination_class=PageNumberPagination()):
     '''
         Return a paginated result for a queryset
     '''
-    paginator = PageNumberPagination()
+    paginator = pagination_class
     paginator.page_size = settings.REST_FRAMEWORK['PAGE_SIZE']
     result_page = paginator.paginate_queryset(queryset, request)
     return (paginator, result_page)
diff --git a/apps/jobs/views.py b/apps/jobs/views.py
--- a/apps/jobs/views.py
+++ b/apps/jobs/views.py
@@ -16,7 +16,7 @@
 from rest_framework.throttling import UserRateThrottle, AnonRateThrottle
 
 from accounts.permissions import HasVerifiedEmail
-from base.utils import paginated_queryset
+from base.utils import paginated_queryset, StandardResultSetPagination
 from challenges.models import (
     ChallengePhase,
     Challenge,
@@ -229,7 +229,10 @@ def leaderboard(request, challenge_phase_split_id):
     for item in distinct_sorted_leaderboard_data:
         item['result'] = [item['result'][index.lower()] for index in leaderboard_labels]
 
-    paginator, result_page = paginated_queryset(distinct_sorted_leaderboard_data, request)
+    paginator, result_page = paginated_queryset(
+                                                distinct_sorted_leaderboard_data,
+                                                request,
+                                                pagination_class=StandardResultSetPagination())
     response_data = result_page
     return paginator.get_paginated_response(response_data)
 


Test patch:
Repository: Cloud-CV/EvalAI

Issue:
A challenge should not be published directly when challenge host creates it.
Once the `challenge_host `creates a challenge then it should not be published directly. **The administrator must approve the challenge before it is published.**

**Solution:** Add a query parameter `approved_by_admin=True` in `get_all_challenges` api.




Discussion:

Resolving patch:
diff --git a/apps/challenges/views.py b/apps/challenges/views.py
--- a/apps/challenges/views.py
+++ b/apps/challenges/views.py
@@ -181,7 +181,7 @@ def get_all_challenges(request, challenge_time):
         response_data = {'error': 'Wrong url pattern!'}
         return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
 
-    q_params = {'published': True}
+    q_params = {'published': True, 'approved_by_admin': True}
     if challenge_time.lower() == "past":
         q_params['end_date__lt'] = timezone.now()
 


Test patch:
diff --git a/tests/unit/challenges/test_views.py b/tests/unit/challenges/test_views.py
--- a/tests/unit/challenges/test_views.py
+++ b/tests/unit/challenges/test_views.py
@@ -545,6 +545,7 @@ def setUp(self):
             creator=self.challenge_host_team,
             published=True,
             enable_forum=True,
+            approved_by_admin=True,
             anonymous_leaderboard=False,
             start_date=timezone.now() - timedelta(days=2),
             end_date=timezone.now() + timedelta(days=1),
@@ -560,6 +561,7 @@ def setUp(self):
             creator=self.challenge_host_team,
             published=True,
             enable_forum=True,
+            approved_by_admin=True,
             anonymous_leaderboard=False,
             start_date=timezone.now() - timedelta(days=2),
             end_date=timezone.now() - timedelta(days=1),
@@ -575,6 +577,7 @@ def setUp(self):
             creator=self.challenge_host_team,
             published=True,
             enable_forum=True,
+            approved_by_admin=True,
             anonymous_leaderboard=False,
             start_date=timezone.now() + timedelta(days=2),
             end_date=timezone.now() + timedelta(days=1),
Repository: Cloud-CV/EvalAI

Issue:
Add approved by admin check in seed script
## Observed Behaviour

Currently, when the seed script is ran, then the challenges are created but they are not shown on the client side since the `approved_by_admin` atribute for those challenges is False by default.

## Objective

Set `approved_by_admin=True` for the dummy challenges in the seed script so that they can be viewed on the client side. 
Add approved by admin check in seed script
## Observed Behaviour

Currently, when the seed script is ran, then the challenges are created but they are not shown on the client side since the `approved_by_admin` atribute for those challenges is False by default.

## Objective

Set `approved_by_admin=True` for the dummy challenges in the seed script so that they can be viewed on the client side. 


Discussion:
@deshraj can I work on this? 
Sure, go ahead. 
@deshraj can I work on this? 
Sure, go ahead. 

Resolving patch:
diff --git a/scripts/seed.py b/scripts/seed.py
--- a/scripts/seed.py
+++ b/scripts/seed.py
@@ -97,6 +97,7 @@ def create_challenge(title, start_date, end_date, host_team):
         submission_guidelines=fake.paragraph(),
         evaluation_details=fake.paragraph(),
         evaluation_script=SimpleUploadedFile(evaluation_script.name, evaluation_script.read()),
+        approved_by_admin=True,
         creator=host_team,
         published=True,
         enable_forum=True,


Test patch:
Repository: Cloud-CV/EvalAI

Issue:
Add approved_by_admin check in submission worker script.
**Need:** Since we need to only publish those challenges that are approved by admin, so it is also necessary that `submission_worker` should load only admin approved challenges.

**Solution:** Make the query parameters [here](https://github.com/Cloud-CV/EvalAI/blob/master/scripts/workers/submission_worker.py#L215) as
`q_params = {'published': True, 'approved_by_admin': True}`


Discussion:

Resolving patch:
diff --git a/scripts/workers/submission_worker.py b/scripts/workers/submission_worker.py
--- a/scripts/workers/submission_worker.py
+++ b/scripts/workers/submission_worker.py
@@ -212,7 +212,7 @@ def load_active_challenges():
     '''
          * Fetches active challenges and corresponding active phases for it.
     '''
-    q_params = {'published': True}
+    q_params = {'published': True, 'approved_by_admin': True}
     q_params['start_date__lt'] = timezone.now()
     q_params['end_date__gt'] = timezone.now()
 


Test patch:
Repository: Cloud-CV/EvalAI

Issue:
Change the message on Challenge Creation
Currently, the error message on missing test annotation file for a phase shows the following error:
<img width="1440" alt="screen shot 2017-08-17 at 4 55 26 pm" src="https://user-images.githubusercontent.com/2945708/29433427-107e80a8-836d-11e7-9511-d98fc2e11c1c.png">

We want to change it to 

```
No test annotation file is present in the zip file for challenge phase 'test-dev2017'. Please try uploading again after adding test annotation file!
```


Discussion:

Resolving patch:
diff --git a/apps/challenges/views.py b/apps/challenges/views.py
--- a/apps/challenges/views.py
+++ b/apps/challenges/views.py
@@ -498,8 +498,8 @@ def create_challenge_using_zip_file(request, challenge_host_team_pk):
         if not isfile(test_annotation_file_path):
             response_data = {
                 'error': ('No test annotation file is present in the zip file'
-                          'for challenge phase {} Please try uploading'
-                          'again the zip file after adding test annotation file!'.format(data['name']))
+                          'for challenge phase \'{}\'. Please try uploading '
+                          'again after adding test annotation file!'.format(data['name']))
             }
             return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
 


Test patch:
Repository: Cloud-CV/EvalAI

Issue:
Remove pagination from challenge phase split list API
## Observed behavior

The Challenge Phase Split list API endpoint currently returns the challenge phase splits in a paginated manner. But while showing the leaderboard, we need the list of all the challenge phase splits requesting once. 

## Objective

Remove the pagination from this API (https://github.com/Cloud-CV/EvalAI/blob/master/apps/challenges/views.py#L357).


Discussion:
@deshraj : Can we instead of removing pagination, take a query parameter like noPage or some better name, which if presents, causes the api to return complete result set instead of pagination?


Resolving patch:
diff --git a/apps/challenges/views.py b/apps/challenges/views.py
--- a/apps/challenges/views.py
+++ b/apps/challenges/views.py
@@ -367,10 +367,9 @@ def challenge_phase_split_list(request, challenge_pk):
         return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
 
     challenge_phase_split = ChallengePhaseSplit.objects.filter(challenge_phase__challenge=challenge)
-    paginator, result_page = paginated_queryset(challenge_phase_split, request)
-    serializer = ChallengePhaseSplitSerializer(result_page, many=True)
+    serializer = ChallengePhaseSplitSerializer(challenge_phase_split, many=True)
     response_data = serializer.data
-    return paginator.get_paginated_response(response_data)
+    return Response(response_data, status=status.HTTP_200_OK)
 
 
 @throttle_classes([UserRateThrottle])


Test patch:
diff --git a/tests/unit/challenges/test_views.py b/tests/unit/challenges/test_views.py
--- a/tests/unit/challenges/test_views.py
+++ b/tests/unit/challenges/test_views.py
@@ -1388,7 +1388,7 @@ def test_get_challenge_phase_split(self):
         ]
 
         response = self.client.get(self.url, {})
-        self.assertEqual(response.data['results'], expected)
+        self.assertEqual(response.data, expected)
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
     def test_challenge_phase_split_when_challenge_phase_does_not_exist(self):
Repository: Cloud-CV/EvalAI

Issue:
Show only approved by admin challenges in analytics dashboard.
Show the challenges `approved_by_admin` and `published` in **Challenges Analytics Home**.


Discussion:

Resolving patch:
diff --git a/apps/challenges/views.py b/apps/challenges/views.py
--- a/apps/challenges/views.py
+++ b/apps/challenges/views.py
@@ -248,7 +248,7 @@ def get_challenge_by_pk(request, pk):
 @permission_classes((permissions.IsAuthenticated, HasVerifiedEmail))
 @authentication_classes((ExpiringTokenAuthentication,))
 def get_challenges_based_on_teams(request):
-    q_params = {}
+    q_params = {'approved_by_admin': True, 'published': True}
     participant_team_id = request.query_params.get('participant_team', None)
     challenge_host_team_id = request.query_params.get('host_team', None)
     mode = request.query_params.get('mode', None)


Test patch:
diff --git a/tests/unit/challenges/test_views.py b/tests/unit/challenges/test_views.py
--- a/tests/unit/challenges/test_views.py
+++ b/tests/unit/challenges/test_views.py
@@ -60,6 +60,7 @@ def setUp(self):
             anonymous_leaderboard=False,
             start_date=timezone.now() - timedelta(days=2),
             end_date=timezone.now() + timedelta(days=1),
+            approved_by_admin=False,
         )
 
         self.challenge_host = ChallengeHost.objects.create(
@@ -808,6 +809,21 @@ def setUp(self):
             status=ChallengeHost.ACCEPTED,
             permissions=ChallengeHost.ADMIN)
 
+        self.challenge = Challenge.objects.create(
+            title='Test Challenge',
+            short_description='Short description for test challenge',
+            description='Description for test challenge',
+            terms_and_conditions='Terms and conditions for test challenge',
+            submission_guidelines='Submission guidelines for test challenge',
+            creator=self.challenge_host_team,
+            published=True,
+            enable_forum=True,
+            anonymous_leaderboard=False,
+            start_date=timezone.now() - timedelta(days=2),
+            end_date=timezone.now() + timedelta(days=1),
+            approved_by_admin=True,
+        )
+
         self.challenge2 = Challenge.objects.create(
             title='Some Test Challenge',
             short_description='Short description for some test challenge',
@@ -815,11 +831,12 @@ def setUp(self):
             terms_and_conditions='Terms and conditions for some test challenge',
             submission_guidelines='Submission guidelines for some test challenge',
             creator=self.challenge_host_team2,
-            published=False,
+            published=True,
             enable_forum=True,
             anonymous_leaderboard=False,
             start_date=timezone.now() - timedelta(days=2),
             end_date=timezone.now() + timedelta(days=1),
+            approved_by_admin=True,
         )
 
         self.participant_team2 = ParticipantTeam.objects.create(
Repository: Cloud-CV/EvalAI

Issue:
Change message after the challenge creation
Currently, when a challenge is being created using the zip file feature, then the user is shown something like this:

<img width="1440" alt="screen shot 2017-09-06 at 6 10 21 pm" src="https://user-images.githubusercontent.com/2945708/30137037-8cb1bb64-932f-11e7-89dd-7cde192b5baf.png">

We would like to change the message to "Challenge <challenge_name> has been created successfully and sent for review to EvalAI Admin."
Change message after the challenge creation
Currently, when a challenge is being created using the zip file feature, then the user is shown something like this:

<img width="1440" alt="screen shot 2017-09-06 at 6 10 21 pm" src="https://user-images.githubusercontent.com/2945708/30137037-8cb1bb64-932f-11e7-89dd-7cde192b5baf.png">

We would like to change the message to "Challenge <challenge_name> has been created successfully and sent for review to EvalAI Admin."


Discussion:
@deshraj can I take this?

@Ram81 Yes Sure , go ahead.
@RishabhJain2018  Can I get a sample zip file for challenge?
Please take a look at the repo https://github.com/Cloud-CV/EvalAI-Examples for sample zip file.
@deshraj can I take this?

@Ram81 Yes Sure , go ahead.
@RishabhJain2018  Can I get a sample zip file for challenge?
Please take a look at the repo https://github.com/Cloud-CV/EvalAI-Examples for sample zip file.

Resolving patch:
diff --git a/apps/challenges/views.py b/apps/challenges/views.py
--- a/apps/challenges/views.py
+++ b/apps/challenges/views.py
@@ -658,7 +658,8 @@ def create_challenge_using_zip_file(request, challenge_host_team_pk):
         if zip_config:
             zip_config.challenge = challenge
             zip_config.save()
-            response_data = {'success': 'Challenge {} is successfully created'.format(challenge.pk)}
+            response_data = {'success': 'Challenge {} has been created successfully and'
+                                        ' sent for review to EvalAI Admin.'.format(challenge.title)}
             return Response(response_data, status=status.HTTP_201_CREATED)
 
     except:


Test patch:
Repository: Cloud-CV/EvalAI

Issue:
Port the Code to Python 3 and make it Python 2 compatible.
If this issue will be accepted I'll be glad to work on this.


Discussion:

Resolving patch:
diff --git a/apps/challenges/views.py b/apps/challenges/views.py
--- a/apps/challenges/views.py
+++ b/apps/challenges/views.py
@@ -60,6 +60,11 @@
 
 logger = logging.getLogger(__name__)
 
+try:
+    xrange          # Python 2
+except NameError:
+    xrange = range  # Python 3
+
 
 @throttle_classes([UserRateThrottle])
 @api_view(['GET', 'POST'])
diff --git a/scripts/migration/set_phase_code_name_unique.py b/scripts/migration/set_phase_code_name_unique.py
--- a/scripts/migration/set_phase_code_name_unique.py
+++ b/scripts/migration/set_phase_code_name_unique.py
@@ -15,7 +15,7 @@ def set_phase_code_name_unique():
             challenge_phase.code_name = new_phase_code_name
             challenge_phase.save()
             print ("Successfully modified Challenge Phase Code Name")
-    except Exception, e:
+    except Exception as e:
         print str(e)
 
 set_phase_code_name_unique()
diff --git a/scripts/migration/set_team_name_unique.py b/scripts/migration/set_team_name_unique.py
--- a/scripts/migration/set_team_name_unique.py
+++ b/scripts/migration/set_team_name_unique.py
@@ -35,7 +35,7 @@ def make_team_name_unique():
                 host_team_iter = host_team_iter + 1
             else:
                 host_team_list.append(host_team.team_name)
-    except Exception, e:
+    except Exception as e:
         print str(e)
 
 make_team_name_unique()


Test patch:
Repository: Cloud-CV/EvalAI

Issue:
Restrict the update profile API Endpoint from updating username 
Currently, django-rest-auth provides the functionality to update the username with the update profile API Endpoint. We want to restrict this since we don't want a user to update his username once he has created his account. 

For more details about the API endpoint, look at http://django-rest-auth.readthedocs.io/en/latest/api_endpoints.html#basic


Discussion:
Related to #863 
@deshraj can I take it up?
@yadavankit Sure. :) 
@deshraj @yadavankit Is anyone still working on this or can I take this one?
@mayank-agarwal-96 Yeah, you can work on it. :) 
@deshraj ohh, I just forgot this issue... my bad 😅  @mayank-agarwal-96 yeah go on bro...you can take this up :)
Hi, I'm a bit new to restful services using django, and I guess that with a bit of learning I could solve this issue, where would be the best place to start using rest for evalai?
Hey @isht3 [Django REST Framework Documentation](http://www.django-rest-framework.org/) would be a good place to start learning about how REST is implemented in EvalAI. 
@taranjeet @yadavankit I'm currently in the process of learning django REST, I'd like to inform that I'll be back for bigger contributions to CloudCV after I'm done with a personal project of mine.
@isht3 Sounds good. Thanks for informing. :) 
@deshraj Can I start working on this? :)
yes sure. Assigning this to you.
Hi, @deshraj @RishabhJain2018 To update the username after creation of account we should do a PUT request to `/api/auth/user/`, right? I'd like to test this for a bit, would it be best to do it through cURL or drf-docs?
@isht3 Please refer here for the command https://pvcarrera.github.io/general/2015/03/18/curl.html. Moreover , you can use` Postman `client for the same. Let me know if you still have doubts.
@RishabhJain2018 I'll look into it! :smile: 
@RishabhJain2018 Hi, I have analysed the issue. Since only the `PUT` or `PATCH` request to the `/auth/user/` which contains `username` should be restricted, it would require writing a view to check the parameters passed during a `PUT` or `PATCH` request, if it doesn't edit the username then passes then pass it onto `rest_auth`, right?

Resolving patch:
diff --git a/apps/accounts/serializers.py b/apps/accounts/serializers.py
new file mode 100644
--- /dev/null
+++ b/apps/accounts/serializers.py
@@ -0,0 +1,13 @@
+from django.contrib.auth import get_user_model
+
+from rest_framework import serializers
+
+
+class UserDetailsSerializer(serializers.ModelSerializer):
+    """
+    Make username as a read_only field.
+    """
+    class Meta:
+        model = get_user_model()
+        fields = ('pk', 'email', 'username', 'first_name', 'last_name')
+        read_only_fields = ('email', 'username')
diff --git a/settings/common.py b/settings/common.py
--- a/settings/common.py
+++ b/settings/common.py
@@ -273,3 +273,8 @@
     },
     'SUBMISSION_QUEUE': 'submission_task_queue',
 }
+
+# To make usermame field read-only, customized serializer is defined.
+REST_AUTH_SERIALIZERS = {
+    'USER_DETAILS_SERIALIZER': 'accounts.serializers.UserDetailsSerializer',
+}


Test patch: