예제 #1
0
파일: views.py 프로젝트: rtbortolin/QandA
def make_a_vote(request):
    if request.method == "GET":
        raise Http404
    if request.method == "POST":
        question_id = request.POST['question_id']
        answer_id = request.POST['answer_id']
        vote_for = request.POST['votefor']
        vote_type = request.POST['vote_type']

        vote_type = 'P' if vote_type == 'like' else 'N'

        user = request.user.userprofile
           
        if(answer_id == '' and vote_for == 'answer'):
            raise Http404

        if(vote_for == 'question'):
            question_utils = QuestionServices()
            question_utils.vote(question_id, vote_type, user)
            return HttpResponse('true', content_type="application/json")
        elif (vote_for == 'answer'):
            answer_utils = AnswerServices()
            answer_utils.vote(question_id, answer_id, vote_type, user) 
            return HttpResponse('true', content_type="application/json")
        else :
            return HttpResponse('false', content_type="application/json")
예제 #2
0
def make_a_vote(request):
    if request.method == "GET":
        raise Http404
    if request.method == "POST":
        question_id = request.POST['question_id']
        answer_id = request.POST['answer_id']
        vote_for = request.POST['votefor']
        vote_type = request.POST['vote_type']

        vote_type = 'P' if vote_type == 'like' else 'N'

        user = request.user.userprofile

        if (answer_id == '' and vote_for == 'answer'):
            raise Http404

        if (vote_for == 'question'):
            question_utils = QuestionServices()
            question_utils.vote(question_id, vote_type, user)
            return HttpResponse('true', content_type="application/json")
        elif (vote_for == 'answer'):
            answer_utils = AnswerServices()
            answer_utils.vote(question_id, answer_id, vote_type, user)
            return HttpResponse('true', content_type="application/json")
        else:
            return HttpResponse('false', content_type="application/json")
예제 #3
0
파일: views.py 프로젝트: rtbortolin/QandA
def make_answer_comment(request):
    if request.method == "GET":
        raise Http404
    if request.method == "POST":
        form = CommentForm(request.POST)
        user = request.user.userprofile

        answer_services = AnswerServices()
        comment = answer_services.create_comment(form.data['comment'], form.data['question_id'], form.data['answer_id'], user)        
        return HttpResponseRedirect('/question/' + form.data['question_id'] + '?comment=' + str(comment.id) + '&answer=' + form.data['answer_id'])
예제 #4
0
def make_answer_comment(request):
    if request.method == "GET":
        raise Http404
    if request.method == "POST":
        form = CommentForm(request.POST)
        user = request.user.userprofile

        answer_services = AnswerServices()
        comment = answer_services.create_comment(form.data['comment'],
                                                 form.data['question_id'],
                                                 form.data['answer_id'], user)
        return HttpResponseRedirect('/question/' + form.data['question_id'] +
                                    '?comment=' + str(comment.id) +
                                    '&answer=' + form.data['answer_id'])