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. 2
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. 3
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
        })
Esempio n. 4
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,
        },
    )
Esempio n. 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
Esempio n. 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})
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 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."""
        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)
Esempio n. 9
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. 10
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)
Esempio n. 11
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. 12
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)