Esempio n. 1
0
 def test_delete_removes_watches(self):
     """Assert deleting a document deletes watches on its threads."""
     t = Thread.objects.get(pk=1)
     d = t.document
     NewThreadEvent.notify('*****@*****.**', t)
     assert NewThreadEvent.is_notifying('*****@*****.**', t)
     d.delete()
     assert not NewThreadEvent.is_notifying('*****@*****.**', t)
Esempio n. 2
0
 def test_delete_removes_watches(self):
     """Assert deleting a document deletes watches on its threads."""
     t = Thread.objects.get(pk=1)
     d = t.document
     NewThreadEvent.notify('*****@*****.**', t)
     assert NewThreadEvent.is_notifying('*****@*****.**', t)
     d.delete()
     assert not NewThreadEvent.is_notifying('*****@*****.**', t)
Esempio n. 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]))
Esempio n. 4
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]))
Esempio n. 5
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]))
Esempio n. 6
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
Esempio n. 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 jingo.render(
        request,
        "kbforums/threads.html",
        {
            "document": doc,
            "threads": threads_,
            "is_watching_forum": is_watching_forum,
            "sort": sort,
            "desc_toggle": desc_toggle,
            "feeds": feed_urls,
        },
    )
Esempio n. 8
0
    def test_watch_forum(self):
        """Watch then unwatch a forum."""
        self.client.login(username='******', password='******')
        user = User.objects.get(username='******')

        d = Document.objects.filter()[0]
        post(self.client, 'wiki.discuss.watch_forum', {'watch': 'yes'},
             args=[d.slug])
        assert NewThreadEvent.is_notifying(user, d)
        # NewPostEvent is not notifying.
        p = d.thread_set.all()[0].post_set.all()[0]
        assert not NewPostEvent.is_notifying(user, p)

        post(self.client, 'wiki.discuss.watch_forum', {'watch': 'no'},
             args=[d.slug])
        assert not NewThreadEvent.is_notifying(user, d)
Esempio n. 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 jingo.render(request, 'kbforums/threads.html',
                        {'document': doc, 'threads': threads_,
                         'is_watching_forum': is_watching_forum,
                         'sort': sort, 'desc_toggle': desc_toggle,
                         'feeds': feed_urls})
Esempio n. 10
0
    def test_watch_forum(self):
        """Watch then unwatch a forum."""
        self.client.login(username='******', password='******')
        user = User.objects.get(username='******')

        d = Document.objects.filter()[0]
        post(self.client, 'wiki.discuss.watch_forum', {'watch': 'yes'},
             args=[d.slug])
        assert NewThreadEvent.is_notifying(user, d)
        # NewPostEvent is not notifying.
        p = d.thread_set.all()[0].post_set.all()[0]
        assert not NewPostEvent.is_notifying(user, p)

        post(self.client, 'wiki.discuss.watch_forum', {'watch': 'no'},
             args=[d.slug])
        assert not NewThreadEvent.is_notifying(user, d)
Esempio n. 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 jingo.render(
        request, 'kbforums/threads.html', {
            'document': doc,
            'threads': threads_,
            'is_watching_forum': is_watching_forum,
            'sort': sort,
            'desc_toggle': desc_toggle,
            'feeds': feed_urls
        })
Esempio n. 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)
Esempio n. 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')
        #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)
Esempio n. 14
0
    def test_watch_thread(self):
        """Watch then unwatch a thread."""
        self.client.login(username='******', password='******')
        user = User.objects.get(username='******')

        t = Thread.objects.filter()[0]
        post(self.client, 'wiki.discuss.watch_thread', {'watch': 'yes'},
             args=[t.document.slug, t.id])
        assert NewPostEvent.is_notifying(user, t)
        # NewThreadEvent is not notifying.
        assert not NewThreadEvent.is_notifying(user, t.document)

        post(self.client, 'wiki.discuss.watch_thread', {'watch': 'no'},
             args=[t.document.slug, t.id])
        assert not NewPostEvent.is_notifying(user, t)
Esempio n. 15
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)
Esempio n. 16
0
    def test_watch_thread(self):
        """Watch then unwatch a thread."""
        self.client.login(username='******', password='******')
        user = User.objects.get(username='******')

        t = Thread.objects.filter()[0]
        post(self.client, 'wiki.discuss.watch_thread', {'watch': 'yes'},
             args=[t.document.slug, t.id])
        assert NewPostEvent.is_notifying(user, t)
        # NewThreadEvent is not notifying.
        assert not NewThreadEvent.is_notifying(user, t.document)

        post(self.client, 'wiki.discuss.watch_thread', {'watch': 'no'},
             args=[t.document.slug, t.id])
        assert not NewPostEvent.is_notifying(user, t)
Esempio n. 17
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)
Esempio n. 18
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'])
        else:
            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
    })