예제 #1
0
def add_comment_to_solution(request, problem_id, solution_id):
    print "inside add_comment_to_solution"
    solution = logic.get_solution(solution_id)
    if request.method == "POST":
        print "request method is post!"
        logic.new_comment_solution(request, solution)
    print "sending to show_solution from add_comment_to_solution"
    return HttpResponseRedirect("/problems/" + str(problem_id) + "/show_solution/" + str(solution_id))
예제 #2
0
def new_comment_solution(request, problem_id, solution_id):
    print "inside new_comment_solution."
    print "Here is the POST: ", request.POST.get("content")
    print "Here is the data: ", json.loads(request.body)["content"]
    print "Is is ajax? ", request.is_ajax()
    solution = logic.get_solution(solution_id)
    if request.method == "POST":
        logic.new_comment_solution(request, solution)
    return HttpResponse(status=200)
예제 #3
0
def delete_solution(request, problem_id, solution_id):
    print "inside edit_solution"
    solution = logic.get_solution(solution_id)
    if request.method == 'POST':
        print "inside post"
        logic.delete_solution(request, solution)
        return HttpResponseRedirect('/problems/' + str(problem_id))
    else:
        return render(request, 'problems/delete_solution.html', {'solution': solution, 'problem_id': problem_id})
예제 #4
0
def edit_comment_from_solution(request, problem_id, solution_id, comment_id):
    solution = logic.get_solution(solution_id)
    comment = comments_logic.get_comment(comment_id)
    if request.method == 'POST':
        comment = logic.edit_comment_solution(request, solution, comment_id)
        return HttpResponseRedirect('/problems/' + str(problem_id) + '/show_solution/' + str(solution_id))
    else:
        comment_form = CommentForm()
    return render(request, 'problems/edit_comment_solution.html',
                  {'form': comment_form, 'problem_id':problem_id, 'solution_id': solution_id, 'comment':comment})
예제 #5
0
def edit_solution(request, problem_id, solution_id):
    print "inside edit_solution"
    solution = logic.get_solution(solution_id)
    if request.method == 'POST':
        print "inside post"
        logic.edit_solution(request, solution)
        return HttpResponseRedirect('/problems/' + str(problem_id) + '/show_solution/' + str(solution_id))
    else:
        form = SolutionForm()
        return render(request, 'problems/edit_solution.html', {'form': form, 'solution': solution, 'problem_id': problem_id})
예제 #6
0
def delete_solution(request, problem_id, solution_id):
    user = User.objects.get(email=request.session["email"])
    try:
        solution = logic.get_solution(solution_id)
    except Exception as e:
        print e
        return HttpResponseRedirect("/problems/" + str(problem_id))
    if request.method == "POST":
        print "inside post"
        logic.delete_solution(request, solution)
        return HttpResponseRedirect("/problems/" + str(problem_id))
    else:
        return render(
            request, "problems/delete_solution.html", {"solution": solution, "problem_id": problem_id, "user": user}
        )
예제 #7
0
def delete_comment_from_solution(request, problem_id, solution_id, comment_id):
    print "Inside delete_comment_from_solution."
    solution = logic.get_solution(solution_id)
    if request.method == "POST":
        logic.delete_comment_solution(request, solution, comment_id)
    return HttpResponseRedirect("/problems/" + str(problem_id) + "/show_solution/" + str(solution_id))
예제 #8
0
def solution_as_json(request, solution_id):
    return HttpResponse(logic.get_solution_as_json(logic.get_solution(solution_id)), content_type="application/json")
예제 #9
0
def vote_solution(request, problem_id, solution_id, vote=0):
    solution = logic.get_solution(solution_id)
    solution = logic.vote_on_solution(request, solution, vote)
    return HttpResponse(logic.get_solution_as_json(solution), content_type="application/json")
예제 #10
0
def delete_comment_from_solution(request, problem_id, solution_id, comment_id):
    solution = logic.get_solution(solution_id)
    if request.method == 'GET':
        logic.delete_comment_solution(request, solution, comment_id)
    return HttpResponseRedirect('/problems/' + str(problem_id) + '/show_solution/' + str(solution_id))