From 2d528a4efde132b066d7f98ef53e038ecef97b9d Mon Sep 17 00:00:00 2001 From: Yash Dusing Date: Sun, 24 Mar 2019 20:00:56 +0530 Subject: [PATCH 01/10] Added re-run functionality --- apps/jobs/urls.py | 3 + apps/jobs/views.py | 57 +++++++++++++++++++ frontend/src/js/controllers/challengeCtrl.js | 26 ++++++++- .../my-challenge-all-submission.html | 3 + 4 files changed, 88 insertions(+), 1 deletion(-) diff --git a/apps/jobs/urls.py b/apps/jobs/urls.py index a4a074846b..226a98e237 100644 --- a/apps/jobs/urls.py +++ b/apps/jobs/urls.py @@ -9,6 +9,9 @@ url(r'^challenge/(?P[0-9]+)/' r'challenge_phase/(?P[0-9]+)/submission/$', views.challenge_submission, name='challenge_submission'), + url(r'^challenge/(?P[0-9]+)/' + r'challenge_phase/(?P[0-9]+)/re_run_submission/(?P[0-9]+)$', + views.re_run_submission, name='re_run_submission'), url(r'^(?P[0-9]+)/' r'remaining_submissions/$', views.get_remaining_submissions, diff --git a/apps/jobs/views.py b/apps/jobs/views.py index 310946d570..3e53e2031a 100644 --- a/apps/jobs/views.py +++ b/apps/jobs/views.py @@ -702,3 +702,60 @@ def update_submission(request, challenge_pk): submission.save() response_data = {'success': 'Submission result has been successfully updated'} return Response(response_data, status=status.HTTP_200_OK) + + +@api_view(['POST', ]) +@throttle_classes([UserRateThrottle, ]) +@permission_classes((permissions.IsAuthenticated, HasVerifiedEmail)) +@authentication_classes((ExpiringTokenAuthentication,)) +def re_run_submission(request, challenge_id, challenge_phase_id, submission_number): + """ + API endpoint to re-run a submission. + Only challenge host has access to this endpoint. + """ + # check if the challenge exists or not + try: + challenge = Challenge.objects.get(pk=challenge_id) + except Challenge.DoesNotExist: + response_data = {'error': 'Challenge does not exist'} + return Response(response_data, status=status.HTTP_400_BAD_REQUEST) + + # check if the challenge phase exists or not + try: + challenge_phase = ChallengePhase.objects.get( + pk=challenge_phase_id, challenge=challenge) + except ChallengePhase.DoesNotExist: + response_data = {'error': 'Challenge Phase does not exist'} + return Response(response_data, status=status.HTTP_400_BAD_REQUEST) + + try: + submission = Submission.objects.get(submission_number=submission_number) + logger.info('Submission found with challenge ID {}, submission number {}' + .format(challenge_id, submission_number)) + except Submission.DoesNotExist: + response_data = {'error': 'Submission with submission number {} does not exist'.format(submission_number)} + return Response(response_data, status=status.HTTP_404_NOT_FOUND) + + if not is_user_a_host_of_challenge(request.user, challenge_id): + response_data = { + "error": "You are not allowed to re-run the challenge submission" + } + return Response(response_data, status=status.HTTP_403_FORBIDDEN) + + if not challenge.is_active: + response_data = {'error': 'Challenge is not active'} + return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE) + + # check if challenge phase is active + if not challenge_phase.is_active: + response_data = { + 'error': 'Sorry, cannot accept submissions since challenge phase is not active'} + return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE) + try: + publish_submission_message(challenge_id, challenge_phase_id, submission.id) + response_data = {'success': 'Submission result has been successfully updated'} + return Response(response_data, status=status.HTTP_200_OK) + except Exception as e: + logger.info('Error occured while sending to queue: {}'.format(str(e))) + response_data = {'error': 'Error occured while sending to queue'} + return Response(response_data, status=status.HTTP_400_BAD_REQUEST) diff --git a/frontend/src/js/controllers/challengeCtrl.js b/frontend/src/js/controllers/challengeCtrl.js index dac42c0320..f03b5d47d8 100644 --- a/frontend/src/js/controllers/challengeCtrl.js +++ b/frontend/src/js/controllers/challengeCtrl.js @@ -862,6 +862,30 @@ utilities.sendRequest(parameters); }; + + vm.rerunSubmission = function(submission_number) { + parameters.url = 'jobs/challenge/' + vm.challengeId +'/challenge_phase/' + vm.phaseId + '/re_run_submission/' + submission_number; + parameters.method = 'POST'; + var formData = new FormData(); + parameters.data = formData; + + parameters.token = userKey; + parameters.callback = { + onSuccess: function() { + $rootScope.notify("success", "Your submission has been re-run succesfully!"); + vm.stopLoader(); + }, + onError: function(response) { + var status = response.status; + var error = response.data; + $rootScope.notify("error", error); + vm.stopLoader(); + } + }; + vm.startLoader("Loading Submissions"); + utilities.sendRequest(parameters); + }; + vm.refreshLeaderboard = function() { vm.startLoader("Loading Leaderboard Items"); vm.leaderboard = {}; @@ -1372,7 +1396,7 @@ }; parameters.callback = { - onSuccess: function(response) { + onSuccess: function(response) {vm.challengePhaseId = vm.page.challenge_phase.id; var status = response.status; if (status === 200) { $mdDialog.hide(); diff --git a/frontend/src/views/web/challenge/my-challenge-all-submission.html b/frontend/src/views/web/challenge/my-challenge-all-submission.html index 03135bf832..a9e015d7dc 100644 --- a/frontend/src/views/web/challenge/my-challenge-all-submission.html +++ b/frontend/src/views/web/challenge/my-challenge-all-submission.html @@ -58,6 +58,7 @@ Stderr File Result File Metadata File + Re-run submissions @@ -92,6 +93,8 @@ N/A + + From 88994a0d37aabb8131b41c0e1853d166e6c8e72d Mon Sep 17 00:00:00 2001 From: Yash Dusing Date: Sun, 24 Mar 2019 20:14:03 +0530 Subject: [PATCH 02/10] Update challengeCtrl.js --- frontend/src/js/controllers/challengeCtrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/js/controllers/challengeCtrl.js b/frontend/src/js/controllers/challengeCtrl.js index 6acfd5e8c3..d41d564a9d 100644 --- a/frontend/src/js/controllers/challengeCtrl.js +++ b/frontend/src/js/controllers/challengeCtrl.js @@ -1396,7 +1396,7 @@ }; parameters.callback = { - onSuccess: function(response) {vm.challengePhaseId = vm.page.challenge_phase.id; + onSuccess: function(response) { var status = response.status; if (status === 200) { $mdDialog.hide(); From 554b24739de4a3b35cf6ef2f0bcf72f5a54b1cf0 Mon Sep 17 00:00:00 2001 From: Yash Dusing Date: Thu, 16 May 2019 23:53:41 +0530 Subject: [PATCH 03/10] Removed challenge_id and challenge_phase_id from url --- apps/jobs/urls.py | 3 +- apps/jobs/views.py | 31 ++++++++++---------- frontend/src/js/controllers/challengeCtrl.js | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/apps/jobs/urls.py b/apps/jobs/urls.py index 20a62061ab..173f270029 100644 --- a/apps/jobs/urls.py +++ b/apps/jobs/urls.py @@ -21,8 +21,7 @@ name="get_remaining_submissions", ), url( - r'^challenge/(?P[0-9]+)/' - r'challenge_phase/(?P[0-9]+)/re_run_submission/(?P[0-9]+)$', + r'^re_run_submission/(?P[0-9]+)$', views.re_run_submission, name='re_run_submission' ), url( diff --git a/apps/jobs/views.py b/apps/jobs/views.py index 992ae07458..71f314b1c8 100644 --- a/apps/jobs/views.py +++ b/apps/jobs/views.py @@ -937,33 +937,34 @@ def update_submission(request, challenge_pk): @throttle_classes([UserRateThrottle, ]) @permission_classes((permissions.IsAuthenticated, HasVerifiedEmail)) @authentication_classes((ExpiringTokenAuthentication,)) -def re_run_submission(request, challenge_id, challenge_phase_id, submission_number): +def re_run_submission(request, submission_number): """ API endpoint to re-run a submission. Only challenge host has access to this endpoint. """ - # check if the challenge exists or not try: - challenge = Challenge.objects.get(pk=challenge_id) - except Challenge.DoesNotExist: - response_data = {'error': 'Challenge does not exist'} - return Response(response_data, status=status.HTTP_400_BAD_REQUEST) + submission = Submission.objects.get(submission_number=submission_number) + logger.info('Submission found with submission number {}' + .format(submission_number)) + except Submission.DoesNotExist: + response_data = {'error': 'Submission with submission number {} does not exist'.format(submission_number)} + return Response(response_data, status=status.HTTP_404_NOT_FOUND) # check if the challenge phase exists or not try: - challenge_phase = ChallengePhase.objects.get( - pk=challenge_phase_id, challenge=challenge) - except ChallengePhase.DoesNotExist: + challenge_phase = submission.challenge_phase + challenge_phase_id = challenge_phase.id + except Exception as e: response_data = {'error': 'Challenge Phase does not exist'} return Response(response_data, status=status.HTTP_400_BAD_REQUEST) + # check if the challenge exists or not try: - submission = Submission.objects.get(submission_number=submission_number) - logger.info('Submission found with challenge ID {}, submission number {}' - .format(challenge_id, submission_number)) - except Submission.DoesNotExist: - response_data = {'error': 'Submission with submission number {} does not exist'.format(submission_number)} - return Response(response_data, status=status.HTTP_404_NOT_FOUND) + challenge = challenge_phase.challenge + challenge_id = challenge.id + except Exception as e: + response_data = {'error': 'Challenge does not exist'} + return Response(response_data, status=status.HTTP_400_BAD_REQUEST) if not is_user_a_host_of_challenge(request.user, challenge_id): response_data = { diff --git a/frontend/src/js/controllers/challengeCtrl.js b/frontend/src/js/controllers/challengeCtrl.js index c442eff3a7..235be4dd43 100644 --- a/frontend/src/js/controllers/challengeCtrl.js +++ b/frontend/src/js/controllers/challengeCtrl.js @@ -883,7 +883,7 @@ }; vm.rerunSubmission = function(submission_number) { - parameters.url = 'jobs/challenge/' + vm.challengeId +'/challenge_phase/' + vm.phaseId + '/re_run_submission/' + submission_number; + parameters.url = 'jobs/re_run_submission/' + submission_number; parameters.method = 'POST'; var formData = new FormData(); parameters.data = formData; From 53943776c7e635935e9a0f54613e26a8064125e1 Mon Sep 17 00:00:00 2001 From: Sanji515 Date: Sat, 25 May 2019 03:40:55 +0000 Subject: [PATCH 04/10] Fix #2209: Add a feature to re-reun a submission by challenge host using UI --- apps/jobs/urls.py | 2 +- apps/jobs/views.py | 18 ++++++++++----- frontend/src/css/modules/challenge.scss | 22 +++++++++++++++++++ frontend/src/js/controllers/challengeCtrl.js | 19 +++++++++++----- .../my-challenge-all-submission.html | 5 ++--- 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/apps/jobs/urls.py b/apps/jobs/urls.py index 173f270029..aeda10e308 100644 --- a/apps/jobs/urls.py +++ b/apps/jobs/urls.py @@ -21,7 +21,7 @@ name="get_remaining_submissions", ), url( - r'^re_run_submission/(?P[0-9]+)$', + r'^re_run_submission/(?P[0-9]+)$', views.re_run_submission, name='re_run_submission' ), url( diff --git a/apps/jobs/views.py b/apps/jobs/views.py index 71f314b1c8..72a27fc12f 100644 --- a/apps/jobs/views.py +++ b/apps/jobs/views.py @@ -2,6 +2,7 @@ import datetime import json import logging +import time from rest_framework import permissions, status from rest_framework.decorators import ( @@ -937,17 +938,17 @@ def update_submission(request, challenge_pk): @throttle_classes([UserRateThrottle, ]) @permission_classes((permissions.IsAuthenticated, HasVerifiedEmail)) @authentication_classes((ExpiringTokenAuthentication,)) -def re_run_submission(request, submission_number): +def re_run_submission(request, submission_id): """ API endpoint to re-run a submission. Only challenge host has access to this endpoint. """ try: - submission = Submission.objects.get(submission_number=submission_number) + submission = Submission.objects.get(id=submission_id) logger.info('Submission found with submission number {}' - .format(submission_number)) + .format(submission_id)) except Submission.DoesNotExist: - response_data = {'error': 'Submission with submission number {} does not exist'.format(submission_number)} + response_data = {'error': 'Submission with submission number {} does not exist'.format(submission_id)} return Response(response_data, status=status.HTTP_404_NOT_FOUND) # check if the challenge phase exists or not @@ -983,7 +984,14 @@ def re_run_submission(request, submission_number): return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE) try: publish_submission_message(challenge_id, challenge_phase_id, submission.id) - response_data = {'success': 'Submission result has been successfully updated'} + time.sleep(1) + submission = Submission.objects.get(id=submission_id) + response_data = { + 'submission_status': submission.status, + 'submission_execution_time': submission.execution_time, + 'submission_number': submission.submission_number, + 'success': 'Submission result has been successfully updated' + } return Response(response_data, status=status.HTTP_200_OK) except Exception as e: logger.info('Error occured while sending to queue: {}'.format(str(e))) diff --git a/frontend/src/css/modules/challenge.scss b/frontend/src/css/modules/challenge.scss index 7e608191fe..b9ecfdd840 100644 --- a/frontend/src/css/modules/challenge.scss +++ b/frontend/src/css/modules/challenge.scss @@ -186,3 +186,25 @@ md-select.md-default-theme .md-select-value span:first-child:after, md-select .m #option-text-color { color: #252833; } + +@-webkit-keyframes spin { + from { -webkit-transform: rotate(0deg); } + to { -webkit-transform: rotate(360deg); } +} + +@keyframes spin { + from {transform:rotate(0deg);} + to {transform:rotate(360deg);} +} + + +.spin { + -webkit-animation: spin 1s linear infinite; + animation: spin 1s linear infinite; + -webkit-animation-fill-mode: both; + animation-fill-mode: both; +} + +.progress-indicator { + width: 14px; +} diff --git a/frontend/src/js/controllers/challengeCtrl.js b/frontend/src/js/controllers/challengeCtrl.js index b1869dd887..b762c60ba4 100644 --- a/frontend/src/js/controllers/challengeCtrl.js +++ b/frontend/src/js/controllers/challengeCtrl.js @@ -890,26 +890,33 @@ utilities.sendRequest(parameters); }; - vm.rerunSubmission = function(submission_number) { - parameters.url = 'jobs/re_run_submission/' + submission_number; + vm.rerunSubmission = function(submissionObject) { + submissionObject.classList = ['spin', 'progress-indicator']; + parameters.url = 'jobs/re_run_submission/' + submissionObject.id; parameters.method = 'POST'; var formData = new FormData(); parameters.data = formData; parameters.token = userKey; parameters.callback = { - onSuccess: function() { + onSuccess: function(response) { $rootScope.notify("success", "Your submission has been re-run succesfully!"); - vm.stopLoader(); + submissionObject.status = response.data.submission_status; + submissionObject.execution_time = response.data.submission_execution_time; + submissionObject.submission_number = response.data.submission_number; + submissionObject.classList = ['']; + $scope.reRunSubmission = 'false'; + // vm.stopLoader(); }, onError: function(response) { var status = response.status; var error = response.data; $rootScope.notify("error", error); - vm.stopLoader(); + submissionObject.classList = ['']; + // vm.stopLoader(); } }; - vm.startLoader("Loading Submissions"); + // vm.startLoader("Loading Submissions"); utilities.sendRequest(parameters); }; diff --git a/frontend/src/views/web/challenge/my-challenge-all-submission.html b/frontend/src/views/web/challenge/my-challenge-all-submission.html index 1980fa9e18..dfae588a40 100644 --- a/frontend/src/views/web/challenge/my-challenge-all-submission.html +++ b/frontend/src/views/web/challenge/my-challenge-all-submission.html @@ -65,7 +65,7 @@ Stderr File Result File Metadata File - Re-run submissions + Re-run Submissions @@ -100,8 +100,7 @@ N/A - - +
From 340f02c7bd5dfe3aaec3e310bbde5716a1b00dcf Mon Sep 17 00:00:00 2001 From: Sanjeev Singh Date: Mon, 3 Jun 2019 16:05:31 +0530 Subject: [PATCH 05/10] Update challengeCtrl.js --- frontend/src/js/controllers/challengeCtrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/js/controllers/challengeCtrl.js b/frontend/src/js/controllers/challengeCtrl.js index b762c60ba4..e59f2dcaa0 100644 --- a/frontend/src/js/controllers/challengeCtrl.js +++ b/frontend/src/js/controllers/challengeCtrl.js @@ -890,7 +890,7 @@ utilities.sendRequest(parameters); }; - vm.rerunSubmission = function(submissionObject) { + vm.reRunSubmission = function(submissionObject) { submissionObject.classList = ['spin', 'progress-indicator']; parameters.url = 'jobs/re_run_submission/' + submissionObject.id; parameters.method = 'POST'; From c4daef9aa2142a9dfeca05da9022570f4ed0ee5b Mon Sep 17 00:00:00 2001 From: Sanji515 Date: Mon, 3 Jun 2019 16:42:53 +0530 Subject: [PATCH 06/10] remove unused variable --- frontend/src/js/controllers/challengeCtrl.js | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/js/controllers/challengeCtrl.js b/frontend/src/js/controllers/challengeCtrl.js index 0c462557dc..f7d123f97b 100644 --- a/frontend/src/js/controllers/challengeCtrl.js +++ b/frontend/src/js/controllers/challengeCtrl.js @@ -948,7 +948,6 @@ submissionObject.execution_time = response.data.submission_execution_time; submissionObject.submission_number = response.data.submission_number; submissionObject.classList = ['']; - $scope.reRunSubmission = 'false'; }, onError: function(response) { var status = response.status; From 51517a40706761fbc28416cfec8143f0e20246a2 Mon Sep 17 00:00:00 2001 From: Sanji515 Date: Tue, 16 Jul 2019 19:30:47 +0530 Subject: [PATCH 07/10] removed the updating by making submission query again --- apps/jobs/urls.py | 2 +- apps/jobs/views.py | 48 ++++++-------------- frontend/src/js/controllers/challengeCtrl.js | 8 +--- 3 files changed, 15 insertions(+), 43 deletions(-) diff --git a/apps/jobs/urls.py b/apps/jobs/urls.py index aeda10e308..9e76bf9e74 100644 --- a/apps/jobs/urls.py +++ b/apps/jobs/urls.py @@ -21,7 +21,7 @@ name="get_remaining_submissions", ), url( - r'^re_run_submission/(?P[0-9]+)$', + r'^submissions/(?P[0-9]+)/re-run/$', views.re_run_submission, name='re_run_submission' ), url( diff --git a/apps/jobs/views.py b/apps/jobs/views.py index 72a27fc12f..559f5c5671 100644 --- a/apps/jobs/views.py +++ b/apps/jobs/views.py @@ -938,65 +938,43 @@ def update_submission(request, challenge_pk): @throttle_classes([UserRateThrottle, ]) @permission_classes((permissions.IsAuthenticated, HasVerifiedEmail)) @authentication_classes((ExpiringTokenAuthentication,)) -def re_run_submission(request, submission_id): +def re_run_submission(request, submission_pk): """ API endpoint to re-run a submission. Only challenge host has access to this endpoint. """ try: - submission = Submission.objects.get(id=submission_id) + submission = Submission.objects.get(pk=submission_pk) logger.info('Submission found with submission number {}' - .format(submission_id)) + .format(submission_pk)) except Submission.DoesNotExist: - response_data = {'error': 'Submission with submission number {} does not exist'.format(submission_id)} + response_data = {'error': 'Submission {} does not exist'.format(submission_pk)} return Response(response_data, status=status.HTTP_404_NOT_FOUND) # check if the challenge phase exists or not try: challenge_phase = submission.challenge_phase - challenge_phase_id = challenge_phase.id except Exception as e: response_data = {'error': 'Challenge Phase does not exist'} return Response(response_data, status=status.HTTP_400_BAD_REQUEST) - # check if the challenge exists or not - try: - challenge = challenge_phase.challenge - challenge_id = challenge.id - except Exception as e: - response_data = {'error': 'Challenge does not exist'} - return Response(response_data, status=status.HTTP_400_BAD_REQUEST) + challenge = challenge_phase.challenge - if not is_user_a_host_of_challenge(request.user, challenge_id): + if not is_user_a_host_of_challenge(request.user, challenge.id): response_data = { - "error": "You are not allowed to re-run the challenge submission" + "error": "Only challenge hosts are allowed to re-run a submission" } return Response(response_data, status=status.HTTP_403_FORBIDDEN) if not challenge.is_active: - response_data = {'error': 'Challenge is not active'} + response_data = {'error': 'Challenge {} is not active'.format(challenge.title)} return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE) - # check if challenge phase is active - if not challenge_phase.is_active: - response_data = { - 'error': 'Sorry, cannot accept submissions since challenge phase is not active'} - return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE) - try: - publish_submission_message(challenge_id, challenge_phase_id, submission.id) - time.sleep(1) - submission = Submission.objects.get(id=submission_id) - response_data = { - 'submission_status': submission.status, - 'submission_execution_time': submission.execution_time, - 'submission_number': submission.submission_number, - 'success': 'Submission result has been successfully updated' - } - return Response(response_data, status=status.HTTP_200_OK) - except Exception as e: - logger.info('Error occured while sending to queue: {}'.format(str(e))) - response_data = {'error': 'Error occured while sending to queue'} - return Response(response_data, status=status.HTTP_400_BAD_REQUEST) + publish_submission_message(challenge.id, challenge_phase.id, submission.id) + response_data = { + 'success': 'Submission is successfully submitted for re-running' + } + return Response(response_data, status=status.HTTP_200_OK) @api_view(["GET"]) diff --git a/frontend/src/js/controllers/challengeCtrl.js b/frontend/src/js/controllers/challengeCtrl.js index f7d123f97b..50e09e51c2 100644 --- a/frontend/src/js/controllers/challengeCtrl.js +++ b/frontend/src/js/controllers/challengeCtrl.js @@ -935,18 +935,12 @@ vm.reRunSubmission = function(submissionObject) { submissionObject.classList = ['spin', 'progress-indicator']; - parameters.url = 'jobs/re_run_submission/' + submissionObject.id; + parameters.url = 'jobs/submissions/' + submissionObject.id + '/re-run/'; parameters.method = 'POST'; - var formData = new FormData(); - parameters.data = formData; - parameters.token = userKey; parameters.callback = { onSuccess: function(response) { $rootScope.notify("success", "Your submission has been re-run succesfully!"); - submissionObject.status = response.data.submission_status; - submissionObject.execution_time = response.data.submission_execution_time; - submissionObject.submission_number = response.data.submission_number; submissionObject.classList = ['']; }, onError: function(response) { From 47b623e15d4d2a321863f31ab0d63c392d6d1450 Mon Sep 17 00:00:00 2001 From: Sanji515 Date: Tue, 16 Jul 2019 20:35:05 +0530 Subject: [PATCH 08/10] removed the unused lines --- apps/jobs/views.py | 1 - frontend/src/js/controllers/challengeCtrl.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/jobs/views.py b/apps/jobs/views.py index f79543d144..9c1d429872 100644 --- a/apps/jobs/views.py +++ b/apps/jobs/views.py @@ -2,7 +2,6 @@ import datetime import json import logging -import time from rest_framework import permissions, status from rest_framework.decorators import ( diff --git a/frontend/src/js/controllers/challengeCtrl.js b/frontend/src/js/controllers/challengeCtrl.js index b734fd8837..aaaace21be 100644 --- a/frontend/src/js/controllers/challengeCtrl.js +++ b/frontend/src/js/controllers/challengeCtrl.js @@ -948,11 +948,10 @@ parameters.token = userKey; parameters.callback = { onSuccess: function(response) { - $rootScope.notify("success", "Your submission has been re-run succesfully!"); + $rootScope.notify("success", response.data.success); submissionObject.classList = ['']; }, onError: function(response) { - var status = response.status; var error = response.data; $rootScope.notify("error", error); submissionObject.classList = ['']; From 99db12a034bc67b08b0f7838a17c5982ed6321b8 Mon Sep 17 00:00:00 2001 From: Sanji515 Date: Tue, 16 Jul 2019 23:22:48 +0530 Subject: [PATCH 09/10] removed the try catch of challenge phase in re-run submission API --- apps/jobs/views.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/apps/jobs/views.py b/apps/jobs/views.py index 9c1d429872..f6af5df004 100644 --- a/apps/jobs/views.py +++ b/apps/jobs/views.py @@ -975,13 +975,8 @@ def re_run_submission(request, submission_pk): response_data = {'error': 'Submission {} does not exist'.format(submission_pk)} return Response(response_data, status=status.HTTP_404_NOT_FOUND) - # check if the challenge phase exists or not - try: - challenge_phase = submission.challenge_phase - except Exception as e: - response_data = {'error': 'Challenge Phase does not exist'} - return Response(response_data, status=status.HTTP_400_BAD_REQUEST) - + # get the challenge and challenge phase object + challenge_phase = submission.challenge_phase challenge = challenge_phase.challenge if not is_user_a_host_of_challenge(request.user, challenge.id): From 2ce5691a9b004b238b5074ef17ee40a0537a8b53 Mon Sep 17 00:00:00 2001 From: Sanji515 Date: Tue, 16 Jul 2019 23:44:53 +0530 Subject: [PATCH 10/10] removed the logger statement and used pk instead of id --- apps/jobs/views.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/jobs/views.py b/apps/jobs/views.py index f6af5df004..c9241fc6c2 100644 --- a/apps/jobs/views.py +++ b/apps/jobs/views.py @@ -969,8 +969,6 @@ def re_run_submission(request, submission_pk): """ try: submission = Submission.objects.get(pk=submission_pk) - logger.info('Submission found with submission number {}' - .format(submission_pk)) except Submission.DoesNotExist: response_data = {'error': 'Submission {} does not exist'.format(submission_pk)} return Response(response_data, status=status.HTTP_404_NOT_FOUND) @@ -979,7 +977,7 @@ def re_run_submission(request, submission_pk): challenge_phase = submission.challenge_phase challenge = challenge_phase.challenge - if not is_user_a_host_of_challenge(request.user, challenge.id): + if not is_user_a_host_of_challenge(request.user, challenge.pk): response_data = { "error": "Only challenge hosts are allowed to re-run a submission" } @@ -989,7 +987,7 @@ def re_run_submission(request, submission_pk): response_data = {'error': 'Challenge {} is not active'.format(challenge.title)} return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE) - publish_submission_message(challenge.id, challenge_phase.id, submission.id) + publish_submission_message(challenge.pk, challenge_phase.pk, submission.pk) response_data = { 'success': 'Submission is successfully submitted for re-running' }