Esempio n. 1
0
def edit_comment_from_problem(request, problem_id, comment_id):
    problem = logic.get_problem(problem_id)
    comment = comments_logic.get_comment(comment_id)
    if request.method == 'POST':
        comment = logic.edit_comment_problem(request, problem, comment_id)
        return HttpResponseRedirect('/problems/' + str(problem_id))
    else:
        comment_form = CommentForm()
    return render(request, 'problems/edit_comment.html',
                  {'form': comment_form, 'problem_id': problem_id, 'comment':comment})
Esempio n. 2
0
def new_comment_problem(request, problem_id):
    print "inside new_problem_comment."
    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()
    problem = logic.get_problem(problem_id)
    if request.method == "POST":
        logic.new_comment_problem(request, problem)
    # return HttpResponseRedirect('/problems/' + str(problem_id))
    return HttpResponse(status=200)
Esempio n. 3
0
def delete_problem(request, problem_id):
    user = User.objects.get(email=request.session["email"])
    try:
        problem = logic.get_problem(problem_id)
    except Exception as e:
        print e
        return HttpResponseRedirect("/problems/")
    if request.method == "POST":
        print "inside post"
        logic.delete_problem(request, problem)
        return HttpResponseRedirect("/problems/")
    else:
        return render(request, "problems/delete_problem.html", {"problem": problem, "user": user})
Esempio n. 4
0
def new_solution(request, problem_id):
    problem = logic.get_problem(problem_id)
    if request.method == "POST":
        solution_form = SolutionForm(request.POST)
        if solution_form.is_valid():
            # print "The users line is: ", submission_form['members_list']
            solution = solution_form.save(commit=False)
            solution.problem = problem
            user_profile = User.objects.get(email=request.session['email'])
            solution.user = user_profile
            solution.description = bleach.clean(solution.description, strip=True)
            solution.save()
            return HttpResponseRedirect('/problems/' + str(problem_id))
        else:
            raise Http404('Form is not valid')

    else:
        solution_form = SolutionForm()
        return render(request, 'problems/new_solution.html', {'form': solution_form, 'problem_id': problem_id})
Esempio n. 5
0
def add_comment_to_problem(request, problem_id):
    problem = logic.get_problem(problem_id)
    if request.method == "POST":
        logic.new_comment_problem(request, problem)
    return HttpResponseRedirect("/problems/" + str(problem_id))
Esempio n. 6
0
def problem_as_json(request, problem_id):
    return HttpResponse(logic.get_problem_as_json(logic.get_problem(problem_id)), content_type="application/json")
Esempio n. 7
0
def vote_problem(request, problem_id, vote):
    print "Inside vote_problem for problem id: ", problem_id, "and vote: ", vote
    problem = logic.get_problem(problem_id)
    problem = logic.vote_on_problem(request, problem, vote)
    # return HttpResponseRedirect('/problems/' + str(problem_id))
    return HttpResponse(logic.get_problem_as_json(problem), content_type="application/json")
Esempio n. 8
0
def mark_problem(request, problem_id):
    problem = logic.get_problem(problem_id)
    problem.marked = datetime.today()
    problem.save()
    return HttpResponseRedirect("/problems/" + str(problem_id))