From 7fa7333ef34136fef36265630490b4be695928ec Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Mon, 8 May 2023 14:40:03 +0500 Subject: [PATCH 01/23] dump creation date fixed --- src/apps/competitions/tasks.py | 9 ++++++--- src/static/riot/competitions/detail/_header.tag | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/apps/competitions/tasks.py b/src/apps/competitions/tasks.py index 804109ce3..4f4fe8ce2 100644 --- a/src/apps/competitions/tasks.py +++ b/src/apps/competitions/tasks.py @@ -4,7 +4,8 @@ import re import traceback import zipfile -from datetime import timedelta +from datetime import timedelta, datetime + from io import BytesIO from tempfile import TemporaryDirectory, NamedTemporaryFile @@ -431,7 +432,9 @@ def create_competition_dump(competition_pk, keys_instead_of_files=True): logger.info(f"Finding competition {competition_pk}") comp = Competition.objects.get(pk=competition_pk) zip_buffer = BytesIO() - zip_name = f"{comp.title}-{comp.created_when.isoformat()}.zip" + current_date_time = datetime.now() + current_date = datetime.today().strftime('%Y-%m-%d') + zip_name = f"{comp.title}-{current_date_time.isoformat()}.zip" zip_file = zipfile.ZipFile(zip_buffer, "w") # -------- Main Competition Details ------- @@ -626,7 +629,7 @@ def create_competition_dump(competition_pk, keys_instead_of_files=True): bundle_count = CompetitionDump.objects.count() + 1 temp_dataset_bundle = Data.objects.create( created_by=comp.created_by, - name=f"{comp.title} Dump #{bundle_count} Created {comp.created_when.date()}", + name=f"{comp.title} Dump #{bundle_count} Created {current_date}", type='competition_bundle', description='Automatically created competition dump', # 'data_file'=, diff --git a/src/static/riot/competitions/detail/_header.tag b/src/static/riot/competitions/detail/_header.tag index 55950fa64..69256387d 100644 --- a/src/static/riot/competitions/detail/_header.tag +++ b/src/static/riot/competitions/detail/_header.tag @@ -190,6 +190,7 @@ self.update_files = (e) => { CODALAB.api.get_competition_files(self.competition.id) .done(data => { + console.log(data) self.files = data self.tr_show = false self.update() From 9f7a1b5ee26753985c9942a817a2e590efb94ba4 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Tue, 9 May 2023 22:23:41 +0500 Subject: [PATCH 02/23] v1 bundle unpacking: use column label as title --- src/apps/competitions/unpackers/v1.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/apps/competitions/unpackers/v1.py b/src/apps/competitions/unpackers/v1.py index a2dcf5386..ed7c6dc85 100644 --- a/src/apps/competitions/unpackers/v1.py +++ b/src/apps/competitions/unpackers/v1.py @@ -158,7 +158,8 @@ def _unpack_leaderboards(self): for index, column in enumerate(columns): new_col_data = { - 'title': column['title'], + # get label as title, if not found, use title by default + 'title': column.get('label', column['title']), 'key': column['title'], 'index': index, 'sorting': column.get('sort') or 'desc', From 8be721c32e4c12d23e0d0f18bf63d2c67b76d130 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Tue, 9 May 2023 22:32:55 +0500 Subject: [PATCH 03/23] title updated in V1_Leaderboard --- src/apps/competitions/tests/unpacker_test_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/competitions/tests/unpacker_test_data.py b/src/apps/competitions/tests/unpacker_test_data.py index 8e04f5785..eb38945e9 100644 --- a/src/apps/competitions/tests/unpacker_test_data.py +++ b/src/apps/competitions/tests/unpacker_test_data.py @@ -149,7 +149,7 @@ "label": "RESULTS", "columns": [ { - "title": "prediction_score", + "title": "Prediction score", "key": "prediction_score", "index": 0, "sorting": "desc", From 915b14dcc53eed05d0187a24057a06415c3672dc Mon Sep 17 00:00:00 2001 From: Benjamin Date: Wed, 10 May 2023 00:01:27 -0400 Subject: [PATCH 04/23] hostname in server_status --- compute_worker/compute_worker.py | 8 ++++++-- src/apps/api/views/submissions.py | 11 +++++++++++ .../0032_submission_worker_hostname.py | 18 ++++++++++++++++++ src/apps/competitions/models.py | 2 ++ src/templates/pages/server_status.html | 2 ++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/apps/competitions/migrations/0032_submission_worker_hostname.py diff --git a/compute_worker/compute_worker.py b/compute_worker/compute_worker.py index fb0d66b30..09544b03c 100644 --- a/compute_worker/compute_worker.py +++ b/compute_worker/compute_worker.py @@ -22,7 +22,7 @@ import websockets import yaml from billiard.exceptions import SoftTimeLimitExceeded -from celery import Celery, task +from celery import Celery, task, utils from kombu import Queue, Exchange from urllib3 import Retry @@ -309,6 +309,9 @@ def _update_submission(self, data): def _update_status(self, status, extra_information=None): if status not in AVAILABLE_STATUSES: raise SubmissionException(f"Status '{status}' is not in available statuses: {AVAILABLE_STATUSES}") + + # from celery.contrib import rdb + # rdb.set_trace() data = { "status": status, "status_details": extra_information, @@ -663,8 +666,9 @@ def prepare(self): self._get_container_image(self.container_image) def start(self): + hostname = utils.nodenames.gethostname() if not self.is_scoring: - self._update_status(STATUS_RUNNING) + self._update_status(STATUS_RUNNING, extra_information=f"hostname-{hostname}") program_dir = os.path.join(self.root_dir, "program") ingestion_program_dir = os.path.join(self.root_dir, "ingestion_program") diff --git a/src/apps/api/views/submissions.py b/src/apps/api/views/submissions.py index aaf7386b6..03f7107ba 100644 --- a/src/apps/api/views/submissions.py +++ b/src/apps/api/views/submissions.py @@ -37,6 +37,17 @@ def check_object_permissions(self, request, obj): raise PermissionDenied("Cannot add task-specific submission re-runs to leaderboards.") return if self.request and self.request.method in ('POST', 'PUT', 'PATCH'): + dir(self.request) + # import pdb; pdb.set_trace() + # self.request.data + # Set hostname of submission - could be better + if "status_details" in self.request.data.keys(): + if request.data['status_details'].find('hostname') != -1: + # import pdb; pdb.set_trace() + hostname = request.data['status_details'].replace('hostname-','') + obj.worker_hostname = hostname + obj.save() + not_bot_user = self.request.user.is_authenticated and not self.request.user.is_bot if self.action in ['update_fact_sheet', 're_run_submission']: diff --git a/src/apps/competitions/migrations/0032_submission_worker_hostname.py b/src/apps/competitions/migrations/0032_submission_worker_hostname.py new file mode 100644 index 000000000..0586a5978 --- /dev/null +++ b/src/apps/competitions/migrations/0032_submission_worker_hostname.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.17 on 2023-05-09 04:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('competitions', '0031_auto_20230504_1016'), + ] + + operations = [ + migrations.AddField( + model_name='submission', + name='worker_hostname', + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] diff --git a/src/apps/competitions/models.py b/src/apps/competitions/models.py index 9c5be88ef..64117b937 100644 --- a/src/apps/competitions/models.py +++ b/src/apps/competitions/models.py @@ -452,6 +452,8 @@ class Submission(ChaHubSaveMixin, models.Model): started_when = models.DateTimeField(null=True) is_public = models.BooleanField(default=False) is_specific_task_re_run = models.BooleanField(default=False) + + worker_hostname = models.CharField(max_length=255, blank=True, null=True) is_migrated = models.BooleanField(default=False) created_by_migration = models.ForeignKey(Phase, related_name='migrated_submissions', on_delete=models.CASCADE, diff --git a/src/templates/pages/server_status.html b/src/templates/pages/server_status.html index b9d0dd294..0ff214291 100644 --- a/src/templates/pages/server_status.html +++ b/src/templates/pages/server_status.html @@ -12,6 +12,7 @@

