Example #1
0
def watch_forum(request, document_slug):
    """Watch/unwatch a document (based on 'watch' POST param)."""
    doc = get_document(document_slug, request)
    if request.POST.get("watch") == "yes":
        NewThreadEvent.notify(request.user, doc)
        statsd.incr("kbforums.watches.document")
    else:
        NewThreadEvent.stop_notifying(request.user, doc)

    return HttpResponseRedirect(reverse("wiki.discuss.threads", args=[document_slug]))
Example #2
0
def watch_forum(request, document_slug):
    """Watch/unwatch a document (based on 'watch' POST param)."""
    doc = get_document(document_slug, request)
    if request.POST.get("watch") == "yes":
        NewThreadEvent.notify(request.user, doc)
    else:
        NewThreadEvent.stop_notifying(request.user, doc)

    return HttpResponseRedirect(
        reverse("wiki.discuss.threads", args=[document_slug]))
Example #3
0
def watch_forum(request, document_slug):
    """Watch/unwatch a document (based on 'watch' POST param)."""
    doc = get_document(document_slug, request)
    if request.POST.get('watch') == 'yes':
        NewThreadEvent.notify(request.user, doc)
        statsd.incr('kbforums.watches.document')
    else:
        NewThreadEvent.stop_notifying(request.user, doc)

    return HttpResponseRedirect(
        reverse('wiki.discuss.threads', args=[document_slug]))
 def _toggle_watch_kbforum_as(self, username, document, turn_on=True):
     """Watch a discussion forum and return it."""
     self.client.login(username=username, password="******")
     user = User.objects.get(username=username)
     watch = "yes" if turn_on else "no"
     post(self.client, "wiki.discuss.watch_forum", {"watch": watch}, args=[document.slug])
     # Watch exists or not, depending on watch.
     if turn_on:
         assert NewThreadEvent.is_notifying(user, document), "NewThreadEvent should be notifying."
     else:
         assert not NewThreadEvent.is_notifying(user, document), "NewThreadEvent should not be notifying."
     return document
Example #5
0
 def _toggle_watch_kbforum_as(self, username, document, turn_on=True):
     """Watch a discussion forum and return it."""
     self.client.login(username=username, password='******')
     user = User.objects.get(username=username)
     watch = 'yes' if turn_on else 'no'
     post(self.client, 'wiki.discuss.watch_forum', {'watch': watch},
          args=[document.slug])
     # Watch exists or not, depending on watch.
     if turn_on:
         assert NewThreadEvent.is_notifying(user, document), (
             'NewThreadEvent should be notifying.')
     else:
         assert not NewThreadEvent.is_notifying(user, document), (
             'NewThreadEvent should not be notifying.')
     return document
Example #6
0
def threads(request, document_slug):
    """View all the threads in a discussion forum."""
    doc = get_document(document_slug, request)
    try:
        sort = int(request.GET.get("sort", 0))
    except ValueError:
        sort = 0

    try:
        desc = int(request.GET.get("desc", 0))
    except ValueError:
        desc = 0
    desc_toggle = 0 if desc else 1

    threads_ = sort_threads(doc.thread_set, sort, desc)
    threads_ = paginate(request, threads_, per_page=kbforums.THREADS_PER_PAGE)

    feed_urls = ((reverse("wiki.discuss.threads.feed", args=[document_slug]), ThreadsFeed().title(doc)),)

    is_watching_forum = request.user.is_authenticated() and NewThreadEvent.is_notifying(request.user, doc)
    return render(
        request,
        "kbforums/threads.html",
        {
            "document": doc,
            "threads": threads_,
            "is_watching_forum": is_watching_forum,
            "sort": sort,
            "desc_toggle": desc_toggle,
            "feeds": feed_urls,
        },
    )
Example #7
0
def threads(request, document_slug):
    """View all the threads in a discussion forum."""
    doc = get_document(document_slug, request)
    try:
        sort = int(request.GET.get('sort', 0))
    except ValueError:
        sort = 0

    try:
        desc = int(request.GET.get('desc', 0))
    except ValueError:
        desc = 0
    desc_toggle = 0 if desc else 1

    threads_ = sort_threads(doc.thread_set, sort, desc)
    threads_ = paginate(request, threads_,
                        per_page=kbforums.THREADS_PER_PAGE)

    feed_urls = ((reverse('wiki.discuss.threads.feed', args=[document_slug]),
                  ThreadsFeed().title(doc)),)

    is_watching_forum = (request.user.is_authenticated() and
                         NewThreadEvent.is_notifying(request.user, doc))
    return render(request, 'kbforums/threads.html', {
        'document': doc, 'threads': threads_,
        'is_watching_forum': is_watching_forum,
        'sort': sort, 'desc_toggle': desc_toggle,
        'feeds': feed_urls})
