Skip to content

Commit

Permalink
[bug 648258] Mark new threads read, at least.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Socol committed Dec 20, 2011
1 parent 8dce129 commit ebdd5d5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
12 changes: 9 additions & 3 deletions apps/forums/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,15 @@ def new_post(self, author, content):
return self.post_set.create(author=author, content=content)

def get_absolute_url(self):
return reverse('forums.posts',
kwargs={'forum_slug': self.forum.slug,
'thread_id': self.id})
return reverse('forums.posts', args=[self.forum.slug, self.id])

def get_last_post_url(self):
query = {'last': self.last_post_id}
page = self.last_page
if page > 1:
query['page'] = page
url = reverse('forums.posts', args=[self.forum.slug, self.id])
return urlparams(url, hash='post-%s' % self.last_post_id, **query)

def save(self, *args, **kwargs):
super(Thread, self).save(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion apps/forums/templates/forums/includes/forum_macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div class="author"><a class="username" href="{{ profile_url(thread.creator) }}">{{ thread.creator.username }}</a></div>
<div class="replies">{{ thread.replies }}</div>
<div class="last-post">
<a href="{{ thread.last_post.get_absolute_url() }}">
<a href="{{ thread.get_last_post_url() }}">
{{ datetimeformat(thread.last_post.created) }}
</a><br/>
{{ _('by <a class="username" href="{profile_url}">{username}</a>')|fe(profile_url=profile_url(thread.last_post.author), username=thread.last_post.author.username) }}
Expand Down
11 changes: 11 additions & 0 deletions apps/forums/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ def test_post_page(self):
p = Post.objects.get(pk=24)
eq_(2, p.page)

def test_thread_last_post_url(self):
p = Post.objects.get(pk=24)
t = p.thread
lp = t.last_post
f = t.forum
url_ = t.get_last_post_url()
assert f.slug in url_
assert str(t.id) in url_
assert '#post-%s' % lp.id in url_
assert 'last=%s' % lp.id in url_

def test_last_post_updated(self):
"""Adding/Deleting the last post in a thread and forum should
update the last_post field
Expand Down
23 changes: 23 additions & 0 deletions apps/forums/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,29 @@ def test_edit_thread_moderator(self):
edited_t = Thread.uncached.get(pk=2)
eq_('new title', edited_t.title)

def test_new_thread_redirect(self):
"""Posting a new thread should redirect."""
self.client.login(username='pcraciunoiu', password='testpass')
f = Forum.objects.get(pk=1)
url = reverse('forums.new_thread', args=[f.slug])
data = {'title': 'some title', 'content': 'some content'}
r = self.client.post(url, data, follow=False)
eq_(302, r.status_code)
assert f.slug in r['location']
assert 'last=' in r['location']

def test_reply_redirect(self):
"""Posting a reply should redirect."""
self.client.login(username='pcraciunoiu', password='testpass')
t = Thread.objects.get(pk=2)
url = reverse('forums.reply', args=[t.forum.slug, t.id])
data = {'content': 'some content'}
r = self.client.post(url, data, follow=False)
eq_(302, r.status_code)
assert t.forum.slug in r['location']
assert str(t.id) in r['location']
assert 'last=' in r['location']


class ThreadPermissionsTests(ForumTestCase):

Expand Down
7 changes: 4 additions & 3 deletions apps/forums/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from forums.feeds import ThreadsFeed, PostsFeed
from forums.forms import ReplyForm, NewThreadForm, EditThreadForm, EditPostForm
from forums.models import Forum, Thread, Post
from sumo.helpers import urlparams
from sumo.urlresolvers import reverse
from sumo.utils import paginate
from users.models import Setting
Expand Down Expand Up @@ -169,7 +170,7 @@ def reply(request, forum_slug, thread_id):
# Send notifications to thread/forum watchers.
NewPostEvent(reply_).fire(exclude=reply_.author)

return HttpResponseRedirect(reply_.get_absolute_url())
return HttpResponseRedirect(thread.get_last_post_url())

return posts(request, forum_slug, thread_id, form, post_preview,
is_reply=True)
Expand Down Expand Up @@ -216,8 +217,8 @@ def new_thread(request, forum_slug):
if Setting.get_for_user(request.user, 'forums_watch_new_thread'):
NewPostEvent.notify(request.user, thread)

return HttpResponseRedirect(
reverse('forums.posts', args=[forum_slug, thread.id]))
url = reverse('forums.posts', args=[forum_slug, thread.id])
return HttpResponseRedirect(urlparams(url, last=post.id))

return jingo.render(request, 'forums/new_thread.html',
{'form': form, 'forum': forum,
Expand Down
3 changes: 2 additions & 1 deletion media/css/forums.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ ol.threads li div.title {
width: 32%;
}

.title a:visited {
.title a:visited,
.last-post a:visited {
color: #777;
}

Expand Down

0 comments on commit ebdd5d5

Please sign in to comment.