Esempio n. 1
0
def _answers_data(request, question_id, form=None, watch_form=None,
                  answer_preview=None):
    """Return a map of the minimal info necessary to draw an answers page."""
    question = get_object_or_404(Question, pk=question_id)
    answers_ = question.answers.all()
    if not request.MOBILE:
        answers_ = paginate(request, answers_,
                            per_page=constants.ANSWERS_PER_PAGE)
    feed_urls = ((reverse('questions.answers.feed',
                          kwargs={'question_id': question_id}),
                  AnswersFeed().title(question)),)
    frequencies = dict(FREQUENCY_CHOICES)

    is_watching_question = (
        request.user.is_authenticated() and (
        QuestionReplyEvent.is_notifying(request.user, question) or
        QuestionSolvedEvent.is_notifying(request.user, question)))
    return {'question': question,
            'answers': answers_,
            'form': form or AnswerForm(),
            'answer_preview': answer_preview,
            'watch_form': watch_form or _init_watch_form(request, 'reply'),
            'feeds': feed_urls,
            'frequencies': frequencies,
            'is_watching_question': is_watching_question,
            'can_tag': request.user.has_perm('questions.tag_question'),
            'can_create_tags': request.user.has_perm('taggit.add_tag')}
Esempio n. 2
0
def _answers_data(request, question_id, form=None, watch_form=None, answer_preview=None):
    """Return a map of the minimal info necessary to draw an answers page."""
    question = get_object_or_404(Question, pk=question_id)
    answers_ = paginate(request, question.answers.all(), per_page=constants.ANSWERS_PER_PAGE)
    vocab = [t.name for t in Tag.objects.all()]  # TODO: Fetch only name.
    feed_urls = (
        (reverse("questions.answers.feed", kwargs={"question_id": question_id}), AnswersFeed().title(question)),
    )
    frequencies = dict(FREQUENCY_CHOICES)

    is_watching_question = request.user.is_authenticated() and (
        QuestionReplyEvent.is_notifying(request.user, question)
        or QuestionSolvedEvent.is_notifying(request.user, question)
    )
    return {
        "question": question,
        "answers": answers_,
        "form": form or AnswerForm(),
        "answer_preview": answer_preview,
        "watch_form": watch_form or _init_watch_form(request, "reply"),
        "feeds": feed_urls,
        "tag_vocab": json.dumps(vocab),
        "frequencies": frequencies,
        "is_watching_question": is_watching_question,
        "can_tag": request.user.has_perm("questions.tag_question"),
        "can_create_tags": request.user.has_perm("taggit.add_tag"),
    }
Esempio n. 3
0
File: views.py Progetto: tantek/kuma
def _answers_data(request, question_id, form=None, watch_form=None,
                  answer_preview=None):
    """Return a map of the minimal info necessary to draw an answers page."""
    question = get_object_or_404(Question, pk=question_id)
    answers_ = paginate(request, question.answers.all(),
                        per_page=constants.ANSWERS_PER_PAGE)
    vocab = [t.name for t in Tag.objects.all()]  # TODO: Fetch only name.
    feed_urls = ((reverse('questions.answers.feed',
                          kwargs={'question_id': question_id}),
                  AnswersFeed().title(question)),)
    frequencies = dict(FREQUENCY_CHOICES)

    is_watching_question = (
        request.user.is_authenticated() and (
        QuestionReplyEvent.is_notifying(request.user, question) or
        QuestionSolvedEvent.is_notifying(request.user, question)))
    return {'question': question,
            'answers': answers_,
            'form': form or AnswerForm(),
            'answer_preview': answer_preview,
            'watch_form': watch_form or _init_watch_form(request, 'reply'),
            'feeds': feed_urls,
            'tag_vocab': json.dumps(vocab),
            'frequencies': frequencies,
            'is_watching_question': is_watching_question,
            'can_tag': request.user.has_perm('questions.tag_question'),
            'can_create_tags': request.user.has_perm('taggit.add_tag')}
Esempio n. 4
0
    def _watch_question(self):
        """Helper to watch a question."""
        question = Question.objects.all()[0]
        self.client.login(username='******', password='******')
        user = User.objects.get(username='******')

        # Make sure it isn't watching yet.
        assert not QuestionSolvedEvent.is_notifying(user, question), (
            '%s should not be notifying.' % QuestionSolvedEvent.__name__)

        post(self.client, 'questions.watch', {}, args=[question.id])

        assert QuestionSolvedEvent.is_notifying(user, question), (
            '%s should be notifying.' % QuestionSolvedEvent.__name__)

        return question
Esempio n. 5
0
    def _watch_question(self):
        """Helper to watch a question."""
        question = Question.objects.all()[0]
        self.client.login(username='******', password='******')
        user = User.objects.get(username='******')

        # Make sure it isn't watching yet.
        assert not QuestionSolvedEvent.is_notifying(user, question), (
            '%s should not be notifying.' % QuestionSolvedEvent.__name__)

        post(self.client, 'questions.watch', {}, args=[question.id])

        assert QuestionSolvedEvent.is_notifying(user, question), (
            '%s should be notifying.' % QuestionSolvedEvent.__name__)

        return question
Esempio n. 6
0
    def test_watch_solution(self, get_current):
        """Watch a question for solution."""
        self.client.logout()
        get_current.return_value.domain = "testserver"

        post(self.client, "questions.watch", {"email": "*****@*****.**", "event_type": "solution"}, args=[self.question.id])
        assert QuestionSolvedEvent.is_notifying("*****@*****.**", self.question), "Watch was not created"

        attrs_eq(mail.outbox[0], to=["*****@*****.**"], subject="Please confirm your email address")
        assert "questions/confirm/" in mail.outbox[0].body
        assert "Solution found" in mail.outbox[0].body

        # Now activate the watch.
        w = Watch.objects.get()
        get(self.client, "questions.activate_watch", args=[w.id, w.secret])
        assert Watch.objects.get().is_active
Esempio n. 7
0
    def test_watch_solution(self, get_current):
        """Watch a question for solution."""
        self.client.logout()
        get_current.return_value.domain = 'testserver'

        post(self.client, 'questions.watch',
             {'email': '*****@*****.**', 'event_type': 'solution'},
             args=[self.question.id])
        assert QuestionSolvedEvent.is_notifying('*****@*****.**', self.question), (
               'Watch was not created')

        attrs_eq(mail.outbox[0], to=['*****@*****.**'],
                 subject='Please confirm your email address')
        assert 'questions/confirm/' in mail.outbox[0].body
        assert 'Solution found' in mail.outbox[0].body

        # Now activate the watch.
        w = Watch.objects.get()
        get(self.client, 'questions.activate_watch', args=[w.id, w.secret])
        assert Watch.objects.get().is_active
Esempio n. 8
0
    def test_watch_solution(self, get_current):
        """Watch a question for solution."""
        self.client.logout()
        get_current.return_value.domain = 'testserver'

        post(self.client, 'questions.watch',
             {'email': '*****@*****.**', 'event_type': 'solution'},
             args=[self.question.id])
        assert QuestionSolvedEvent.is_notifying('*****@*****.**', self.question), (
               'Watch was not created')

        attrs_eq(mail.outbox[0], to=['*****@*****.**'],
                 subject='Please confirm your email address')
        assert 'questions/confirm/' in mail.outbox[0].body
        assert 'Solution found' in mail.outbox[0].body

        # Now activate the watch.
        w = Watch.objects.get()
        get(self.client, 'questions.activate_watch', args=[w.id, w.secret])
        assert Watch.objects.get().is_active