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
15 changes: 15 additions & 0 deletions src/apps/api/serializers/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Meta:
'created_by',
'data_file',
'was_created_by_competition',
'competition',
'file_name',
)
read_only_fields = (
'key',
Expand Down Expand Up @@ -71,6 +73,7 @@ class Meta:

class DataDetailSerializer(serializers.ModelSerializer):
created_by = serializers.CharField(source='created_by.username')
competition = serializers.SerializerMethodField()

class Meta:
model = Data
Expand All @@ -86,8 +89,20 @@ class Meta:
'was_created_by_competition',
'in_use',
'file_size',
'competition',
'file_name',
)

def get_competition(self, obj):

# return competition dict with id and title if available
if obj.competition:
return {
"id": obj.competition.id,
"title": obj.competition.title,
}
return None


class DataGroupSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
1 change: 1 addition & 0 deletions src/apps/api/tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_dataset_api_checks_duplicate_names_for_same_user(self):
'name': 'Test!',
'type': Data.COMPETITION_BUNDLE,
'request_sassy_file_name': faker.file_name(),
'file_name': faker.file_name(),
})

assert resp.status_code == 400
Expand Down
1 change: 1 addition & 0 deletions src/apps/api/views/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def get_serializer_class(self):
return serializers.DataSerializer

def create(self, request, *args, **kwargs):

serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
new_dataset = serializer.save() # request_sassy_file_name is temporarily set via this serializer
Expand Down
25 changes: 25 additions & 0 deletions src/apps/datasets/migrations/0005_auto_20230527_0837.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.2.17 on 2023-05-27 08:37

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


class Migration(migrations.Migration):

dependencies = [
('competitions', '0032_submission_worker_hostname'),
('datasets', '0004_data_deleted'),
]

operations = [
migrations.AddField(
model_name='data',
name='competition',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='submission', to='competitions.Competition'),
),
migrations.AddField(
model_name='data',
name='file_name',
field=models.CharField(default='', max_length=64),
),
]
4 changes: 4 additions & 0 deletions src/apps/datasets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from chahub.models import ChaHubSaveMixin
from utils.data import PathWrapper
from utils.storage import BundleStorage
from competitions.models import Competition


class Data(ChaHubSaveMixin, models.Model):
Expand Down Expand Up @@ -57,6 +58,9 @@ 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')
file_name = models.CharField(max_length=64, default="")

def get_download_url(self):
return reverse('datasets:download', kwargs={'key': self.key})

Expand Down
1 change: 1 addition & 0 deletions src/static/js/ours/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ CODALAB.api = {
create_dataset: function (metadata, data_file, progress_update_callback) {
// Pass the requested file name for the SAS url
metadata.request_sassy_file_name = data_file.name
metadata.file_name = data_file.name

// This will be set on successful dataset creation, then used to complete the dataset upload
var dataset = {}
Expand Down
3 changes: 2 additions & 1 deletion src/static/riot/competitions/detail/submission_upload.tag
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@
task_ids_to_run = [self.selected_tasks[0].id]
}
var data_file_metadata = {
type: 'submission'
type: 'submission',
competition: self.opts.competition.id
}
var data_file = self.refs.data_file.refs.file_input.files[0]
self.children = []
Expand Down
19 changes: 15 additions & 4 deletions src/static/riot/datasets/management.tag
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<table class="ui {selectable: datasets.length > 0} celled compact table">
<thead>
<tr>
<th>Name</th>
<th>File Name</th>
<th>Competition in</th>
<th width="175px">Type</th>
<th width="175px">Size</th>
<th width="125px">Uploaded</th>
Expand All @@ -45,7 +46,12 @@
<tr each="{ dataset, index in datasets }"
class="dataset-row"
onclick="{show_info_modal.bind(this, dataset)}">
<td>{ dataset.name }</td>
<!-- show file name if exists otherwise show name(for old submissions) -->
<td>{ dataset.file_name || dataset.name }</td>
<!-- show compeition name as link if competition is available -->
<td if="{dataset.competition}"><a class="link-no-deco" target="_blank" href="../competitions/{ dataset.competition.id }">{ dataset.competition.title }</a></td>
<!-- show empty td if competition is not available -->
<td if="{!dataset.competition}"></td>
<td>{ dataset.type }</td>
<td>{ format_file_size(dataset.file_size) }</td>
<td>{ timeSince(Date.parse(dataset.created_when)) } ago</td>
Expand Down Expand Up @@ -80,7 +86,7 @@
Pagination
-------------------------------------->
<tr>
<th colspan="8" if="{datasets.length > 0}">
<th colspan="9" if="{datasets.length > 0}">
<div class="ui right floated pagination menu" if="{datasets.length > 0}">
<a show="{!!_.get(pagination, 'previous')}" class="icon item" onclick="{previous_page}">
<i class="left chevron icon"></i>
Expand All @@ -99,7 +105,7 @@

<div ref="info_modal" class="ui modal">
<div class="header">
{selected_row.name}
{selected_row.file_name || selected_row.name}
</div>
<div class="content">
<h3>Details</h3>
Expand All @@ -108,6 +114,7 @@
<thead>
<tr>
<th>Key</th>
<th>Competition in</th>
<th>Created By</th>
<th>Created</th>
<th>Type</th>
Expand All @@ -117,6 +124,10 @@
<tbody>
<tr>
<td>{selected_row.key}</td>
<!-- show compeition name as link if competition is available -->
<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>{pretty_date(selected_row.created_when)}</td>
<td>{_.startCase(selected_row.type)}</td>
Expand Down