def ajax_delete_question(request): result = False if request.method == "POST": key = request.POST['question_id'] question = get_object_or_404(Question, pk=key) if can_edit(user=request.user, obj=question): question.delete() result = True return HttpResponse(json.dumps(result), mimetype='application/json')
def ajax_answer_delete(request): if request.method == 'POST': aid = request.POST['answer_id'] answer = get_object_or_404(Answer, pk=aid) if can_edit(user=request.user, obj=answer): answer.delete() return HttpResponse("deleted") return HttpResponseForbidden("Not Authorised")
def ajax_answer_comment_update(request): if request.method == "POST": comment_id = request.POST["comment_id"] comment_body = request.POST["comment_body"] comment = get_object_or_404(AnswerComment, pk=comment_id) if can_edit(user=request.user, obj=comment): comment.body = comment_body.encode('unicode_escape') comment.save() return HttpResponse("saved") return HttpResponseForbidden("Not Authorised")
def ajax_answer_update(request): if request.method == 'POST': aid = request.POST['answer_id'] body = request.POST['answer_body'] answer = get_object_or_404(Answer, pk=aid) if can_edit(user=request.user, obj=answer): answer.body = body.encode('unicode_escape') answer.save() return HttpResponse("saved") return HttpResponseForbidden("Not Authorised")
def ajax_question_update(request): if request.method == 'POST': qid = request.POST['question_id'] title = request.POST['question_title'] body = request.POST['question_body'] question = get_object_or_404(Question, pk=qid) if can_edit(user=request.user, obj=question): question.title = title question.body = body.encode('unicode_escape') question.save() return HttpResponse("saved") return HttpResponseForbidden("Not Authorised")
def ajax_details_update(request): if request.method == 'POST': qid = request.POST['qid'] category = request.POST['category'] tutorial = request.POST['tutorial'] minute_range = request.POST['minute_range'] second_range = request.POST['second_range'] question = get_object_or_404(Question, pk=qid) if can_edit(user=request.user, obj=question): question.category = category question.tutorial = tutorial question.minute_range = minute_range question.second_range = second_range question.save() return HttpResponse("saved") return HttpResponseForbidden("Not Authorised")