##// END OF EJS Templates
Fixed getting posts for a thread. Implemented thread getting test.
neko259 -
r17:e40b2431 default
parent child Browse files
Show More
@@ -41,10 +41,13 b' class PostManager(models.Manager):'
41 return threads
41 return threads
42
42
43 def get_thread(self, opening_post_id):
43 def get_thread(self, opening_post_id):
44 opening_post = self.get(opening_post_id)
44 opening_post = self.get(id = opening_post_id)
45 replies = self.filter(parent = opening_post_id)
45 replies = self.filter(parent = opening_post_id)
46
46
47 return [opening_post, replies]
47 thread = [opening_post]
48 thread.extend(replies)
49
50 return thread
48
51
49 def exists(self, post_id):
52 def exists(self, post_id):
50 posts = self.filter(id = post_id)
53 posts = self.filter(id = post_id)
@@ -86,3 +86,14 b' class BoardTests(TestCase):'
86
86
87 admin.delete()
87 admin.delete()
88
88
89 def test_get_thread(self):
90 opening_post = self._create_post()
91 op_id = opening_post.id
92
93 for i in range(0, 2):
94 Post.objects.create_post('title', 'text',
95 parent_id = op_id)
96
97 thread = Post.objects.get_thread(op_id)
98
99 self.assertEqual(3, thread.__len__())
@@ -12,9 +12,9 b" urlpatterns = patterns('',"
12 url(r'^logout$', views.logout, name='logout'),
12 url(r'^logout$', views.logout, name='logout'),
13
13
14 # /boards/tag/
14 # /boards/tag/
15 url(r'^(?P<tag>\w+)/$', views.tag, name = 'tag'),
15 url(r'^tag/(?P<tag>\w+)/$', views.tag, name = 'tag'),
16 # /boards/post_id/
16 # /boards/post_id/
17 url(r'^(?P<post>\w+)/$', views.thread, name = 'thread'),
17 url(r'^post/(?P<id>\w+)/$', views.thread, name = 'thread'),
18 # /boards/tag/post/
18 # /boards/tag/post/
19 url(r'^post.html$', views.new_post,
19 url(r'^post.html$', views.new_post,
20 name='post'),
20 name='post'),
@@ -47,18 +47,17 b' def tag(request):'
47 return render(request, 'posting_general.html',
47 return render(request, 'posting_general.html',
48 context)
48 context)
49
49
50 def thread(request):
50 def thread(request, id):
51 """Get all thread posts"""
51 """Get all thread posts"""
52
52
53 # TODO Show 404 if there is no such thread
53 # TODO Show 404 if there is no such thread
54
54
55 opening_post_id = request.GET['id']
55 posts = Post.objects.get_thread(id)
56 posts = Post.objects.get_thread(opening_post_id)
57
56
58 context = RequestContext(request)
57 context = RequestContext(request)
59 context['posts'] = posts
58 context['posts'] = posts
60
59
61 return render(request), 'thread.html'
60 return render(request, 'thread.html', context)
62
61
63 def login(request):
62 def login(request):
64 """Log in as admin"""
63 """Log in as admin"""
@@ -6,7 +6,8 b''
6 {% for thread in threads %}
6 {% for thread in threads %}
7 <span class="title">{{ thread.title }}</span><br />
7 <span class="title">{{ thread.title }}</span><br />
8 <span class="text">{{ thread.text }}</span><br />
8 <span class="text">{{ thread.text }}</span><br />
9 <a class="link" href="/boards/id/{{ thread.id }}/">View thread</a>
9 <a class="link" href="/boards/post/{{ thread.id }}/">View
10 thread</a>
10 <hr />
11 <hr />
11 {% endfor %}
12 {% endfor %}
12 {% else %}
13 {% else %}
General Comments 0
You need to be logged in to leave comments. Login now