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()

    # Remove spam flag if an answer passed the moderation queue
    if not settings.READ_ONLY:
        answers_.filter(flags__status=2).update(is_spam=False)

    if not request.user.has_perm("flagit.can_moderate"):
        answers_ = answers_.filter(is_spam=False)

    answers_ = paginate(request, answers_, per_page=config.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
from django.conf.urls import patterns, url
from django.contrib.contenttypes.models import ContentType

from kitsune.questions.feeds import (QuestionsFeed, AnswersFeed,
                                     TaggedQuestionsFeed)
from kitsune.questions.models import Question, Answer
from kitsune.flagit import views as flagit_views
from kitsune.sumo.views import handle404

if settings.DISABLE_FEEDS:
    questions_feed_view = handle404
    answers_feed_view = handle404
    tagged_feed_view = handle404
else:
    questions_feed_view = QuestionsFeed()
    answers_feed_view = AnswersFeed()
    tagged_feed_view = TaggedQuestionsFeed()

urlpatterns = patterns(
    'kitsune.questions.views',
    url(r'^$', 'product_list', name='questions.home'),
    url(r'^/answer-preview-async$',
        'answer_preview_async',
        name='questions.answer_preview_async'),
    url(r'^/dashboard/metrics$', 'metrics', name='questions.metrics'),
    url(r'^/dashboard/metrics/(?P<locale_code>[^/]+)$',
        'metrics',
        name='questions.locale_metrics'),

    # AAQ
    url(r'^/new$', 'aaq', name='questions.aaq_step1'),
Esempio n. 3
0
    url(r'^/(?P<question_id>\d+)/vote/(?P<answer_id>\d+)$',
        'answer_vote', name='questions.answer_vote'),
    url(r'^/(?P<question_id>\d+)/add-tag$', 'add_tag',
        name='questions.add_tag'),
    url(r'^/(?P<question_id>\d+)/remove-tag$', 'remove_tag',
        name='questions.remove_tag'),
    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'),

    # Feeds
    # Note: this needs to be above questions.list because "feed"
    # matches the product slug regex.
    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'),

    # Mark as spam
    url(r'^/mark_spam$', 'mark_spam', name='questions.mark_spam'),
    url(r'^/unmark_spam$', 'unmark_spam', name='questions.unmark_spam'),

    # Question lists
    url(r'^/(?P<product_slug>[\w+\-\,]+)$', 'question_list',
        name='questions.list'),

    # Flag content ("Report this post")
    url(r'^/(?P<object_id>\d+)/flag$', flagit_views.flag,
        {'content_type': ContentType.objects.get_for_model(Question).id},
Esempio n. 4
0
        {'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'),
)