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
4 changes: 4 additions & 0 deletions src/apps/api/serializers/competitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ class CompetitionUpdateSerializer(CompetitionSerializer):
queue = None


class CompetitionCreateSerializer(CompetitionSerializer):
queue = None


class CompetitionDetailSerializer(serializers.ModelSerializer):
created_by = serializers.CharField(source='created_by.username', read_only=True)
pages = PageSerializer(many=True)
Expand Down
9 changes: 8 additions & 1 deletion src/apps/api/tests/test_competitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rest_framework.test import APITestCase

from api.serializers.competitions import CompetitionSerializer
from competitions.models import CompetitionParticipant, Submission
from competitions.models import CompetitionParticipant, Submission, Competition
from factories import UserFactory, CompetitionFactory, CompetitionParticipantFactory, PhaseFactory, LeaderboardFactory, \
ColumnFactory, SubmissionFactory, SubmissionScoreFactory, TaskFactory

Expand Down Expand Up @@ -75,6 +75,13 @@ def test_adding_organizer_accepts_them_if_they_were_existing_participant(self):
status=CompetitionParticipant.APPROVED
).count() == 1

def test_delete_own_competition(self):
self.client.login(username='creator', password='creator')
url = reverse('competition-detail', kwargs={"pk": self.comp.pk})
resp = self.client.delete(url)
assert resp.status_code == 204
assert not Competition.objects.filter(pk=self.comp.pk).exists()


class PhaseMigrationTests(APITestCase):
def setUp(self):
Expand Down
8 changes: 4 additions & 4 deletions src/apps/api/views/competitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from api.pagination import LargePagination
from api.renderers import ZipRenderer
from rest_framework.viewsets import ModelViewSet
from api.serializers.competitions import CompetitionSerializer, CompetitionSerializerSimple, PhaseSerializer, \
from api.serializers.competitions import CompetitionSerializerSimple, PhaseSerializer, \
CompetitionCreationTaskStatusSerializer, CompetitionDetailSerializer, CompetitionParticipantSerializer, \
FrontPageCompetitionsSerializer, PhaseResultsSerializer, CompetitionUpdateSerializer
FrontPageCompetitionsSerializer, PhaseResultsSerializer, CompetitionUpdateSerializer, CompetitionCreateSerializer
from api.serializers.leaderboards import LeaderboardPhaseSerializer, LeaderboardSerializer
from competitions.emails import send_participation_requested_emails, send_participation_accepted_emails, \
send_participation_denied_emails, send_direct_participant_email
Expand Down Expand Up @@ -146,7 +146,8 @@ def get_serializer_class(self):
elif self.request.method == 'PATCH':
return CompetitionUpdateSerializer
else:
return CompetitionSerializer
# Really just CompetitionSerializer with queue = None
return CompetitionCreateSerializer