Example #8
0
 def _toggle_watch_kbforum_as(self, username, document, turn_on=True):
     """Watch a discussion forum and return it."""
     self.client.login(username=username, password="******")
     user = User.objects.get(username=username)
     watch = "yes" if turn_on else "no"
     post(self.client,
          "wiki.discuss.watch_forum", {"watch": watch},
          args=[document.slug])
     # Watch exists or not, depending on watch.
     if turn_on:
         assert NewThreadEvent.is_notifying(
             user, document), "NewThreadEvent should be notifying."
     else:
         assert not NewThreadEvent.is_notifying(
             user, document), "NewThreadEvent should not be notifying."
     return document
Example #9
0
def threads(request, document_slug):
    """View all the threads in a discussion forum."""
    doc = get_document(document_slug, request)
    try:
        sort = int(request.GET.get("sort", 0))
    except ValueError:
        sort = 0

    try:
        desc = int(request.GET.get("desc", 0))
    except ValueError:
        desc = 0
    desc_toggle = 0 if desc else 1

    threads_ = sort_threads(doc.thread_set, sort, desc)
    threads_ = paginate(request, threads_, per_page=kbforums.THREADS_PER_PAGE)

    feed_urls = ((reverse("wiki.discuss.threads.feed",
                          args=[document_slug]), ThreadsFeed().title(doc)), )

    is_watching_forum = request.user.is_authenticated and NewThreadEvent.is_notifying(
        request.user, doc)
    return render(
        request,
        "kbforums/threads.html",
        {
            "document": doc,
            "threads": threads_,
            "is_watching_forum": is_watching_forum,
            "sort": sort,
            "desc_toggle": desc_toggle,
            "feeds": feed_urls,
        },
    )
Example #10
0
    def test_watch_forum(self):
        """Watch then unwatch a forum."""
        u = UserFactory()
        self.client.login(username=u.username, password='******')

        d = DocumentFactory()
        post(self.client, 'wiki.discuss.watch_forum', {'watch': 'yes'},
             args=[d.slug])
        assert NewThreadEvent.is_notifying(u, d)
        # NewPostEvent is not notifying.
        t = ThreadFactory(document=d)
        p = t.new_post(creator=t.creator, content='test')
        assert not NewPostEvent.is_notifying(u, p)

        post(self.client, 'wiki.discuss.watch_forum', {'watch': 'no'}, args=[d.slug])
        assert not NewThreadEvent.is_notifying(u, d)
Example #11
0
def threads(request, document_slug):
    """View all the threads in a discussion forum."""
    doc = get_document(document_slug, request)
    try:
        sort = int(request.GET.get('sort', 0))
    except ValueError:
        sort = 0

    try:
        desc = int(request.GET.get('desc', 0))
    except ValueError:
        desc = 0
    desc_toggle = 0 if desc else 1

    threads_ = sort_threads(doc.thread_set, sort, desc)
    threads_ = paginate(request, threads_, per_page=kbforums.THREADS_PER_PAGE)

    feed_urls = ((reverse('wiki.discuss.threads.feed',
                          args=[document_slug]), ThreadsFeed().title(doc)), )

    is_watching_forum = (request.user.is_authenticated()
                         and NewThreadEvent.is_notifying(request.user, doc))
    return render(
        request, 'kbforums/threads.html', {
            'document': doc,
            'threads': threads_,
            'is_watching_forum': is_watching_forum,
            'sort': sort,
            'desc_toggle': desc_toggle,
            'feeds': feed_urls
        })
Example #12
0
    def test_watch_forum(self):
        """Watch then unwatch a forum."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        d = document(save=True)
        post(self.client, 'wiki.discuss.watch_forum', {'watch': 'yes'},
             args=[d.slug])
        assert NewThreadEvent.is_notifying(u, d)
        # NewPostEvent is not notifying.
        t = thread(document=d, save=True)
        p = t.new_post(creator=t.creator, content='test')
        #p = d.thread_set.all()[0].post_set.all()[0]
        assert not NewPostEvent.is_notifying(u, p)

        post(self.client, 'wiki.discuss.watch_forum', {'watch': 'no'},
             args=[d.slug])
        assert not NewThreadEvent.is_notifying(u, d)
Example #13
0
    def test_watch_forum(self):
        """Watch then unwatch a forum."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        d = document(save=True)
        post(self.client,
             'wiki.discuss.watch_forum', {'watch': 'yes'},
             args=[d.slug])
        assert NewThreadEvent.is_notifying(u, d)
        # NewPostEvent is not notifying.
        t = thread(document=d, save=True)
        p = t.new_post(creator=t.creator, content='test')
        assert not NewPostEvent.is_notifying(u, p)

        post(self.client,
             'wiki.discuss.watch_forum', {'watch': 'no'},
             args=[d.slug])
        assert not NewThreadEvent.is_notifying(u, d)
