# HG changeset patch # User neko259 # Date 2013-03-25 20:12:48 # Node ID e40b2431856150a08fa1e536c0d1474861495453 # Parent fdfec9a2d87672dd1efef2fbf4b86f8f7343d542 Fixed getting posts for a thread. Implemented thread getting test. diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -41,10 +41,13 @@ class PostManager(models.Manager): return threads def get_thread(self, opening_post_id): - opening_post = self.get(opening_post_id) - replies = self.filter(parent = opening_post_id) + opening_post = self.get(id = opening_post_id) + replies = self.filter(parent = opening_post_id) - return [opening_post, replies] + thread = [opening_post] + thread.extend(replies) + + return thread def exists(self, post_id): posts = self.filter(id = post_id) diff --git a/boards/tests.py b/boards/tests.py --- a/boards/tests.py +++ b/boards/tests.py @@ -86,3 +86,14 @@ class BoardTests(TestCase): admin.delete() + def test_get_thread(self): + opening_post = self._create_post() + op_id = opening_post.id + + for i in range(0, 2): + Post.objects.create_post('title', 'text', + parent_id = op_id) + + thread = Post.objects.get_thread(op_id) + + self.assertEqual(3, thread.__len__()) diff --git a/boards/urls.py b/boards/urls.py --- a/boards/urls.py +++ b/boards/urls.py @@ -12,9 +12,9 @@ urlpatterns = patterns('', url(r'^logout$', views.logout, name='logout'), # /boards/tag/ - url(r'^(?P\w+)/$', views.tag, name = 'tag'), + url(r'^tag/(?P\w+)/$', views.tag, name = 'tag'), # /boards/post_id/ - url(r'^(?P\w+)/$', views.thread, name = 'thread'), + url(r'^post/(?P\w+)/$', views.thread, name = 'thread'), # /boards/tag/post/ url(r'^post.html$', views.new_post, name='post'), diff --git a/boards/views.py b/boards/views.py --- a/boards/views.py +++ b/boards/views.py @@ -47,18 +47,17 @@ def tag(request): return render(request, 'posting_general.html', context) -def thread(request): +def thread(request, id): """Get all thread posts""" # TODO Show 404 if there is no such thread - opening_post_id = request.GET['id'] - posts = Post.objects.get_thread(opening_post_id) + posts = Post.objects.get_thread(id) context = RequestContext(request) context['posts'] = posts - return render(request), 'thread.html' + return render(request, 'thread.html', context) def login(request): """Log in as admin""" diff --git a/templates/posting_general.html b/templates/posting_general.html --- a/templates/posting_general.html +++ b/templates/posting_general.html @@ -6,7 +6,8 @@ {% for thread in threads %} {{ thread.title }}
{{ thread.text }}
- View thread + View + thread
{% endfor %} {% else %}