Show More
@@ -8,7 +8,7 b" DIR_IMAGES = 'images'" | |||||
8 |
|
8 | |||
9 | class PostManager(models.Manager): |
|
9 | class PostManager(models.Manager): | |
10 |
|
10 | |||
11 | def create_post(self, title, text, image, parent_id = NO_PARENT, |
|
11 | def create_post(self, title, text, image = None, parent_id = NO_PARENT, | |
12 | ip = NO_IP): |
|
12 | ip = NO_IP): | |
13 | post = self.create(title = title, |
|
13 | post = self.create(title = title, | |
14 | text = text, |
|
14 | text = text, | |
@@ -31,6 +31,21 b' class PostManager(models.Manager):' | |||||
31 | for post in posts: |
|
31 | for post in posts: | |
32 | self.delete_post(post) |
|
32 | self.delete_post(post) | |
33 |
|
33 | |||
|
34 | def get_threads(self, tag = None): | |||
|
35 | if tag is None: | |||
|
36 | threads = self.filter(parent = NO_PARENT) | |||
|
37 | else: | |||
|
38 | threads = self.filter(parent = NO_PARENT, tag = tag) | |||
|
39 | ||||
|
40 | return threads | |||
|
41 | ||||
|
42 | def get_thread(self, opening_post_id): | |||
|
43 | opening_post = self.get(opening_post_id) | |||
|
44 | replies = self.filter(parent = opening_post_id) | |||
|
45 | ||||
|
46 | return [opening_post, replies] | |||
|
47 | ||||
|
48 | ||||
34 | class Tag(models.Model): |
|
49 | class Tag(models.Model): | |
35 | """ |
|
50 | """ | |
36 | A tag is a text node assigned to the post. The tag serves as a board |
|
51 | A tag is a text node assigned to the post. The tag serves as a board |
@@ -1,13 +1,12 b'' | |||||
1 | from django.test import TestCase |
|
1 | from django.test import TestCase | |
2 | from django.conf import settings |
|
|||
3 |
|
2 | |||
4 |
from boards.models import |
|
3 | from boards.models import Post | |
5 |
|
4 | |||
6 | class BoardTests(TestCase): |
|
5 | class BoardTests(TestCase): | |
7 |
|
6 | |||
8 | def create_post(self, parent_id): |
|
7 | def create_post(self, parent_id): | |
9 | return Post.objects.create_post(title='title', |
|
8 | return Post.objects.create_post(title = 'title', | |
10 |
text='text', |
|
9 | text = 'text', parent_id = parent_id) | |
11 |
|
10 | |||
12 | def test_post_add(self): |
|
11 | def test_post_add(self): | |
13 | post = self.create_post(Post.NO_PARENT) |
|
12 | post = self.create_post(Post.NO_PARENT) |
@@ -1,9 +1,11 b'' | |||||
1 | from django.http import HttpResponse |
|
1 | from django.http import HttpResponse | |
2 |
|
2 | |||
3 | from boards.models import Post |
|
3 | from boards.models import Post | |
4 | import boards.models |
|
|||
5 |
|
4 | |||
6 | def index(request): |
|
5 | def index(request): | |
|
6 | # TODO Show a real index page with all threads list | |||
|
7 | threads = Post.objects.get_threads() | |||
|
8 | ||||
7 | return HttpResponse('Imageboard, motherfucker! Do you post to it?!') |
|
9 | return HttpResponse('Imageboard, motherfucker! Do you post to it?!') | |
8 |
|
10 | |||
9 | def new_post(request): |
|
11 | def new_post(request): | |
@@ -16,11 +18,21 b' def new_post(request):' | |||||
16 |
|
18 | |||
17 | post = Post.objects.create_post(title = title, text = text, image = image) |
|
19 | post = Post.objects.create_post(title = title, text = text, image = image) | |
18 |
|
20 | |||
|
21 | # TODO Show the thread with a newly created post | |||
|
22 | ||||
19 | def tag(request): |
|
23 | def tag(request): | |
20 | """Get all tag threads (posts without a parent).""" |
|
24 | """Get all tag threads (posts without a parent).""" | |
21 |
|
25 | |||
22 | tag_name = request.GET['tag'] |
|
26 | tag_name = request.GET['tag'] | |
23 |
|
27 | |||
24 |
posts = Post.objects. |
|
28 | posts = Post.objects.get_threads(tag = tag) | |
|
29 | ||||
|
30 | # TODO Send a response with the post list | |||
25 |
|
31 | |||
26 | # TODO Send a response with the post list No newline at end of file |
|
32 | def thread(request): | |
|
33 | """Get all thread posts""" | |||
|
34 | ||||
|
35 | opening_post_id = request.GET['id'] | |||
|
36 | posts = Post.objects.get_thread(opening_post_id) | |||
|
37 | ||||
|
38 | # TODO Show all posts for the current thread No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now