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 jingo.render(request, 'forums/threads.html', {'forum': forum, 'threads': threads_, 'is_watching_forum': is_watching_forum, 'sort': sort, 'desc_toggle': desc_toggle, 'feeds': feed_urls})
def test_multi_feed_titling(self): """Ensure that titles are being applied properly to feeds.""" forum = Forum.objects.filter()[0] response = get(self.client, 'forums.threads', args=[forum.slug]) doc = pq(response.content) given_ = doc('link[type="application/atom+xml"]')[0].attrib['title'] exp_ = ThreadsFeed().title(forum) eq_(exp_, given_)
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'])
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)
def test_threads_sort(self): """Ensure that threads are being sorted properly by date/time.""" f = Forum.objects.get(pk=1) given_ = ThreadsFeed().items(f)[0].id exp_ = 4L eq_(exp_, given_)
urlpatterns = patterns('forums.views', 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$',
urlpatterns = patterns( 'forums.views', 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',