def rejudge(request): """Ajax method: Rejudge a single submission `id`""" user = User.getCurrent(request) id = request.POST["id"] submission = Submission.get(id) runCode(submission, user) return JsonResponse(submission.result, safe=False)
def judge_submission(request, *args, **kwargs): submission = Submission.get(kwargs.get('id')) user = User.getCurrent(request) version = int(request.POST["version"]) force = kwargs.get('force') == "force" if submission.version != version: return JsonResponse(f"CHANGES", safe=False) elif not submission.checkoutToJudge(user.id, force): return JsonResponse( f"CONFLICT:{User.get(submission.checkout).username}", safe=False) return HttpResponse(SubmissionCard(submission, user, force))
def viewDiff(request, *args, **kwargs): submission = Submission.get(kwargs.get('id')) user = User.getCurrent(request) problem = submission.problem answers = submission.readFilesForDisplay('out') diffTables = [] for i in range(len(problem.testData)): if i < problem.samples: caseType = "Sample" caseNo = i else: caseType = "Judge" caseNo = i - problem.samples diffTables.append( h.div( h. h3(f"{caseType} Case #{caseNo} (Expected Output | Contestant Output)", id=f"case{i}diff"), h.div( h.script( f"document.getElementById('case{i}result').innerHTML = 'Result: ' + verdict_name.{submission.results[i]}" ), id=f"case{i}result", ), generateDiffTable(problem.testData[i].output, answers[i]), )) pass return HttpResponse( div(cls="center", contents=[ h.link( rel="stylesheet", href= "/static/styles/style.css?642ab0bc-f075-4c4c-a2ba-00f55392dafc", type="text/css"), h.script(src="/static/lib/jquery/jquery.min.js"), h.script(src="/static/lib/jqueryui/jquery-ui.min.js"), h.script( src= "/static/scripts/script.js?75c1bf1e-10e8-4c8d-9730-0903f6540439" ), h2(f"Diffs for {submission.id}", cls="center"), h. em("Insertions are in <span style=color:darkgreen;background-color:palegreen>green</span>, deletions are in <span style=color:darkred;background-color:#F6B0B0>red</span>" ), h.div(contents=diffTables) ]))
def changeResult(request, *args, **kwargs): version = int(request.POST["version"]) id = request.POST["id"] sub = Submission.get(id) if not sub: return JsonResponse("Error: no such submission", safe=False) if sub.changeResult(request.POST["result"], request.POST["status"], version): sub.save() else: return JsonResponse( "The submission has been changed by another judge since you loaded it. Please reload the sumbission to " "modify it.", safe=False) return JsonResponse("ok", safe=False)
def download(request): id = request.POST["id"] submission = Submission.get(id) buf = io.BytesIO() with ZipFile(buf, 'w') as zip: sourceFile = f"source.{exts[submission.language]}" zip.writestr(sourceFile, submission.code) for index in range(submission.problem.tests): for fileType in ["in", "out", "answer", "error"]: filename = f"/db/submissions/{id}/{fileType}{index}.txt" output_dest_filename = f"{fileType}{index}.txt" if os.path.exists(filename): zip.write(filename, output_dest_filename) data = {"download.zip": base64.b64encode(buf.getvalue()).decode('ascii')} return JsonResponse(json.dumps(data), safe=False)
def contestant_submission(request, *args, **kwargs): return HttpResponse(SubmissionCard(Submission.get(kwargs.get('id'))))
def judge_submission_close(request): submission = Submission.get(request.POST["id"]) user = User.getCurrent(request) if submission.checkout == user.id: submission.checkout = None return JsonResponse('ok', safe=False)