Recent submissions (up to 250 or 2 days old)

Competition Submission PK Submitter + Hostname Submitted at Status @@ -26,6 +27,7 @@

Recent submissions (up to 250 or 2 days old)

{{ submission.phase.competition }} {{ submission.pk }} {{ submission.owner.username }} + {{ submission.worker_hostname }} {{ submission.created_when|timesince }} ago {{ submission.status }} From 63d0f3e0745ab0a95d074566d9d40d3ee887ee3a Mon Sep 17 00:00:00 2001 From: Benjamin Date: Wed, 10 May 2023 00:08:16 -0400 Subject: [PATCH 05/23] flake8 --- src/apps/api/views/submissions.py | 1 - src/apps/competitions/models.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/apps/api/views/submissions.py b/src/apps/api/views/submissions.py index 03f7107ba..88ef62024 100644 --- a/src/apps/api/views/submissions.py +++ b/src/apps/api/views/submissions.py @@ -47,7 +47,6 @@ def check_object_permissions(self, request, obj): hostname = request.data['status_details'].replace('hostname-','') obj.worker_hostname = hostname obj.save() - not_bot_user = self.request.user.is_authenticated and not self.request.user.is_bot if self.action in ['update_fact_sheet', 're_run_submission']: diff --git a/src/apps/competitions/models.py b/src/apps/competitions/models.py index 64117b937..f355802d1 100644 --- a/src/apps/competitions/models.py +++ b/src/apps/competitions/models.py @@ -452,9 +452,7 @@ class Submission(ChaHubSaveMixin, models.Model): started_when = models.DateTimeField(null=True) is_public = models.BooleanField(default=False) is_specific_task_re_run = models.BooleanField(default=False) - worker_hostname = models.CharField(max_length=255, blank=True, null=True) - is_migrated = models.BooleanField(default=False) created_by_migration = models.ForeignKey(Phase, related_name='migrated_submissions', on_delete=models.CASCADE, null=True, From d5be6486edbc75bd3f062e15ab9bd09a91ba9912 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Wed, 10 May 2023 00:12:12 -0400 Subject: [PATCH 06/23] missing whitespace after ',' --- src/apps/api/views/submissions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/api/views/submissions.py b/src/apps/api/views/submissions.py index 88ef62024..a87363d4e 100644 --- a/src/apps/api/views/submissions.py +++ b/src/apps/api/views/submissions.py @@ -44,7 +44,7 @@ def check_object_permissions(self, request, obj): if "status_details" in self.request.data.keys(): if request.data['status_details'].find('hostname') != -1: # import pdb; pdb.set_trace() - hostname = request.data['status_details'].replace('hostname-','') + hostname = request.data['status_details'].replace('hostname-', '') obj.worker_hostname = hostname obj.save() not_bot_user = self.request.user.is_authenticated and not self.request.user.is_bot From eeab5add633e71262053b7f0a5620f444db83f23 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Wed, 10 May 2023 12:18:18 +0500 Subject: [PATCH 07/23] show compeittion in Benchmark Im running when user is collaborator --- src/apps/api/views/competitions.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index ef90394a4..e41a13c97 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -35,6 +35,8 @@ from leaderboards.models import Leaderboard from utils.data import make_url_sassy from api.permissions import IsOrganizerOrCollaborator +import logging +logger = logging.getLogger() class CompetitionViewSet(ModelViewSet): @@ -56,7 +58,14 @@ def get_queryset(self): mine = self.request.query_params.get('mine', None) if mine: - qs = qs.filter(created_by=self.request.user) + # either competition is mine + # or + # I am one of the collaborator + qs = Competition.objects.filter( + (Q(created_by=self.request.user)) | + (Q(collaborators__in=[self.request.user])) + + ) participating_in = self.request.query_params.get('participating_in', None) From 05a73da33901bc8395d5534a5d7cea181fdf430e Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Wed, 10 May 2023 12:23:54 +0500 Subject: [PATCH 08/23] white space removed --- src/apps/api/views/competitions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index e41a13c97..a3d011233 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -58,7 +58,7 @@ def get_queryset(self): mine = self.request.query_params.get('mine', None) if mine: - # either competition is mine + # either competition is mine # or # I am one of the collaborator qs = Competition.objects.filter( From 38d6664fa9fff25cd2a046703722f36b6da080c3 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Wed, 10 May 2023 14:50:04 +0500 Subject: [PATCH 09/23] collaborator can access a private competition. --- src/apps/api/views/competitions.py | 8 ++++++-- src/apps/competitions/views.py | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index ef90394a4..5c030f0ec 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -35,6 +35,7 @@ from leaderboards.models import Leaderboard from utils.data import make_url_sassy from api.permissions import IsOrganizerOrCollaborator +import logging; logger = logging.getLogger() class CompetitionViewSet(ModelViewSet): @@ -69,10 +70,11 @@ def get_queryset(self): ).values_list('status')[:1] qs = qs.annotate(participant_status=Subquery(participant_status_query)) - # new condition for search bar + # new condition # `mine` is true when this is called from "Benchmarks I'm Running" # `participating_in` is true when this is called from "Benchmarks I'm in" - # `mine` and `participating_in` are none when this is called from Search bar + # `mine` and `participating_in` are none when this is called either from Search bar + # or from competition detail page if (not mine) and (not participating_in): # User is logged in # filter his own competitions @@ -80,6 +82,7 @@ def get_queryset(self): # filter published competitions by other users qs = qs.filter( (Q(created_by=self.request.user)) | + (Q(collaborators__in=[self.request.user])) | (Q(published=True) & ~Q(created_by=self.request.user)) ) else: @@ -111,6 +114,7 @@ def get_queryset(self): ) search_query = self.request.query_params.get('search') + # search_query is true when called from searchbar if search_query: qs = qs.filter(Q(title__icontains=search_query) | Q(description__icontains=search_query)) diff --git a/src/apps/competitions/views.py b/src/apps/competitions/views.py index 581392fa1..61d09e0f3 100644 --- a/src/apps/competitions/views.py +++ b/src/apps/competitions/views.py @@ -28,13 +28,16 @@ class CompetitionDetail(DetailView): def get_object(self, *args, **kwargs): competition = super().get_object(*args, **kwargs) - is_creator, is_collaborator, is_participant = False, False, False + is_admin, is_creator, is_collaborator, is_participant = False, False, False, False # check if user is loggedin if self.request.user.is_authenticated: + # check if user is admin + is_admin = self.request.user.is_superuser + # check if user is the creator of this competition - is_creator = self.request.user.is_superuser or self.request.user == competition.created_by + is_creator = self.request.user == competition.created_by # check if user is collaborator of this competition is_collaborator = self.request.user in competition.collaborators.all() @@ -46,7 +49,14 @@ def get_object(self, *args, **kwargs): # check if secret key provided is valid valid_secret_key = self.request.GET.get('secret_key') == str(competition.secret_key) - if is_creator or is_collaborator or competition.published or valid_secret_key or is_participant: + if ( + is_admin or + is_creator or + is_collaborator or + competition.published or + valid_secret_key or + is_participant + ): return competition raise Http404() From 119b1dbe7c0354c5596a967715d2d6b68a1dd407 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Wed, 10 May 2023 14:53:37 +0500 Subject: [PATCH 10/23] removed unused import --- src/apps/api/views/competitions.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index 5c030f0ec..eedbf7144 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -35,7 +35,6 @@ from leaderboards.models import Leaderboard from utils.data import make_url_sassy from api.permissions import IsOrganizerOrCollaborator -import logging; logger = logging.getLogger() class CompetitionViewSet(ModelViewSet): From 42b2e3bb7caa562f39ffdcc2077f99d3ae9f6962 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Wed, 10 May 2023 15:13:41 +0500 Subject: [PATCH 11/23] participant can not access a private competition --- src/apps/api/views/competitions.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index eedbf7144..36c61e608 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -75,13 +75,18 @@ def get_queryset(self): # `mine` and `participating_in` are none when this is called either from Search bar # or from competition detail page if (not mine) and (not participating_in): - # User is logged in - # filter his own competitions + # User is logged in then show + # compeitions which this user owns # or - # filter published competitions by other users + # compeititions in which this user is collaborator + # or + # competitions in which this user is participant and status is approved + # or + # compeitions is published and belongs to someone else qs = qs.filter( (Q(created_by=self.request.user)) | (Q(collaborators__in=[self.request.user])) | + (Q(participants__user=self.request.user, participants__status="approved")) | (Q(published=True) & ~Q(created_by=self.request.user)) ) else: From b3eb96c644e31cd3356450887da9a1a61446cfdb Mon Sep 17 00:00:00 2001 From: Benjamin Bearce Date: Wed, 10 May 2023 09:54:55 -0400 Subject: [PATCH 12/23] Update compute_worker.py remove rdb commands --- compute_worker/compute_worker.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compute_worker/compute_worker.py b/compute_worker/compute_worker.py index 09544b03c..c8bef06d1 100644 --- a/compute_worker/compute_worker.py +++ b/compute_worker/compute_worker.py @@ -309,9 +309,7 @@ def _update_submission(self, data): def _update_status(self, status, extra_information=None): if status not in AVAILABLE_STATUSES: raise SubmissionException(f"Status '{status}' is not in available statuses: {AVAILABLE_STATUSES}") - - # from celery.contrib import rdb - # rdb.set_trace() + data = { "status": status, "status_details": extra_information, From 70d94e886e5d0f32600c7c23a32f1e95bafb3f7b Mon Sep 17 00:00:00 2001 From: Benjamin Bearce Date: Wed, 10 May 2023 09:55:26 -0400 Subject: [PATCH 13/23] Update submissions.py remove rdb --- src/apps/api/views/submissions.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/apps/api/views/submissions.py b/src/apps/api/views/submissions.py index a87363d4e..3fae5589c 100644 --- a/src/apps/api/views/submissions.py +++ b/src/apps/api/views/submissions.py @@ -38,9 +38,7 @@ def check_object_permissions(self, request, obj): return if self.request and self.request.method in ('POST', 'PUT', 'PATCH'): dir(self.request) - # import pdb; pdb.set_trace() - # self.request.data - # Set hostname of submission - could be better + # Set hostname of submission if "status_details" in self.request.data.keys(): if request.data['status_details'].find('hostname') != -1: # import pdb; pdb.set_trace() From 3267648a051cf239d6363c6159d465f383304b0a Mon Sep 17 00:00:00 2001 From: Benjamin Bearce Date: Wed, 10 May 2023 09:55:52 -0400 Subject: [PATCH 14/23] Update submissions.py remove pdb --- src/apps/api/views/submissions.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/apps/api/views/submissions.py b/src/apps/api/views/submissions.py index 3fae5589c..75e75df47 100644 --- a/src/apps/api/views/submissions.py +++ b/src/apps/api/views/submissions.py @@ -41,7 +41,6 @@ def check_object_permissions(self, request, obj): # Set hostname of submission if "status_details" in self.request.data.keys(): if request.data['status_details'].find('hostname') != -1: - # import pdb; pdb.set_trace() hostname = request.data['status_details'].replace('hostname-', '') obj.worker_hostname = hostname obj.save() From 509e4774c97715188532ab72a51857161dadd01f Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Wed, 10 May 2023 21:19:02 +0500 Subject: [PATCH 15/23] fixed the participants part of query --- src/apps/api/views/competitions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index 36c61e608..f252cd375 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -75,20 +75,20 @@ def get_queryset(self): # `mine` and `participating_in` are none when this is called either from Search bar # or from competition detail page if (not mine) and (not participating_in): - # User is logged in then show + # User is logged in then filter # compeitions which this user owns # or # compeititions in which this user is collaborator # or - # competitions in which this user is participant and status is approved - # or # compeitions is published and belongs to someone else qs = qs.filter( (Q(created_by=self.request.user)) | (Q(collaborators__in=[self.request.user])) | - (Q(participants__user=self.request.user, participants__status="approved")) | (Q(published=True) & ~Q(created_by=self.request.user)) ) + # or + # competitions in which this user is participant and status is approved + qs = qs.filter(participants__user=self.request.user, participants__status="approved") else: # if user is not authenticated only filter published/public competitions qs = qs.filter(Q(published=True)) From 55950bb5ada07ac64e342f5894e764f4fa68eb91 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Thu, 11 May 2023 13:34:23 +0500 Subject: [PATCH 16/23] by default files will be downloaded instead of just keys used in yaml. This dump when uploaded to codabench creates a new competition successfully --- src/apps/api/views/competitions.py | 6 +++++- src/apps/competitions/tasks.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index 342e237ce..b07600f07 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -358,7 +358,11 @@ def create_dump(self, request, pk=None): competition = self.get_object() if not competition.user_has_admin_permission(request.user): raise PermissionDenied("You don't have access") - create_competition_dump.delay(pk) + + # arg 1: pk: competition primary key + # arg 2: False: keys_instead_of_files (if false: files will be dowloaded in dumps, if true: only keys) + create_competition_dump.delay(pk, False) + serializer = CompetitionCreationTaskStatusSerializer({"status": "Success. Competition dump is being created."}) return Response(serializer.data, status=201) diff --git a/src/apps/competitions/tasks.py b/src/apps/competitions/tasks.py index 4f4fe8ce2..3fd41d79f 100644 --- a/src/apps/competitions/tasks.py +++ b/src/apps/competitions/tasks.py @@ -424,7 +424,7 @@ def _get_error_string(error_dict): @app.task(queue='site-worker', soft_time_limit=60 * 10) -def create_competition_dump(competition_pk, keys_instead_of_files=True): +def create_competition_dump(competition_pk, keys_instead_of_files=False): yaml_data = {"version": "2"} try: # -------- SetUp ------- From 7c7916d0e128a2999bb9187bf1efd5c81c092dc1 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Thu, 11 May 2023 16:39:51 +0500 Subject: [PATCH 17/23] date-time converted to readbale format --- src/apps/competitions/tasks.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/apps/competitions/tasks.py b/src/apps/competitions/tasks.py index 3fd41d79f..96a1a1d16 100644 --- a/src/apps/competitions/tasks.py +++ b/src/apps/competitions/tasks.py @@ -432,9 +432,8 @@ def create_competition_dump(competition_pk, keys_instead_of_files=False): logger.info(f"Finding competition {competition_pk}") comp = Competition.objects.get(pk=competition_pk) zip_buffer = BytesIO() - current_date_time = datetime.now() - current_date = datetime.today().strftime('%Y-%m-%d') - zip_name = f"{comp.title}-{current_date_time.isoformat()}.zip" + current_date_time = datetime.today().strftime('%Y-%m-%d %H:%M:%S') + zip_name = f"{comp.title}-{current_date_time}.zip" zip_file = zipfile.ZipFile(zip_buffer, "w") # -------- Main Competition Details ------- @@ -629,7 +628,7 @@ def create_competition_dump(competition_pk, keys_instead_of_files=False): bundle_count = CompetitionDump.objects.count() + 1 temp_dataset_bundle = Data.objects.create( created_by=comp.created_by, - name=f"{comp.title} Dump #{bundle_count} Created {current_date}", + name=f"{comp.title} Dump #{bundle_count} Created {current_date_time}", type='competition_bundle', description='Automatically created competition dump', # 'data_file'=, From 6280ab13839c951e88c3c1d57d57f0204ba70721 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Thu, 11 May 2023 18:35:48 +0500 Subject: [PATCH 18/23] queue added to competition while unpacking from YAML --- .../competitions/unpackers/base_unpacker.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/apps/competitions/unpackers/base_unpacker.py b/src/apps/competitions/unpackers/base_unpacker.py index 8a10dc77f..2b1ac3a06 100644 --- a/src/apps/competitions/unpackers/base_unpacker.py +++ b/src/apps/competitions/unpackers/base_unpacker.py @@ -201,15 +201,24 @@ def _unpack_image(self): def _unpack_queue(self): # Get Queue by vhost/uuid. If instance not returned, or we don't have access don't set it! - vhost = self.competition_yaml.get('queue') - if vhost: + queue_name = self.competition_yaml.get('queue') + if queue_name: try: - queue = Queue.objects.get(vhost=vhost) + queue = Queue.objects.get(name=queue_name) if not queue.is_public: all_queue_organizer_names = queue.organizers.all().values_list('username', flat=True) if queue.owner != self.creator and self.creator.username not in all_queue_organizer_names: raise CompetitionUnpackingException("You do not have access to the specified queue!") - self.competition['queue'] = queue.id + self.competition['queue'] = { + 'name': queue.name, + 'vhost': queue.vhost, + 'is_public': queue.is_public, + 'owner': queue.owner, + 'organizers': queue.organizers, + 'broker_url': queue.broker_url, + 'created_when': queue.broker_url, + 'id': queue.id, + } except Queue.DoesNotExist: raise CompetitionUnpackingException("The specified Queue does not exist!") From 4b689f67f3294082fce23378b28e22a7c32d2d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Pav=C3=A3o?= Date: Thu, 11 May 2023 16:12:17 +0200 Subject: [PATCH 19/23] Update competitions.py --- src/apps/api/views/competitions.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index f252cd375..d806466d1 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -69,7 +69,6 @@ def get_queryset(self): ).values_list('status')[:1] qs = qs.annotate(participant_status=Subquery(participant_status_query)) - # new condition # `mine` is true when this is called from "Benchmarks I'm Running" # `participating_in` is true when this is called from "Benchmarks I'm in" # `mine` and `participating_in` are none when this is called either from Search bar @@ -78,9 +77,9 @@ def get_queryset(self): # User is logged in then filter # compeitions which this user owns # or - # compeititions in which this user is collaborator + # competitions in which this user is collaborator # or - # compeitions is published and belongs to someone else + # competitions is published and belongs to someone else qs = qs.filter( (Q(created_by=self.request.user)) | (Q(collaborators__in=[self.request.user])) | From 547cd0e66fe1943cb6b7ccfe7183134a05160420 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Thu, 11 May 2023 19:30:52 +0500 Subject: [PATCH 20/23] participant condition fixed for private competition --- src/apps/api/views/competitions.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index f252cd375..56294277f 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -81,14 +81,14 @@ def get_queryset(self): # compeititions in which this user is collaborator # or # compeitions is published and belongs to someone else + # or + # competitions in which this user is participant and status is approved qs = qs.filter( (Q(created_by=self.request.user)) | (Q(collaborators__in=[self.request.user])) | - (Q(published=True) & ~Q(created_by=self.request.user)) - ) - # or - # competitions in which this user is participant and status is approved - qs = qs.filter(participants__user=self.request.user, participants__status="approved") + (Q(published=True) & ~Q(created_by=self.request.user)) | + (Q(participants__user=self.request.user) & Q(participants__status="approved")) + ).distinct() else: # if user is not authenticated only filter published/public competitions qs = qs.filter(Q(published=True)) From 92049ed3081150836663ba042e124986c9ae5be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Pav=C3=A3o?= Date: Thu, 11 May 2023 16:34:54 +0200 Subject: [PATCH 21/23] Update competitions.py (typos) --- src/apps/api/views/competitions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/api/views/competitions.py b/src/apps/api/views/competitions.py index 0e74f7970..541869c81 100644 --- a/src/apps/api/views/competitions.py +++ b/src/apps/api/views/competitions.py @@ -75,11 +75,11 @@ def get_queryset(self): # or from competition detail page if (not mine) and (not participating_in): # User is logged in then filter - # compeitions which this user owns + # competitions which this user owns # or # competitions in which this user is collaborator # or - # compeitions is published and belongs to someone else + # competitions is published and belongs to someone else # or # competitions in which this user is participant and status is approved qs = qs.filter( From 1c318d6871a031f89b127cdaf15721fc72dbd942 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Thu, 11 May 2023 19:41:16 +0500 Subject: [PATCH 22/23] queue name changed to vhost --- src/apps/competitions/unpackers/base_unpacker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apps/competitions/unpackers/base_unpacker.py b/src/apps/competitions/unpackers/base_unpacker.py index 2b1ac3a06..281069ca1 100644 --- a/src/apps/competitions/unpackers/base_unpacker.py +++ b/src/apps/competitions/unpackers/base_unpacker.py @@ -201,10 +201,10 @@ def _unpack_image(self): def _unpack_queue(self): # Get Queue by vhost/uuid. If instance not returned, or we don't have access don't set it! - queue_name = self.competition_yaml.get('queue') - if queue_name: + vhost = self.competition_yaml.get('queue') + if vhost: try: - queue = Queue.objects.get(name=queue_name) + queue = Queue.objects.get(vhost=vhost) if not queue.is_public: all_queue_organizer_names = queue.organizers.all().values_list('username', flat=True) if queue.owner != self.creator and self.creator.username not in all_queue_organizer_names: From a649e9800c9e90d415bb7d6a6d5f44fc53089de6 Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Thu, 11 May 2023 19:47:14 +0500 Subject: [PATCH 23/23] console log removed --- src/static/riot/competitions/detail/_header.tag | 1 - 1 file changed, 1 deletion(-) diff --git a/src/static/riot/competitions/detail/_header.tag b/src/static/riot/competitions/detail/_header.tag index 69256387d..55950fa64 100644 --- a/src/static/riot/competitions/detail/_header.tag +++ b/src/static/riot/competitions/detail/_header.tag @@ -190,7 +190,6 @@ self.update_files = (e) => { CODALAB.api.get_competition_files(self.competition.id) .done(data => { - console.log(data) self.files = data self.tr_show = false self.update()