def create(self, request, *args, **kwargs):
"""Mostly a copy of the underlying base create, however we return some additional data
Expand All @@ -158,7 +159,6 @@ def create(self, request, *args, **kwargs):

# TODO - This is Temporary. Need to change Leaderboard to Phase connect to M2M and handle this correctly.
# save leaderboard individually, then pass pk to each phase
print(f"{request.data['leaderboards']}")
data = request.data
if 'leaderboards' in data:
leaderboard_data = data['leaderboards'][0]
Expand Down
3 changes: 2 additions & 1 deletion src/apps/competitions/unpackers/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def _unpack_leaderboards(self):
except KeyError:
raise CompetitionUnpackingException('Could not find leaderboards declared on the competition leaderboard')
try:
columns = sorted([{'title': k, **v} for k, v in leaderboard['columns'].items()], key=lambda c: c['rank'])
# use rank = 1 if rank is not defined in .yaml file
columns = sorted([{'title': k, **v} for k, v in leaderboard['columns'].items()], key=lambda c: c.get('rank', 1))
except KeyError:
raise CompetitionUnpackingException('Could not find columns declared on the competition leaderboard')

Expand Down
19 changes: 19 additions & 0 deletions src/apps/datasets/migrations/0007_auto_20230609_1738.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.17 on 2023-06-09 17:38

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('datasets', '0006_auto_20230528_0829'),
]

operations = [
migrations.AlterField(
model_name='data',
name='competition',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='submission', to='competitions.Competition'),
),
]
2 changes: 1 addition & 1 deletion src/apps/datasets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Data(ChaHubSaveMixin, models.Model):
# are NOT marked True, since they are not created by unpacking!
was_created_by_competition = models.BooleanField(default=False)

competition = models.ForeignKey(Competition, on_delete=models.PROTECT, null=True, related_name='submission')
competition = models.ForeignKey(Competition, on_delete=models.CASCADE, null=True, related_name='submission')
file_name = models.CharField(max_length=64, default="")

def get_download_url(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
</div>
<div class="field required">
<label>Competition Docker Image</label>
<input type="text" ref="docker_image" onchange="{form_updated}">
<input type="text" ref="docker_image" onchange="{form_updated}" value="codalab/codalab-legacy:py37">
</div>
<div class="field">
<label>Competition Type</label>
Expand Down
6 changes: 4 additions & 2 deletions src/static/riot/competitions/editor/_phases.tag
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@

self.has_initialized_calendars = true
}
$(self.refs.calendar_start).calendar('set date', self.phases[self.selected_phase_index].start)
$(self.refs.calendar_end).calendar('set date', self.phases[self.selected_phase_index].end)
if(!(self.selected_phase_index === undefined)){
$(self.refs.calendar_start).calendar('set date', self.phases[self.selected_phase_index].start)
$(self.refs.calendar_end).calendar('set date', self.phases[self.selected_phase_index].end)
}
}

self.close_modal = function () {
Expand Down
4 changes: 2 additions & 2 deletions src/static/riot/competitions/public-list.tag
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<public-list>
<h1>Public Competitions</h1>
<div class="pagination-nav" hide="{(get_array_length(competitions.results) === competitions.count) || (get_array_length(competitions.results) < 10)}">
<div class="pagination-nav" hide="{(get_array_length(competitions.results) === competitions.count) || (get_array_length(competitions.results) < 10)}">
<button show="{competitions.previous}" onclick="{handle_ajax_pages.bind(this, -1)}" class="float-left ui inline button active">Back</button>
<button hide="{competitions.previous}" disabled="disabled" class="float-left ui inline button disabled">Back</button>
{ current_page } of {Math.ceil(competitions.count/competitions.page_size)}
Expand Down Expand Up @@ -32,7 +32,7 @@
</div>
</a>
</div>
<div class="pagination-nav" hide="{get_array_length(competitions.results) === competitions.count}">
<div class="pagination-nav" hide="{(get_array_length(competitions.results) === competitions.count) || (get_array_length(competitions.results) < 10)}}">
<button show="{competitions.previous}" onclick="{handle_ajax_pages.bind(this, -1)}" class="float-left ui inline button active">Back</button>
<button hide="{competitions.previous}" disabled="disabled" class="float-left ui inline button disabled">Back</button>
{ current_page } of {Math.ceil(competitions.count/competitions.page_size)}
Expand Down
2 changes: 1 addition & 1 deletion src/static/riot/datasets/management.tag
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<tbody>
<tr>
<td>{selected_row.key}</td>
<td>{selected_row.created_by}</td>
<td><a href="/profiles/user/{selected_row.created_by}/" target=_blank>{selected_row.created_by}</a></td>
<td>{pretty_date(selected_row.created_when)}</td>
<td>{_.startCase(selected_row.type)}</td>
<td>{_.startCase(selected_row.is_public)}</td>
Expand Down
2 changes: 1 addition & 1 deletion src/static/riot/submissions/resource_submissions.tag
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<td if="{selected_row.competition}"><a class="link-no-deco" target="_blank" href="../competitions/{ selected_row.competition.id }">{ selected_row.competition.title }</a></td>
<!-- show empty td if competition is not available -->
<td if="{!selected_row.competition}"></td>
<td>{selected_row.created_by}</td>
<td><a href="/profiles/user/{selected_row.created_by}/" target=_blank>{selected_row.created_by}</a></td>
<td>{pretty_date(selected_row.created_when)}</td>
<td>{_.startCase(selected_row.type)}</td>
<td>{_.startCase(selected_row.is_public)}</td>
Expand Down
2 changes: 1 addition & 1 deletion src/static/riot/tasks/management.tag
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<div class="content">
<h4>{selected_task.description}</h4>
<div class="ui divider" show="{selected_task.description}"></div>
<div><strong>Created By:</strong> {selected_task.created_by}</div>
<div><strong>Created By:</strong> <a href="/profiles/user/{selected_task.created_by}/" target=_blank>{selected_task.created_by}</a></div>
<div><strong>Key:</strong> {selected_task.key}</div>
<div><strong>Has Been Validated
<span data-tooltip="A task has been validated once one of its solutions has successfully been run against it">
Expand Down
6 changes: 2 additions & 4 deletions src/templates/pages/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<div class="ui text container">
<img id="jumbo_logo" src="{% static "img/codabench.png" %}">
<h2 class="subtitle"><h1> BETA </h1></h2>
<!--<h2 class="subtitle"><h1> Subtitle </h1></h2>-->
</div>

{% endblock %}
Expand All @@ -23,10 +23,8 @@ <h2 class="subtitle"><h1> BETA </h1></h2>
<div class="center aligned column">
<h3 class="ui icon header">
<!-- <i class="trophy icon"></i> -->
<p style="font-weight: bold;">Welcome to Codabench!</p>
</h3>
<div>
<p style="font-weight: bold;">Welcome to Codabench Beta !</p>
</div>
</div>
</div>
</div>
Expand Down