diff --git a/oj/urls.py b/oj/urls.py index ffe526fb..c626656b 100644 --- a/oj/urls.py +++ b/oj/urls.py @@ -9,8 +9,9 @@ urlpatterns = [ url(r"^api/admin/", include("conf.urls.admin")), url(r"^api/", include("problem.urls.oj")), url(r"^api/admin/", include("problem.urls.admin")), - url(r"^api/admin/", include("contest.urls.admin")), url(r"^api/", include("contest.urls.oj")), + url(r"^api/admin/", include("contest.urls.admin")), url(r"^api/", include("submission.urls.oj")), + url(r"^api/admin/", include("submission.urls.admin")), url(r"^api/admin/", include("utils.urls")), ] diff --git a/submission/urls/admin.py b/submission/urls/admin.py index e69de29b..bf86022f 100644 --- a/submission/urls/admin.py +++ b/submission/urls/admin.py @@ -0,0 +1,7 @@ +from django.conf.urls import url + +from ..views.admin import SubmissionRejudgeAPI + +urlpatterns = [ + url(r"^submission/rejudge?$", SubmissionRejudgeAPI.as_view(), name="submission_rejudge_api"), +] diff --git a/submission/views/admin.py b/submission/views/admin.py index e69de29b..679360b6 100644 --- a/submission/views/admin.py +++ b/submission/views/admin.py @@ -0,0 +1,24 @@ +from account.decorators import super_admin_required +from judge.tasks import judge_task +# from judge.dispatcher import JudgeDispatcher +from utils.api import APIView +from ..models import Submission, JudgeStatus + + +class SubmissionRejudgeAPI(APIView): + @super_admin_required + def get(self, request): + id = request.GET.get("id") + if not id: + return self.error("Paramater error, id is required") + try: + submission = Submission.objects.select_related("problem").get(id=id, contest_id__isnull=True) + except Submission.DoesNotExist: + return self.error("Submission does not exists") + submission.result = JudgeStatus.PENDING + submission.info = {} + submission.statistic_info = {} + submission.save() + + judge_task.delay(submission.id, submission.problem.id) + return self.success() diff --git a/submission/views/oj.py b/submission/views/oj.py index 88a5c272..8514c13c 100644 --- a/submission/views/oj.py +++ b/submission/views/oj.py @@ -206,6 +206,6 @@ class SubmissionExistsAPI(APIView): def get(self, request): if not request.GET.get("problem_id"): return self.error("Parameter error, problem_id is required") - return self.success(request.user.is_authenticated and + return self.success(request.user.is_authenticated() and Submission.objects.filter(problem_id=request.GET["problem_id"], user_id=request.user.id).exists())