Beispiel #1
0
def threads(request, forum_slug):
    """View all the threads in a forum."""
    forum = get_object_or_404(Forum, slug=forum_slug)
    if not forum.allows_viewing_by(request.user):
        raise Http404  # Pretend there's nothing there.

    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(forum.thread_set, sort, desc)
    count = threads_.count()
    threads_ = threads_.select_related('creator', 'last_post',
                                       'last_post__author')
    threads_ = paginate(request, threads_,
                        per_page=constants.THREADS_PER_PAGE, count=count)

    feed_urls = ((reverse('forums.threads.feed', args=[forum_slug]),
                  ThreadsFeed().title(forum)),)

    is_watching_forum = (request.user.is_authenticated() and
                         NewThreadEvent.is_notifying(request.user, forum))
    return render(request, 'forums/threads.html', {
        'forum': forum, 'threads': threads_,
        'is_watching_forum': is_watching_forum,
        'sort': sort, 'desc_toggle': desc_toggle,
        'feeds': feed_urls})
Beispiel #2
0
    def test_threads_sort(self):
        """Ensure that threads are being sorted properly by date/time."""
        # Threads are sorted descending by last post date.
        f = ForumFactory()
        ThreadFactory(forum=f, created=YESTERDAY)
        t2 = ThreadFactory(forum=f)

        eq_(t2.id, ThreadsFeed().items(f)[0].id)
Beispiel #3
0
    def test_multi_feed_titling(self):
        """Ensure that titles are being applied properly to feeds."""
        t = thread(save=True)
        forum = t.forum
        post(thread=t, save=True)

        response = get(self.client, 'forums.threads', args=[forum.slug])
        doc = pq(response.content)
        eq_(ThreadsFeed().title(forum),
            doc('link[type="application/atom+xml"]')[0].attrib['title'])
Beispiel #4
0
    def test_threads_sort(self):
        """Ensure that threads are being sorted properly by date/time."""
        # Threads are sorted descending by last post date.
        f = forum(save=True)
        t1 = thread(forum=f, created=YESTERDAY, save=True)
        post(thread=t1, created=YESTERDAY, save=True)
        t2 = thread(forum=f, save=True)
        post(thread=t2, save=True)

        eq_(t2.id, ThreadsFeed().items(f)[0].id)
Beispiel #5
0
    def test_multi_feed_titling(self):
        """Ensure that titles are being applied properly to feeds."""
        t = ThreadFactory()
        forum = t.forum
        PostFactory(thread=t)

        response = get(self.client, "forums.threads", args=[forum.slug])
        doc = pq(response.content)
        eq_(
            ThreadsFeed().title(forum), doc('link[type="application/atom+xml"]')[0].attrib["title"]
        )
Beispiel #6
0
def threads(request, forum_slug):
    """View all the threads in a forum."""
    forum = get_object_or_404(Forum, slug=forum_slug)
    if not forum.allows_viewing_by(request.user):
        raise Http404  # Pretend there's nothing there.

    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(forum.thread_set, sort, desc)
    count = threads_.count()
    threads_ = threads_.select_related("creator", "last_post",
                                       "last_post__author")
    threads_ = paginate(request,
                        threads_,
                        per_page=constants.THREADS_PER_PAGE,
                        count=count)

    feed_urls = ((reverse("forums.threads.feed",
                          args=[forum_slug]), ThreadsFeed().title(forum)), )

    is_watching_forum = request.user.is_authenticated and NewThreadEvent.is_notifying(
        request.user, forum)
    return render(
        request,
        "forums/threads.html",
        {
            "forum": forum,
            "threads": threads_,
            "is_watching_forum": is_watching_forum,
            "sort": sort,
            "desc_toggle": desc_toggle,
            "feeds": feed_urls,
        },
    )
Beispiel #7
0
from django.conf.urls import patterns, url, include
from django.contrib.contenttypes.models import ContentType

from kitsune.forums.feeds import ThreadsFeed, PostsFeed
from kitsune.forums.models import Post
from kitsune.flagit import views as flagit_views


