def problem_id(request, pid): if request.method == 'POST': form = SubmitForm(request.POST, request.FILES) if form.is_valid(): code = form.save(commit=False) #variable name need to change code.user_id = request.user problem = Problem.objects.get(id=pid) problem.no_of_submissions += 1 code.problem_id = problem code.save() #save the model before judging with default values #need to redirect to current submission page (not implemented) if code.language == 'Python': #Time limit for different language time = problem.time_limit[1] else: time = problem.time_limit[0] code.verdict, code.time = judging(problem.input_file.path, problem.output_file.path, code.code.path, code.language, time, problem.memory_limit) if code.verdict == 1: problem.no_of_accepted += 1 #final save after judging code.save() problem.save() return redirect('submit') else: form = SubmitForm() problem = Problem.objects.get(id=pid) request.session['pid'] = pid context = {'problem': problem, 'form': form} return render(request, 'problem.html', context)
def cont_problem(request, pid, cid): if request.method == 'POST': contest = Contest.objects.get(id=cid) if timezone.now() > contest.end_time: return redirect('contest_end', contest.id) # show contest end message form = SubmitForm(request.POST, request.FILES) if form.is_valid(): code = form.save(commit=False) # variable name need to change code.user_id = request.user # Current Problem problem = Problem.objects.get(id=pid) problem.no_of_submissions += 1 # current user current_user = CustomUser.objects.get(id=request.user.id) current_user.problem_tried += 1 code.problem_id = problem code.save() # save the model before judging with default values if code.language == 'Python': # Time limit for different language time = problem.time_limit[1] else: time = problem.time_limit[0] code.verdict, code.time = judging(problem.input_file.path, problem.output_file.path, code.code.path, code.language, time, problem.memory_limit) if code.verdict == 1: current_user.problem_solved += 1 problem.no_of_accepted += 1 code.save() problem.save() current_user.save() return redirect( 'single_status', pid) # after submit redirect to user_submission page else: form = SubmitForm() problem = Problem.objects.get(id=pid) contest = Contest.objects.get(id=cid) request.session['pid'] = pid context = {'problem': problem, 'contest': contest, 'form': form} return render(request, 'contest/cont_problem.html', context)
def cont_problem(request, cid, pid): if request.method == 'POST': contest = get_object_or_404(Contest,id=cid) if timezone.now() > contest.end_time : return redirect('contest_end' , contest.id ) # show contest end message form = SubmitForm(request.POST, request.FILES) if form.is_valid(): code = form.save(commit=False) # variable name need to change code.user_id = request.user # Current Problem problem = Problem.objects.get(id=pid) problem.contest_time_submissions+=1 # current user current_user = CustomUser.objects.get(id=request.user.id) current_user.problem_tried += 1 code.problem_id = problem code.save() # save the model before judging with default values if code.language == 'Python': # Time limit for different language time = problem.time_limit[1] else: time = problem.time_limit[0] code.verdict, code.time = judging(problem.input_file.path, problem.output_file.path, code.code.path, code.language, time, problem.memory_limit) if code.verdict == 1: current_user.problem_solved += 1 problem.contest_time_AC+=1 #ContestParticipant,problemtry models update/create code.save() problem.save() current_user.save() #print(current_user.id , problem.id) obj,created =ContestParticipant.objects.get_or_create(contestant=request.user ,contestid=contest,defaults={'penalty_time':timezone.now(),'penalty':0,'solved':0}) obj2,created =ProblemTry.objects.get_or_create(user=request.user , part=obj, prob=problem,defaults={'status':False}) #print(obj.id) #print("Hello") if(code.verdict==1 and obj2.status==False): obj2.status=True obj.solved+=1 if(obj.penalty > 0): obj.penalty_time=(timezone.now()+timezone.timedelta(0,1200*obj.penalty)-contest.start_time) else: obj.penalty+=1 obj.save() obj2.save() return redirect('single_status' , pid ) # after submit redirect to user_submission page else: form = SubmitForm() problem = Problem.objects.get(id=pid) contest = Contest.objects.get(id=cid) request.session['pid'] = pid context = {'problem': problem, 'contest': contest, 'form': form} return render(request, 'contest/cont_problem.html', context)