@require_POST
@login_required
@ratelimit('answer-min', '4/m', skip_if=_skip_answer_ratelimit)
@ratelimit('answer-day', '100/d', skip_if=_skip_answer_ratelimit)
def reply(request, question_id):
    """Post a new answer to a question."""
    question = get_object_or_404(Question, pk=question_id, is_spam=False)
    answer_preview = None

    if not question.allows_new_answer(request.user):
        raise PermissionDenied

    form = AnswerForm(request.POST)

    # NOJS: delete images
    if 'delete_images' in request.POST:
        for image_id in request.POST.getlist('delete_image'):
            ImageAttachment.objects.get(pk=image_id).delete()

        return question_details(request, question_id=question_id, form=form)

    # NOJS: upload image
    if 'upload_image' in request.POST:
        upload_imageattachment(request, request.user)
        return question_details(request, question_id=question_id, form=form)

    if form.is_valid() and not request.limited:
        answer = Answer(question=question, creator=request.user,
                        content=form.cleaned_data['content'])
        if 'preview' in request.POST:
            answer_preview = answer
        else:
            answer.save()
            ans_ct = ContentType.objects.get_for_model(answer)
            # Move over to the answer all of the images I added to the
            # reply form
            user_ct = ContentType.objects.get_for_model(request.user)
            up_images = ImageAttachment.objects.filter(creator=request.user,
                                                       content_type=user_ct)
            up_images.update(content_type=ans_ct, object_id=answer.id)
            statsd.incr('questions.answer')

            # Handle needsinfo tag
            if 'needsinfo' in request.POST:
                question.set_needs_info()
            elif 'clear_needsinfo' in request.POST:
                question.unset_needs_info()

            if Setting.get_for_user(request.user,
                                    'questions_watch_after_reply'):
                QuestionReplyEvent.notify(request.user, question)

            return HttpResponseRedirect(answer.get_absolute_url())

    return question_details(
        request, question_id=question_id, form=form,
        answer_preview=answer_preview)
dataset/ETHPy150Open mozilla/kitsune/kitsune/questions/views.py/reply/original