# These patterns inherit (?P<forum_slug>\d+).
forum_patterns = patterns(
    'kitsune.forums.views',
    url(r'^$', 'threads', name='forums.threads'),
    url(r'^/new$', 'new_thread', name='forums.new_thread'),
    url(r'^/(?P<thread_id>\d+)$', 'posts', name='forums.posts'),
    url(r'^/(?P<thread_id>\d+)/reply$', 'reply', name='forums.reply'),
    url(r'^/feed$', ThreadsFeed(), name="forums.threads.feed"),
    url(r'^/(?P<thread_id>\d+)/feed$', PostsFeed(), name="forums.posts.feed"),
    url(r'^/(?P<thread_id>\d+)/lock$', 'lock_thread',
        name='forums.lock_thread'),
    url(r'^/(?P<thread_id>\d+)/sticky$', 'sticky_thread',
        name='forums.sticky_thread'),
    url(r'^/(?P<thread_id>\d+)/edit$', 'edit_thread',
        name='forums.edit_thread'),
    url(r'^/(?P<thread_id>\d+)/delete$', 'delete_thread',
        name='forums.delete_thread'),
    url(r'^/(?P<thread_id>\d+)/move$', 'move_thread',
        name='forums.move_thread'),
    url(r'^/(?P<thread_id>\d+)/(?P<post_id>\d+)/edit$', 'edit_post',
        name='forums.edit_post'),
    url(r'^/(?P<thread_id>\d+)/(?P<post_id>\d+)/delete$', 'delete_post',
        name='forums.delete_post'),
Beispiel #8
0
from django.conf import settings
from django.conf.urls import url, include

from kitsune.forums import views
from kitsune.forums.feeds import ThreadsFeed, PostsFeed
from kitsune.forums.models import Post
from kitsune.flagit import views as flagit_views
from kitsune.sumo.views import handle404

if settings.DISABLE_FEEDS:
    threads_feed_view = handle404
    posts_feed_view = handle404
else:
    threads_feed_view = ThreadsFeed()
    posts_feed_view = PostsFeed()

# These patterns inherit (?P<forum_slug>\d+).
forum_patterns = [
    url(r"^$", views.threads, name="forums.threads"),
    url(r"^/new$", views.new_thread, name="forums.new_thread"),
    url(r"^/(?P<thread_id>\d+)$", views.posts, name="forums.posts"),
    url(r"^/(?P<thread_id>\d+)/reply$", views.reply, name="forums.reply"),
    url(r"^/feed$", threads_feed_view, name="forums.threads.feed"),
    url(r"^/(?P<thread_id>\d+)/feed$",
        posts_feed_view,
        name="forums.posts.feed"),
    url(r"^/(?P<thread_id>\d+)/lock$",
        views.lock_thread,
        name="forums.lock_thread"),
    url(r"^/(?P<thread_id>\d+)/sticky$",
        views.sticky_thread,
Beispiel #9
0
        'post_preview_async',
        name='forums.post_preview_async'),

    # TODO: Factor out `/(?P<forum_slug>\d+)` below
    url(r'^/(?P<forum_slug>[\w\-]+)$', 'threads', name='forums.threads'),
    url(r'^/(?P<forum_slug>[\w\-]+)/new$',
        'new_thread',
        name='forums.new_thread'),
    url(r'^/(?P<forum_slug>[\w\-]+)/(?P<thread_id>\d+)$',
        'posts',
        name='forums.posts'),
    url(r'^/(?P<forum_slug>[\w\-]+)/(?P<thread_id>\d+)/reply$',
        'reply',
        name='forums.reply'),
    url(r'^/(?P<forum_slug>[\w\-]+)/feed$',
        ThreadsFeed(),
        name="forums.threads.feed"),
    url(r'^/(?P<forum_slug>[\w\-]+)/(?P<thread_id>\d+)/feed$',
        PostsFeed(),
        name="forums.posts.feed"),
    url(r'^/(?P<forum_slug>[\w\-]+)/(?P<thread_id>\d+)/lock$',
        'lock_thread',
        name='forums.lock_thread'),
    url(r'^/(?P<forum_slug>[\w\-]+)/(?P<thread_id>\d+)/sticky$',
        'sticky_thread',
        name='forums.sticky_thread'),
    url(r'^/(?P<forum_slug>[\w\-]+)/(?P<thread_id>\d+)/edit$',
        'edit_thread',
        name='forums.edit_thread'),
    url(r'^/(?P<forum_slug>[\w\-]+)/(?P<thread_id>\d+)/delete$',
        'delete_thread',