def get_problem_info(req, oj, problem_id, index): problem_id = int(problem_id) data = { 'pid': 0, 'title': '', 'index': index, 'new': 0, } try: pinfo = Problem.objects.get(oj=oj, problem_id=problem_id) except: if oj != 'neau': c = Connect() title = c.test_problem(oj, problem_id).decode('UTF-8') if len(title): p = Problem(oj=oj, problem_id=problem_id, judge_type=1) p.save() c = Connect() c.download_problem(oj, problem_id, p.id) data['pid'] = p.id data['title'] = title data['new'] = 1 else: data = { 'pid': pinfo.id, 'title': pinfo.title, 'index': index, 'new': 0 } return JsonResponse(data)
def submit(req): if req.method == 'GET': form = SubmitForm() return render_to_response('problem_submit.html', { 'path': req.path, 'form': form }, context_instance=RequestContext(req)) if req.method == 'POST': form = SubmitForm(req.POST) form.set_user(req.user) form.set_contest(req.POST.get('contest', -1)) if form.is_valid(): new_submit = form.save() con = Connect() receive = con.judge_code(new_submit.id) logger.info(receive) logger.info(u"User: "******"s Submited Problem: <" + new_submit.problem.oj + str( new_submit.problem.problem_id) + u"> Title: " + new_submit.problem.title) if form.contest_id >= 0: return HttpResponseRedirect("/contest/c/" + str(form.contest_id)) # + "?status=1" return HttpResponseRedirect("/status") else: return render_to_response("problem_submit.html", { 'path': req.path, 'form': form, }, context_instance=RequestContext(req))
def rejudge(req, sid): if req.method == 'GET': con = Connect() receive = con.judge_code(sid) logger.info(receive) logger.info(u"User: "******" Rejudge Solve ID: <" + sid + u">") return HttpResponseRedirect("/status") raise Http404()
def clean_cid(self): cid = self.cleaned_data.get("cid") c = Connect() number = int(c.test_contest(cid)) if number == 0: raise forms.ValidationError("No Such Contest") self.number = number return cid
def test_account(oj, username, password): try: na = OJ_account.objects.get(oj=oj, username=username, password=password) except: c = Connect() return True if c.test_user(oj, username, password) == '1' else False else: return False
def get_problem(req, pid): data = { 'wait': 1 } try: p = Problem.objects.get(id=pid) except: raise Http404() if p.defunct <= 0: c = Connect() c.download_problem(p.oj, p.problem_id, p.id) else: data = { 'wait': 0 } return JsonResponse(data)
def problem_main(req, pid): if req.method == 'GET': try: p = Problem.objects.get(id=pid) except: return render_to_response('problem_error.html') wait = True if p.judge_type == 1: if p.defunct <= 0: c = Connect() c.download_problem(p.oj, p.problem_id, p.id) else: wait = False p.defunct = p.defunct - 1 p.save() return render_to_response('problem_main.html', { 'path': req.path, 'p': p, 'wait': wait }, context_instance=RequestContext(req))
def test(req): p = None if req.method == 'POST': wait = True form = testform(req.POST) if form.is_valid(): ind = form.cleaned_data['ind'] oj = form.cleaned_data['oj'] try: p = Problem.objects.get(oj=oj, problem_id=ind) except: p = Problem(oj=oj, problem_id=ind, judge_type=1) p.save() c = Connect() c.download_problem(oj, ind, p.id) else: if p.defunct <= 0: c = Connect() c.download_problem(oj, ind, p.id) else: wait = False return render_to_response('problem_test.html', { 'form': form, 'path': req.path, 'wait': wait, 'p': p, }, context_instance=RequestContext(req)) else: form = testform() return render_to_response('problem_test.html', { 'form': form, 'path': req.path, 'wait': True, 'p': p, }, context_instance=RequestContext(req))
def save(self, user): cid = self.cleaned_data.get("cid") from datetime import datetime from problem.models import Problem from contest.models import Contest, In_Problem try: contest = Contest.objects.get(clone=cid) flag = True except: contest = Contest( title="None", start_time=datetime.now(), end_time=datetime.now(), description="", private=0, impose=0, type=1, password="", creator=user, ) contest.save() flag = False if not flag: for i in range(self.number): p = Problem(oj="hdu_std", problem_id=i + 1001, judge_type=1, data_number=cid) p.save() new_problem = In_Problem( problem=p, problem_new_id=i, title="None", ) new_problem.save() contest.problem.add(new_problem) c = Connect() c.clone_contest(cid, contest.id)
def updata_user(user): c = Connect() c.update_user(str(user.info.id))