Repository: Cloud-CV/EvalAI

Issue:
Disable the Challenge Phase buttons which are inactive while making submissions
## Observed Behaviour
Currently, if a challenge phase is inactive then also a participant can select the phase to make submissions. 

See screenshot for example:
<img width="1440" alt="screen shot 2017-08-08 at 7 21 16 pm" src="https://user-images.githubusercontent.com/2945708/29098709-ca4c67a8-7c6e-11e7-8729-73122eb9982e.png">

## Expected Behaviour

The challenge phases that are not active now should be ideally disabled and the user shouldn't be allowed to select those challenge phases. 
Disable the Challenge Phase buttons which are inactive while making submissions
## Observed Behaviour
Currently, if a challenge phase is inactive then also a participant can select the phase to make submissions. 

See screenshot for example:
<img width="1440" alt="screen shot 2017-08-08 at 7 21 16 pm" src="https://user-images.githubusercontent.com/2945708/29098709-ca4c67a8-7c6e-11e7-8729-73122eb9982e.png">

## Expected Behaviour

The challenge phases that are not active now should be ideally disabled and the user shouldn't be allowed to select those challenge phases. 


Discussion:
@deshraj can I take this up?
@Ram81 Yes sure. go ahead!

@deshraj can I take this up?
@Ram81 Yes sure. go ahead!


Resolving patch:
diff --git a/apps/participants/serializers.py b/apps/participants/serializers.py
--- a/apps/participants/serializers.py
+++ b/apps/participants/serializers.py
@@ -1,4 +1,5 @@
 from django.contrib.auth.models import User
+from django.utils import timezone
 
 from rest_framework import serializers
 
@@ -102,6 +103,10 @@ def __init__(self, challenge_participant_team_list):
 class ChallengeParticipantTeamListSerializer(serializers.Serializer):
     """Serializer to map a challenge's participant team lists."""
     challenge_participant_team_list = ChallengeParticipantTeamSerializer(many=True)
+    datetime_now = serializers.SerializerMethodField()
+
+    def get_datetime_now(self, obj):
+        return timezone.now()
 
 
 class ParticipantTeamCount(object):


Test patch:
diff --git a/tests/unit/participants/test_views.py b/tests/unit/participants/test_views.py
--- a/tests/unit/participants/test_views.py
+++ b/tests/unit/participants/test_views.py
@@ -568,6 +568,8 @@ def setUp(self):
             'participants:get_teams_and_corresponding_challenges_for_a_participant',
             kwargs={'challenge_pk': self.challenge1.pk})
 
+        self.time = timezone.now()
+
     def test_get_teams_and_corresponding_challenges_for_a_participant(self):
 
         self.challenge1.participant_teams.add(self.participant_team1)
@@ -608,6 +610,10 @@ def test_get_teams_and_corresponding_challenges_for_a_participant(self):
             "is_challenge_host": False
         }
         response = self.client.get(self.url, {})
+        # checking 'datetime_now' separately because of time difference in microseconds
+        self.assertTrue(abs(response.data['datetime_now'] - self.time) < timedelta(seconds=1))
+        # deleting field 'datetime_now' from response to check with expected response without time field
+        del response.data['datetime_now']
         self.assertEqual(response.data, expected)
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
@@ -627,6 +633,10 @@ def test_when_participant_team_hasnot_participated_in_any_challenge(self):
             "is_challenge_host": False
         }
         response = self.client.get(self.url, {})
+        # checking 'datetime_now' separately because of time difference in microseconds
+        self.assertTrue(abs(response.data['datetime_now'] - self.time) < timedelta(seconds=1))
+        # deleting field 'datetime_now' from response to check with expected response without time field
+        del response.data['datetime_now']
         self.assertEqual(response.data, expected)
         self.assertEqual(response.status_code, status.HTTP_200_OK)
 
@@ -640,6 +650,10 @@ def test_when_there_is_no_participant_team_of_user(self):
         }
 
         response = self.client.get(self.url, {})
+        # checking 'datetime_now' separately because of time difference in microseconds
+        self.assertTrue(abs(response.data['datetime_now'] - self.time) < timedelta(seconds=1))
+        # deleting field 'datetime_now' from response to check with expected response without time field
+        del response.data['datetime_now']
         self.assertEqual(response.data, expected)
         self.assertEqual(response.status_code, status.HTTP_200_OK)