Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions src/apps/api/serializers/competitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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)
Expand Down
34 changes: 0 additions & 34 deletions src/static/riot/competitions/detail/_tabs.tag
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 8 additions & 10 deletions src/static/riot/competitions/detail/submission_upload.tag
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<submission-upload>
<div class="ui sixteen wide column submission-container"
show="{_.get(selected_phase, 'status') === 'Current' || opts.is_admin}">
<div class="ui sixteen wide column submission-container">

<div class="submission-form">
<h1>Submission upload</h1>
<div if="{_.get(selected_phase, 'phase_ended')}" class="ui red message">This phase has ended and no longer accepts submissions!</div>
<div if="{!_.get(selected_phase, 'phase_started')}" class="ui yellow message">This phase hasn't started yet!</div>
<div if="{_.get(selected_phase, 'status') === 'Previous'}" class="ui red message">This phase has ended and no longer accepts submissions!</div>
<div if="{_.get(selected_phase, 'status') === 'Next'}" class="ui yellow message">This phase hasn't started yet!</div>
<form class="ui form coda-animated {error: errors}" ref="form" enctype="multipart/form-data">
<div class="submission-form" ref="fact_sheet_form" if="{ opts.fact_sheet !== null}">
<h2>Metadata or Fact Sheet</h2>
Expand Down Expand Up @@ -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) {
Expand All @@ -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()
}
Expand Down