diff --git a/src/apps/api/serializers/competitions.py b/src/apps/api/serializers/competitions.py index 0314d831d..69d352c67 100644 --- a/src/apps/api/serializers/competitions.py +++ b/src/apps/api/serializers/competitions.py @@ -15,11 +15,13 @@ from tasks.models import Task from api.serializers.queues import QueueSerializer +from datetime import datetime class PhaseSerializer(WritableNestedModelSerializer): tasks = serializers.SlugRelatedField(queryset=Task.objects.all(), required=True, allow_null=False, slug_field='key', many=True) + status = serializers.SerializerMethodField() class Meta: model = Phase @@ -42,6 +44,42 @@ class Meta: 'is_final_phase', ) + def get_status(self, obj): + + now = datetime.now().replace(tzinfo=None) + start = obj.start.replace(tzinfo=None) + end = obj.end.replace(tzinfo=None) if obj.end else obj.end + phase_ended = False + phase_started = False + + # check if phase has started + if start > now: + # start date is in the future, phase started = NO + phase_started = False + else: + # start date is not in the future, phase started = YES + phase_started = True + + if phase_started: + # check if end date exists for this phase + if end: + if end < now: + # Phase cannote accept submissions if end date is in the past + phase_ended = True + else: + # Phase can accept submissions if end date is in the future + phase_ended = False + else: + # Phase can accept submissions if end date is not given + phase_ended = False + + if phase_started and phase_ended: + return Phase.PREVIOUS + elif phase_started and (not phase_ended): + return Phase.CURRENT + elif not phase_started: + return Phase.NEXT + def validate_leaderboard(self, value): if not value: raise ValidationError("Phases require a leaderboard") @@ -50,6 +88,7 @@ def validate_leaderboard(self, value): class PhaseDetailSerializer(serializers.ModelSerializer): tasks = PhaseTaskInstanceSerializer(source='task_instances', many=True) + status = serializers.SerializerMethodField() class Meta: model = Phase @@ -71,6 +110,42 @@ class Meta: 'is_final_phase', ) + def get_status(self, obj): + + now = datetime.now().replace(tzinfo=None) + start = obj.start.replace(tzinfo=None) + end = obj.end.replace(tzinfo=None) if obj.end else obj.end + phase_ended = False + phase_started = False + + # check if phase has started + if start > now: + # start date is in the future, phase started = NO + phase_started = False + else: + # start date is not in the future, phase started = YES + phase_started = True + + if phase_started: + # check if end date exists for this phase + if end: + if end < now: + # Phase cannote accept submissions if end date is in the past + phase_ended = True + else: + # Phase can accept submissions if end date is in the future + phase_ended = False + else: + # Phase can accept submissions if end date is not given + phase_ended = False + + if phase_started and phase_ended: + return Phase.PREVIOUS + elif phase_started and (not phase_ended): + return Phase.CURRENT + elif not phase_started: + return Phase.NEXT + class PhaseUpdateSerializer(PhaseSerializer): tasks = PhaseTaskInstanceSerializer(source='task_instances', many=True) diff --git a/src/static/riot/competitions/detail/_tabs.tag b/src/static/riot/competitions/detail/_tabs.tag index 3ef4279b3..6102bf2cf 100644 --- a/src/static/riot/competitions/detail/_tabs.tag +++ b/src/static/riot/competitions/detail/_tabs.tag @@ -289,40 +289,6 @@ }) }) - // loop over competition phases to mark if phase has started or ended - self.competition.phases.forEach(function (phase, index) { - - phase_ended = false - phase_started = false - - // check if phase has started - if((Date.parse(phase["start"]) - Date.parse(new Date())) > 0){ - // start date is in the future, phase started = NO - phase_started = false - }else{ - // start date is not in the future, phase started = YES - phase_started = true - } - - if(phase_started){ - // check if end data exists for this phase - if(phase["end"]){ - if((Date.parse(phase["end"]) - Date.parse(new Date())) < 0){ - // Phase cannote accept submissions if end date is in the past - phase_ended = true - }else{ - // Phase can accept submissions if end date is in the future - phase_ended = false - } - }else{ - // Phase can accept submissions if end date is not given - phase_ended = false - } - } - self.competition.phases[index]["phase_ended"] = phase_ended - self.competition.phases[index]["phase_started"] = phase_started - }) - self.competition.is_admin = CODALAB.state.user.has_competition_admin_privileges(competition) self.selected_phase_index = _.get(_.find(self.competition.phases, {'status': 'Current'}), 'id') if (self.selected_phase_index == null) { diff --git a/src/static/riot/competitions/detail/submission_upload.tag b/src/static/riot/competitions/detail/submission_upload.tag index 76728a5ee..792842582 100644 --- a/src/static/riot/competitions/detail/submission_upload.tag +++ b/src/static/riot/competitions/detail/submission_upload.tag @@ -1,11 +1,10 @@ -
+

Submission upload

-
This phase has ended and no longer accepts submissions!
-
This phase hasn't started yet!
+
This phase has ended and no longer accepts submissions!
+
This phase hasn't started yet!

Metadata or Fact Sheet

@@ -353,7 +352,7 @@ self.check_can_upload = function () { // Check if selected phase accepts submissions (within the deadline of the phase) - if(self.selected_phase.phase_started && !self.selected_phase.phase_ended){ + if(self.selected_phase.status === "Current"){ CODALAB.api.can_make_submissions(self.selected_phase.id) .done(function (data) { @@ -368,13 +367,12 @@ }) }else{ // Error when phase is not accepting submissions - if(!self.selected_phase.phase_started){ + if(self.selected_phase.status === "Next"){ toastr.error('This phase has not started yet. Please check the phase start date!') - }else { - if(self.selected_phase.phase_ended){ - toastr.error('This phase has ended and no longer accepts submissions!') - } + } + if(self.selected_phase.status === "Previous"){ + toastr.error('This phase has ended and no longer accepts submissions!') } self.clear_form() }