Example #1
0
def question(request, id, slug='', answer=None):
    try:
        question = Question.objects.get(id=id)
    except:
        if slug:
            question = match_question_slug(id, slug)
            if question is not None:
                return HttpResponseRedirect(question.get_absolute_url())

        raise Http404()

    if question.nis.deleted and not request.user.can_view_deleted_post(
            question):
        raise Http404

    if request.GET.get('type', None) == 'rss':
        return RssAnswerFeed(request,
                             question,
                             include_comments=request.GET.get(
                                 'comments', None) == 'yes')(request)

    if answer:
        answer = get_object_or_404(Answer, id=answer)

        if (question.nis.deleted
                and not request.user.can_view_deleted_post(question)
            ) or answer.question != question:
            raise Http404

        if answer.marked:
            return HttpResponsePermanentRedirect(question.get_absolute_url())

        return answer_redirect(request, answer)

    if settings.FORCE_SINGLE_URL and (slug != slugify(question.title)):
        return HttpResponsePermanentRedirect(question.get_absolute_url())

    if request.POST:
        answer_form = AnswerForm(request.POST, user=request.user)
    else:
        answer_form = AnswerForm(user=request.user)

    answers = request.user.get_visible_answers(question)

    update_question_view_times(request, question)

    if request.user.is_authenticated():
        try:
            subscription = QuestionSubscription.objects.get(question=question,
                                                            user=request.user)
        except:
            subscription = False
    else:
        subscription = False
    try:
        focused_answer_id = int(request.GET.get("focusedAnswerId", None))
    except TypeError, ValueError:
        focused_answer_id = None
Example #2
0
def question(request, id, slug='', answer=None):
    try:
        question = Question.objects.get(id=id)
    except:
        if slug:
            question = match_question_slug(id, slug)
            if question is not None:
                return HttpResponseRedirect(question.get_absolute_url())

        raise Http404()

    if question.nis.deleted and not request.user.can_view_deleted_post(question):
        raise Http404

    if request.GET.get('type', None) == 'rss':
        return RssAnswerFeed(request, question, include_comments=request.GET.get('comments', None) == 'yes')(request)

    if answer:
        answer = get_object_or_404(Answer, id=answer)

        if (question.nis.deleted and not request.user.can_view_deleted_post(question)) or answer.question != question:
            raise Http404

        if answer.marked:
            return HttpResponsePermanentRedirect(question.get_absolute_url())

        return answer_redirect(request, answer)

    if settings.FORCE_SINGLE_URL and (slug != slugify(question.title)):
        return HttpResponsePermanentRedirect(question.get_absolute_url())

    if request.POST:
        answer_form = AnswerForm(request.POST, user=request.user)
    else:
        answer_form = AnswerForm(user=request.user)

    answers = request.user.get_visible_answers(question)

    update_question_view_times(request, question)

    if request.user.is_authenticated():
        try:
            subscription = QuestionSubscription.objects.get(question=question, user=request.user)
        except:
            subscription = False
    else:
        subscription = False

    from django.db import connection, transaction
    cursor = connection.cursor()
    cursor.execute("SELECT a.user_id, a.score FROM analytics_answerer_recommendation a WHERE a.question_id=%s AND NOT EXISTS (SELECT * FROM forum_node f WHERE f.id=a.question_id AND f.author_id=a.user_id) AND NOT EXISTS (SELECT * FROM forum_node f2 WHERE f2.parent_id=a.question_id AND f2.author_id=a.user_id) AND NOT EXISTS (SELECT * FROM forum_node f3 WHERE f3.parent_id=a.question_id AND f3.marked=1) ORDER BY score ASC LIMIT 12", [question.id])
    row_list = cursor.fetchall()
    user_list = []

    for row in row_list:
        user = User.objects.get(pk=row[0])
        if (row[1] > 0):
            user_list.append({"user": user, "score": row[1]})

    return pagination.paginated(request, ('answers', AnswerPaginatorContext()), {
    "question" : question,
    "answer" : answer_form,
    "answers" : answers,
    "similar_questions" : question.get_related_questions(),
    "subscription": subscription,
    "recommendedanswerers": user_list,
    })
Example #3
0
def question(request, id, slug='', answer=None):
    try:
        question = Question.objects.get(id=id)
    except:
        if slug:
            question = match_question_slug(id, slug)
            if question is not None:
                return HttpResponseRedirect(question.get_absolute_url())

        raise Http404()

    if question.nis.deleted and not request.user.can_view_deleted_post(
            question):
        raise Http404

    if request.GET.get('type', None) == 'rss':
        return RssAnswerFeed(request,
                             question,
                             include_comments=request.GET.get(
                                 'comments', None) == 'yes')(request)

    if answer:
        answer = get_object_or_404(Answer, id=answer)

        if (question.nis.deleted
                and not request.user.can_view_deleted_post(question)
            ) or answer.question != question:
            raise Http404

        if answer.marked:
            return HttpResponsePermanentRedirect(question.get_absolute_url())

        return answer_redirect(request, answer)

    if settings.FORCE_SINGLE_URL and (slug != slugify(question.title)):
        return HttpResponsePermanentRedirect(question.get_absolute_url())

    if request.POST:
        answer_form = AnswerForm(request.POST, user=request.user)
    else:
        answer_form = AnswerForm(user=request.user)

    answers = request.user.get_visible_answers(question)

    update_question_view_times(request, question)

    if request.user.is_authenticated():
        try:
            subscription = QuestionSubscription.objects.get(question=question,
                                                            user=request.user)
        except:
            subscription = False
    else:
        subscription = False
    from forum.models import CustomBadge
    response_restricted = CustomBadge.is_response_restricted(
        request.user, question)

    return pagination.paginated(
        request, ('answers', AnswerPaginatorContext()), {
            "question": question,
            "answer": answer_form,
            "answers": answers,
            "similar_questions": question.get_related_questions(),
            "subscription": subscription,
            'response_restricted': response_restricted,
        })