def show_submits(request, problem_id): try: problem = Problem.objects.get(id=problem_id) except TestProgram.DoesNotExist: return HttpResponse("Nie istnieje taki problem") tmp = check_user_priviledge(request, problem.group) if tmp != True: return tmp if request.user.is_staff: submits_list_total = Submit.objects.filter(problem=problem).order_by('-pub_date') else: submits_list_total = Submit.objects.filter(problem=problem, user=request.user).order_by('-pub_date') paginator = Paginator(submits_list_total, 25) page = request.GET.get('page') try: submits_list = paginator.page(page) except PageNotAnInteger: submits_list = paginator.page(1) except EmptyPage: submits_list = paginator.page(paginator.num_pages) return render(request, 'problems/show_submits.html', {'problem': problem, 'submits_list': submits_list})
def index(request, shortname): # shortname = "MAIN"; # if request.session['group'] != "": # shortname = request.session['group'] try: group = Group.objects.get(shortname=shortname) except Group.DoesNotExist: return HttpResponseRedirect('/problems/groups/') request.session['group'] = shortname if not group.open: tmp = check_user_priviledge(request, group) if tmp != True: return tmp problems_list_total = Problem.objects.filter(group=group).order_by('pub_date') paginator = Paginator(problems_list_total, 25) page = request.GET.get('page') try: problems_list = paginator.page(page) except PageNotAnInteger: problems_list = paginator.page(1) except EmptyPage: problems_list = paginator.page(paginator.num_pages) return render(request, 'problems/index.html', {'problems_list': problems_list, 'group': group})
def submit(request, problem_id): if not request.user.is_authenticated(): return HttpResponseRedirect('/user/') form = SubmitForm() problem = Problem.objects.get(id=problem_id) tmp = check_user_priviledge(request, problem.group) if tmp != True: return tmp if request.method == 'POST': form = SubmitForm(request.POST) if form.is_valid(): if len(form.cleaned_data['code']) > 100000: return HttpResponse("Za długi program") problem.submit_set.create(code=form.cleaned_data['code'], pub_date=timezone.now(), user=request.user) thr = Thread(target=execute) thr.start() # execute() return HttpResponseRedirect('/submits') else: form = SubmitForm() return render(request, 'problems/submit.html', {'problem': problem, 'form': form})
def download(request, problem_id): try: problem = Problem.objects.get(id=problem_id) tmp = check_user_priviledge(request, problem.group) if tmp != True: return tmp if settings.PRODUCTION: file = open(problem.pdf_file_link, 'rb') response = HttpResponse(file, content_type='application/pdf') return response else: return HttpResponseRedirect(problem.pdf_file_link) except Problem.DoesNotExist: return HttpResponse(request, "Nie istnieje taki problem")
def detail(request, problem_id): try: problem = Problem.objects.get(id=problem_id) except Problem.DoesNotExist: return HttpResponse("Nie istnieje taki problem") group = Group.objects.get(problem=problem) request.session['group'] = group.shortname tmp = check_user_priviledge(request, group) if tmp != True: return tmp tests = TestProgram.objects.filter(problem=problem) list_of_comments = Comment.objects.filter(problem=problem) context = {'problem': problem, 'tests': tests, 'comments_num': len(list_of_comments)} return render(request, 'problems/detail.html', context)
def comment(request, problem_id): message = '' form = CommentForm() problem = Problem.objects.get(id=problem_id) tmp = check_user_priviledge(request, problem.group) if tmp != True: return tmp if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): if len(form.cleaned_data['content']) > 5000: return HttpResponse("Za długi komentarz") problem.comment_set.create(content=form.cleaned_data['content'], pub_date=timezone.now(), user=request.user) return HttpResponseRedirect('/problems/%s/comments' % problem_id) else: form = CommentForm() message = "Błąd w formularzu" return render(request, 'problems/comment.html', {'problem': problem, 'form': form, 'message': message})
def comment(request, problem_id): message = "" form = CommentForm() problem = Problem.objects.get(id=problem_id) tmp = check_user_priviledge(request, problem.group) if tmp != True: return tmp if request.method == "POST": form = CommentForm(request.POST) if form.is_valid(): if len(form.cleaned_data["content"]) > 5000: return HttpResponse("Za długi komentarz") problem.comment_set.create(content=form.cleaned_data["content"], pub_date=timezone.now(), user=request.user) return HttpResponseRedirect("/problems/%s/comments" % problem_id) else: form = CommentForm() message = "Błąd w formularzu" return render(request, "problems/comment.html", {"problem": problem, "form": form, "message": message})
def comments(request, problem_id): try: problem = Problem.objects.get(id=problem_id) except Problem.DoesNotExist: return HttpResponse("Nie istnieje taki problem") tmp = check_user_priviledge(request, problem.group) if tmp != True: return tmp comments_list_total = Comment.objects.filter(problem=problem) form = CommentForm() paginator = Paginator(comments_list_total, 10) page = request.GET.get('page') try: comment_list = paginator.page(page) except PageNotAnInteger: comment_list = paginator.page(1) except EmptyPage: comment_list = paginator.page(paginator.num_pages) context = {'problem': problem, 'comment_list': comment_list, 'form': form} return render(request, 'problems/comments.html', context)