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')}
{'content_type': ContentType.objects.get_for_model(Question).id}, name='questions.flag'), url(r'^/(?P<question_id>\d+)/flag/(?P<object_id>\d+)$', flagit_views.flag, {'content_type': ContentType.objects.get_for_model(Answer).id}, name='questions.answer_flag'), # Subcribe by email url(r'^/(?P<question_id>\d+)/watch$', 'watch_question', name='questions.watch'), url(r'^/(?P<question_id>\d+)/unwatch$', 'unwatch_question', name='questions.unwatch'), url(r'^/confirm/(?P<watch_id>\d+)/(?P<secret>\w+)$', 'activate_watch', name='questions.activate_watch'), url(r'^/unsubscribe/(?P<watch_id>\d+)/(?P<secret>\w+)$', 'unsubscribe_watch', name='questions.unsubscribe'), # Feeds url(r'^/feed$', QuestionsFeed(), name='questions.feed'), url(r'^/(?P<question_id>\d+)/feed$', AnswersFeed(), name='questions.answers.feed'), url(r'^/tagged/(?P<tag_slug>[\w\-]+)/feed$', TaggedQuestionsFeed(), name='questions.tagged_feed'), )
url(r'^/(?P<question_id>\d+)/add-tag-async$', 'add_tag_async', name='questions.add_tag_async'), url(r'^/(?P<question_id>\d+)/remove-tag-async$', 'remove_tag_async', name='questions.remove_tag_async'), # Flag content ("Report this post") url(r'^/(?P<object_id>\d+)/flag$', flagit_views.flag, {'content_type': ContentType.objects.get_for_model(Question).id}, name='questions.flag'), url(r'^/(?P<question_id>\d+)/flag/(?P<object_id>\d+)$', flagit_views.flag, {'content_type': ContentType.objects.get_for_model(Answer).id}, name='questions.answer_flag'), # Subcribe by email url(r'^/(?P<question_id>\d+)/watch$', 'watch_question', name='questions.watch'), url(r'^/(?P<question_id>\d+)/unwatch$', 'unwatch_question', name='questions.unwatch'), url(r'^/confirm/(?P<watch_id>\d+)/(?P<secret>\w+)$', 'activate_watch', name='questions.activate_watch'), url(r'^/unsubscribe/(?P<watch_id>\d+)/(?P<secret>\w+)$', 'unsubscribe_watch', name='questions.unsubscribe'), # Feeds url(r'^/feed$', QuestionsFeed(), name='questions.feed'), url(r'^/(?P<question_id>\d+)/feed$', AnswersFeed(), name='questions.answers.feed'), url(r'^/tagged/(?P<tag_slug>[\w\-]+)/feed$', TaggedQuestionsFeed(), name='questions.tagged_feed'), )