Esempio n. 1
0
def posts(request,
          forum_slug,
          thread_id,
          form=None,
          post_preview=None,
          is_reply=False):
    """View all the posts in a thread."""
    thread = get_object_or_404(Thread, pk=thread_id)
    forum = thread.forum

    if forum.slug != forum_slug and not is_reply:
        new_forum = get_object_or_404(Forum, slug=forum_slug)
        if new_forum.allows_viewing_by(request.user):
            return HttpResponseRedirect(thread.get_absolute_url())
        raise Http404  # User has no right to view destination forum.
    elif forum.slug != forum_slug:
        raise Http404

    if not forum.allows_viewing_by(request.user):
        raise Http404

    posts_ = thread.post_set.all()
    count = posts_.count()
    if count:
        last_post = posts_[count - 1]
    else:
        last_post = None
    posts_ = posts_.select_related('author', 'updated_by')
    posts_ = posts_.extra(
        select={
            'author_post_count':
            'SELECT COUNT(*) FROM forums_post WHERE '
            'forums_post.author_id = auth_user.id'
        })
    posts_ = paginate(request, posts_, constants.POSTS_PER_PAGE, count=count)

    if not form:
        form = ReplyForm()

    feed_urls = ((reverse('forums.posts.feed',
                          kwargs={
                              'forum_slug': forum_slug,
                              'thread_id': thread_id
                          }), PostsFeed().title(thread)), )

    is_watching_thread = (request.user.is_authenticated()
                          and NewPostEvent.is_notifying(request.user, thread))
    return render(
        request, 'forums/posts.html', {
            'forum': forum,
            'thread': thread,
            'posts': posts_,
            'form': form,
            'count': count,
            'last_post': last_post,
            'post_preview': post_preview,
            'is_watching_thread': is_watching_thread,
            'feeds': feed_urls,
            'forums': Forum.objects.all()
        })
Esempio n. 2
0
def posts(request, forum_slug, thread_id, form=None, reply_preview=None):
    """View all the posts in a thread."""
    forum = get_object_or_404(Forum, slug=forum_slug)
    if not forum.allows_viewing_by(request.user):
        raise Http404

    thread = get_object_or_404(Thread, pk=thread_id, forum=forum)

    posts_ = thread.post_set.all()
    count = posts_.count()
    posts_ = posts_.select_related('author', 'updated_by')
    posts_ = posts_.extra(
        select={'author_post_count': 'SELECT COUNT(*) FROM forums_post WHERE '
                                     'forums_post.author_id = auth_user.id'})
    posts_ = paginate(request, posts_, constants.POSTS_PER_PAGE, count=count)

    if not form:
        form = ReplyForm()

    feed_urls = ((reverse('forums.posts.feed',
                          kwargs={'forum_slug': forum_slug,
                                  'thread_id': thread_id}),
                  PostsFeed().title(thread)),)

    is_watching_thread = (request.user.is_authenticated() and
                          NewPostEvent.is_notifying(request.user, thread))
    return jingo.render(request, 'forums/posts.html',
                        {'forum': forum, 'thread': thread,
                         'posts': posts_, 'form': form,
                         'reply_preview': reply_preview,
                         'is_watching_thread': is_watching_thread,
                         'feeds': feed_urls,
                         'forums': Forum.objects.all()})
Esempio n. 3
0
def posts(request, forum_slug, thread_id, form=None, reply_preview=None):
    """View all the posts in a thread."""
    forum = get_object_or_404(Forum, slug=forum_slug)
    if not forum.allows_viewing_by(request.user):
        raise Http404

    thread = get_object_or_404(Thread, pk=thread_id, forum=forum)

    posts_ = paginate(request, thread.post_set.all(), constants.POSTS_PER_PAGE)

    if not form:
        form = ReplyForm()

    feed_urls = ((reverse('forums.posts.feed',
                          kwargs={
                              'forum_slug': forum_slug,
                              'thread_id': thread_id
                          }), PostsFeed().title(thread)), )

    is_watching_thread = (request.user.is_authenticated()
                          and NewPostEvent.is_notifying(request.user, thread))
    return jingo.render(
        request, 'forums/posts.html', {
            'forum': forum,
            'thread': thread,
            'posts': posts_,
            'form': form,
            'reply_preview': reply_preview,
            'is_watching_thread': is_watching_thread,
            'feeds': feed_urls,
            'forums': Forum.objects.all()
        })
Esempio n. 4
0
    def test_posts_sort(self):
        """Ensure that posts are being sorted properly by date/time."""
        t = thread(save=True)
        post(thread=t, created=YESTERDAY, save=True)
        post(thread=t, created=YESTERDAY, save=True)
        p = post(thread=t, save=True)

        # The newest post should be the first one listed.
        eq_(p.id, PostsFeed().items(t)[0].id)
Esempio n. 5
0
 def test_posts_sort(self):
     """Ensure that posts are being sorted properly by date/time."""
     t = Thread.objects.get(pk=1)
     given_ = PostsFeed().items(t)[0].id
     exp_ = 24L
     eq_(exp_, given_)
Esempio n. 6
0
    url(r'^$', 'forums', name='forums.forums'),
    url(r'^/post-preview-async$', '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', name='forums.delete_thread'),
    url(r'^/(?P<forum_slug>[\w\-]+)/(?P<thread_id>\d+)/move$',
        'move_thread', name='forums.move_thread'),
    url(r'^/(?P<forum_slug>[\w\-]+)/(?P<thread_id>\d+)/(?P<post_id>\d+)/edit$',
        'edit_post', name='forums.edit_post'),
    url(r'^/(?P<forum_slug>[\w\-]+)/(?P<thread_id>\d+)/(?P<post_id>\d+)/delete$',
        'delete_post', name='forums.delete_post'),
    url(r'^/(?P<forum_slug>[\w\-]+)/(?P<thread_id>\d+)/watch',
Esempio n. 7
0
 url(r'^$', 'forums', name='forums.forums'),
 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',
     name='forums.delete_thread'),
 url(r'^/(?P<forum_slug>[\w\-]+)/(?P<thread_id>\d+)/move$',
     'move_thread',