Example #1
0
def submitProblem(request):
    if request.POST['problemId'] != '':
        problem = PublicProblem.objects.get(pk=request.POST['problemId'])
        if request.user != problem.author:
            return HttpResponse("you don't have permission to edit this problem")
    else:
        problem = PublicProblem()
        problem.category = Categories.objects.get(pk=request.POST['categoryId'])
        problem.author = User.objects.get(username=request.user.username)

    problem.text = request.POST['textEditor']
    problem.javascript = request.POST['codeEditor']
    problem.title = request.POST['title']

    problem.save()

    return HttpResponseRedirect(request.POST['nextURL'])
Example #2
0
def index(request, categoryId=None, problemId=None):
	try:
		practiceProblem = PublicProblem.objects.get(title="temporary-problem-" + request.user.username)
	except ObjectDoesNotExist:
		practiceProblem = PublicProblem()
		practiceProblem.title = "temporary-problem-" + request.user.username
		practiceProblem.category = Categories.objects.get(title="temporary")
		practiceProblem.author = User.objects.get(username=request.user.username)
		practiceProblem.save()
		
	problem = None
	if problemId is not None:
	    problem = PublicProblem.objects.get(pk=problemId)
	    if request.user != problem.author:
		    return HttpResponse("you don't have permission to edit this problem")
	
	return render(request, "createproblem/index.html", {'id':practiceProblem.id, 'categoryId':categoryId, 'problem':problem, 'nextURLTemplateVariable':request.GET['nextURL']})