def post(self, request, cid):
try:
if self.contest.status != 0:
raise ValueError("Contest is not running.")
lang = request.POST.get('lang', '')
if lang not in self.contest.supported_language_list:
raise ValueError("Invalid language.")
try:
problem = self.contest.contestproblem_set.get(identifier=request.POST.get('problem', '')).problem_id
except ContestProblem.DoesNotExist:
raise ValueError("Invalid problem.")
submission = create_submission(problem, self.user, request.POST.get('code', ''), lang,
contest=self.contest, ip=get_ip(request))
contest_participant, _ = self.contest.contestparticipant_set.get_or_create(user=self.user)
if contest_participant.is_disabled:
raise ValueError("You have quitted the contest.")
judge_submission_on_contest(submission)
return JsonResponse({"url": reverse('contest:submission_api',
kwargs={'cid': self.contest.id, 'sid': submission.id})})
except Exception as e:
return HttpResponseBadRequest(str(e).encode())
评论列表
文章目录