def submitscript(request): ip_address = request.META['REMOTE_ADDR'] user = authenticate(ip_address=ip_address) if user is not None and user.is_active: response = HttpResponse() if not 'problem' in request.POST or not 'compiler' in request.POST or not 'submission' in request.POST or not 'filename' in request.POST: response.write("Missing POST variables") return response try: problem = Problem.objects.get(letter=request.POST['problem']) except: response.write("ERROR: Invalid problem") return response try: compiler = Compiler.objects.get(id=request.POST['compiler']) except: response.write("ERROR: Invalid compiler") return response profile = user.get_profile() if not profile.is_judge: contest = Contest.objects.get() if contest.status != "RUNNING" and contest.status != "NOINFO": response.write("ERROR: Contest is not running.") return response if Submission.objects.filter(team=profile.team, problem=problem, result__judgement__exact="ACCEPTED").count(): response.write("ERROR: A submission for this problem has been accepted already.") return response submission = Submission() submission.status = "NEW" submission.team = profile.team submission.problem = problem submission.compiler = compiler submission.file_name = request.POST['filename'] file = File() file.content = request.POST['submission'] file.save() submission.file = file submission.save() response.write("Submission successful") return response else: return HttpResponseRedirect('/look/')
def submission(request, problem=None): profile = request.user.get_profile() contest = Contest.objects.get() if request.method == 'POST': form = SubmitForm(request.POST, request.FILES, request=request) if form.is_valid(): # TODO: Check whether extension is correct. submission = Submission() submission.status = "NEW" submission.team = profile.team submission.problem = form.cleaned_data['problem'] submission.compiler = form.cleaned_data['compiler'] submission.file_name = request.FILES['file'].name file = File() content = request.FILES['file'].read() try: file.content = content.decode("utf-8") except UnicodeError: file.content = content.decode("iso8859-1") file.save() submission.file = file submission.save() return HttpResponseRedirect('/team/submission/') else: form = SubmitForm() profile.team.new_results = False profile.team.save() submissions = Submission.objects.filter(team=profile.team).order_by("-timestamp") result_list = [] for s in submissions: try: judgement = s.result.judgement except AttributeError: judgement = "Pending..." r = {'time': gettime(s.timestamp, contest), 'problem': s.problem, 'judgement': judgement} result_list.append(r) return render_to_response('team_submission.html', {"profile": profile, 'form': form, 'results': result_list}, context_instance=RequestContext(request))