Example #14
0
    def test_watch_thread(self):
        """Watch then unwatch a thread."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        t = thread(save=True)
        post(self.client, 'wiki.discuss.watch_thread', {'watch': 'yes'},
             args=[t.document.slug, t.id])
        assert NewPostEvent.is_notifying(u, t)
        # NewThreadEvent is not notifying.
        assert not NewThreadEvent.is_notifying(u, t.document)

        post(self.client, 'wiki.discuss.watch_thread', {'watch': 'no'},
             args=[t.document.slug, t.id])
        assert not NewPostEvent.is_notifying(u, t)
Example #15
0
def new_thread(request, document_slug):
    """Start a new thread."""
    doc = get_document(document_slug, request)

    if request.method == "GET":
        form = NewThreadForm()
        return render(request, "kbforums/new_thread.html", {
            "form": form,
            "document": doc
        })

    form = NewThreadForm(request.POST)
    post_preview = None
    if form.is_valid():
        if "preview" in request.POST:
            thread = Thread(creator=request.user,
                            title=form.cleaned_data["title"])
            post_preview = Post(thread=thread,
                                creator=request.user,
                                content=form.cleaned_data["content"])
        elif not _is_ratelimited(request):
            thread = doc.thread_set.create(creator=request.user,
                                           title=form.cleaned_data["title"])
            thread.save()
            post = thread.new_post(creator=request.user,
                                   content=form.cleaned_data["content"])
            post.save()

            # Send notifications to forum watchers.
            NewThreadEvent(post).fire(exclude=post.creator)

            # Add notification automatically if needed.
            if Setting.get_for_user(request.user, "kbforums_watch_new_thread"):
                NewPostEvent.notify(request.user, thread)

            return HttpResponseRedirect(
                reverse("wiki.discuss.posts", args=[document_slug, thread.id]))

    return render(
        request,
        "kbforums/new_thread.html",
        {
            "form": form,
            "document": doc,
            "post_preview": post_preview
        },
    )
Example #16
0
    def test_watch_thread(self):
        """Watch then unwatch a thread."""
        u = user(save=True)
        self.client.login(username=u.username, password='******')

        t = thread(save=True)
        post(self.client,
             'wiki.discuss.watch_thread', {'watch': 'yes'},
             args=[t.document.slug, t.id])
        assert NewPostEvent.is_notifying(u, t)
        # NewThreadEvent is not notifying.
        assert not NewThreadEvent.is_notifying(u, t.document)

        post(self.client,
             'wiki.discuss.watch_thread', {'watch': 'no'},
             args=[t.document.slug, t.id])
        assert not NewPostEvent.is_notifying(u, t)
Example #17
0
def new_thread(request, document_slug):
    """Start a new thread."""
    doc = get_document(document_slug, request)

    if request.method == 'GET':
        form = NewThreadForm()
        return render(request, 'kbforums/new_thread.html', {
            'form': form,
            'document': doc
        })

    form = NewThreadForm(request.POST)
    post_preview = None
    if form.is_valid():
        if 'preview' in request.POST:
            thread = Thread(creator=request.user,
                            title=form.cleaned_data['title'])
            post_preview = Post(thread=thread,
                                creator=request.user,
                                content=form.cleaned_data['content'])
        elif not _is_ratelimited(request):
            thread = doc.thread_set.create(creator=request.user,
                                           title=form.cleaned_data['title'])
            thread.save()
            statsd.incr('kbforums.thread')
            post = thread.new_post(creator=request.user,
                                   content=form.cleaned_data['content'])
            post.save()

            # Send notifications to forum watchers.
            NewThreadEvent(post).fire(exclude=post.creator)

            # Add notification automatically if needed.
            if Setting.get_for_user(request.user, 'kbforums_watch_new_thread'):
                NewPostEvent.notify(request.user, thread)

            return HttpResponseRedirect(
                reverse('wiki.discuss.posts', args=[document_slug, thread.id]))

    return render(request, 'kbforums/new_thread.html', {
        'form': form,
        'document': doc,
        'post_preview': post_preview
    })