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})
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})
def delete_comment_solution(request, solution, comment_id): comment = comments_logic.get_comment(comment_id) if comment: if comment in solution.comments.all(): solution.comments.remove(comment) else: return False comments_logic.delete_comment(request, comment) return True else: print "something went wrong, couldn't find comment" return False
def edit_comment_solution(request, solution, comment_id): """ Edit comment. """ comment = comments_logic.get_comment(comment_id) # Return false if comment is not in this problem! if comment: if comment not in solution.comments.all(): return False comments_logic.edit_comment(request, comment) return comment else: print "something went wrong, couldn't find comment" return False
def delete_comment_problem(request, problem, comment_id): print "inside logic deletecommentproblem" comment = comments_logic.get_comment(comment_id) if comment: if comment in problem.comments.all(): problem.comments.remove(comment) else: return False comments_logic.delete_comment(request, comment) return True else: print "something went wrong, couldn't find comment" return False
def delete_comment_problem(request, problem, comment_id): print "inside logic deletecommentproblem" comment = comments_logic.get_comment(comment_id) if comment and is_authorized(comment, request.session["email"]): if comment in problem.comments.all(): problem.comments.remove(comment) else: return False problem.save() comments_logic.delete_comment(request, comment) return True else: print "something went wrong, couldn't find comment" return False
def delete_comment_solution(request, solution, comment_id): comment = comments_logic.get_comment(comment_id) if comment and is_authorized(comment, request.session["email"]): if comment in solution.comments.all(): print "Removing solution's comment. ", comment.content solution.comments.remove(comment) else: return False solution.save() comments_logic.delete_comment(request, comment) return True else: print "something went wrong, couldn't find comment" return False